增加自定义Scheme的激活和删除功能。
This commit is contained in:
		@@ -29,6 +29,7 @@ const routes = createBrowserRouter([
 | 
				
			|||||||
        path: 'schemes',
 | 
					        path: 'schemes',
 | 
				
			||||||
        element: <Schemes />,
 | 
					        element: <Schemes />,
 | 
				
			||||||
        children: [
 | 
					        children: [
 | 
				
			||||||
 | 
					          { index: true, element: <div /> },
 | 
				
			||||||
          { path: 'new', element: <NewScheme /> },
 | 
					          { path: 'new', element: <NewScheme /> },
 | 
				
			||||||
          { path: 'not-found', element: <SchemeNotFound /> },
 | 
					          { path: 'not-found', element: <SchemeNotFound /> },
 | 
				
			||||||
          { path: ':id', element: <SchemeDetail /> },
 | 
					          { path: ':id', element: <SchemeDetail /> },
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -20,6 +20,7 @@
 | 
				
			|||||||
      display: flex;
 | 
					      display: flex;
 | 
				
			||||||
      flex-direction: column;
 | 
					      flex-direction: column;
 | 
				
			||||||
      align-items: stretch;
 | 
					      align-items: stretch;
 | 
				
			||||||
 | 
					      gap: var(--spacing-s);
 | 
				
			||||||
      .scheme_item {
 | 
					      .scheme_item {
 | 
				
			||||||
        padding: calc(var(--spacing) * 2) calc(var(--spacing) * 8);
 | 
					        padding: calc(var(--spacing) * 2) calc(var(--spacing) * 8);
 | 
				
			||||||
        &.selected {
 | 
					        &.selected {
 | 
				
			||||||
@@ -53,6 +54,42 @@
 | 
				
			|||||||
        font-size: var(--font-size-xs);
 | 
					        font-size: var(--font-size-xs);
 | 
				
			||||||
        color: var(--color-accent);
 | 
					        color: var(--color-accent);
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					      .delete_btn {
 | 
				
			||||||
 | 
					        font-size: var(--font-size-xs);
 | 
				
			||||||
 | 
					        color: var(--color-yuebai);
 | 
				
			||||||
 | 
					        background-color: oklch(from var(--color-danger) l c h / 0.25);
 | 
				
			||||||
 | 
					        &:hover {
 | 
				
			||||||
 | 
					          background-color: oklch(from var(--color-danger-hover) l c h / 0.65);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        &:active {
 | 
				
			||||||
 | 
					          background-color: oklch(from var(--color-danger-active) l c h / 0.65);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      .active_btn {
 | 
				
			||||||
 | 
					        font-size: var(--font-size-xs);
 | 
				
			||||||
 | 
					        color: var(--color-yuebai);
 | 
				
			||||||
 | 
					        background-color: oklch(from var(--color-info) l c h / 0.25);
 | 
				
			||||||
 | 
					        &:hover {
 | 
				
			||||||
 | 
					          background-color: oklch(from var(--color-info-hover) l c h / 0.65);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        &:active {
 | 
				
			||||||
 | 
					          background-color: oklch(from var(--color-info-active) l c h / 0.65);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        &.deactive {
 | 
				
			||||||
 | 
					          background-color: oklch(from var(--color-warn) l c h / 0.25);
 | 
				
			||||||
 | 
					          &:hover {
 | 
				
			||||||
 | 
					            background-color: oklch(from var(--color-warn-hover) l c h / 0.65);
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
 | 
					          &:active {
 | 
				
			||||||
 | 
					            background-color: oklch(from var(--color-warn-active) l c h / 0.65);
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      .active_badge {
 | 
				
			||||||
 | 
					        font-size: var(--font-size-xs);
 | 
				
			||||||
 | 
					        color: var(--color-yuebai);
 | 
				
			||||||
 | 
					        background-color: var(--color-success);
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    .empty_prompt {
 | 
					    .empty_prompt {
 | 
				
			||||||
      padding-inline: calc(var(--spacing) * 6);
 | 
					      padding-inline: calc(var(--spacing) * 6);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,12 +1,12 @@
 | 
				
			|||||||
import { Icon } from '@iconify/react/dist/iconify.js';
 | 
					 | 
				
			||||||
import cx from 'clsx';
 | 
					import cx from 'clsx';
 | 
				
			||||||
import dayjs from 'dayjs';
 | 
					import { useAtom } from 'jotai';
 | 
				
			||||||
import { useAtomValue } from 'jotai';
 | 
					 | 
				
			||||||
import { isEmpty, isEqual } from 'lodash-es';
 | 
					import { isEmpty, isEqual } from 'lodash-es';
 | 
				
			||||||
import { useMemo } from 'react';
 | 
					import { useCallback, useMemo } from 'react';
 | 
				
			||||||
import { Link, useNavigate, useParams } from 'react-router-dom';
 | 
					import { Link, useNavigate, useParams } from 'react-router-dom';
 | 
				
			||||||
 | 
					import { ActionIcon } from '../../components/ActionIcon';
 | 
				
			||||||
 | 
					import { Badge } from '../../components/Badge';
 | 
				
			||||||
import { SchemeSign } from '../../components/SchemeSign';
 | 
					import { SchemeSign } from '../../components/SchemeSign';
 | 
				
			||||||
import { activeSchemeAtom, useSchemeList } from '../../stores/schemes';
 | 
					import { activeSchemeAtom, useRemoveScheme, useSchemeList } from '../../stores/schemes';
 | 
				
			||||||
import styles from './SchemeList.module.css';
 | 
					import styles from './SchemeList.module.css';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function OperateButtons() {
 | 
					function OperateButtons() {
 | 
				
			||||||
@@ -26,9 +26,20 @@ type SchemeItemProps = {
 | 
				
			|||||||
function SchemeItem({ item }: SchemeItemProps) {
 | 
					function SchemeItem({ item }: SchemeItemProps) {
 | 
				
			||||||
  const navParams = useParams();
 | 
					  const navParams = useParams();
 | 
				
			||||||
  const navigate = useNavigate();
 | 
					  const navigate = useNavigate();
 | 
				
			||||||
  const activedScheme = useAtomValue(activeSchemeAtom);
 | 
					  const [activedScheme, setActiveScheme] = useAtom(activeSchemeAtom);
 | 
				
			||||||
 | 
					  const removeScheme = useRemoveScheme(item.id);
 | 
				
			||||||
  const isActived = useMemo(() => isEqual(activedScheme, item.id), [activedScheme, item.id]);
 | 
					  const isActived = useMemo(() => isEqual(activedScheme, item.id), [activedScheme, item.id]);
 | 
				
			||||||
  const isSelected = useMemo(() => isEqual(navParams['id'], item.id), [navParams, item.id]);
 | 
					  const isSelected = useMemo(() => isEqual(navParams['id'], item.id), [navParams, item.id]);
 | 
				
			||||||
 | 
					  const handleActiveScheme = useCallback(() => {
 | 
				
			||||||
 | 
					    setActiveScheme((prev) => (prev ? null : item.id));
 | 
				
			||||||
 | 
					  }, [item]);
 | 
				
			||||||
 | 
					  const handleRemoveScheme = useCallback(() => {
 | 
				
			||||||
 | 
					    removeScheme();
 | 
				
			||||||
 | 
					    if (isActived) {
 | 
				
			||||||
 | 
					      setActiveScheme(null);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    navigate(-1);
 | 
				
			||||||
 | 
					  }, [item, isActived]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return (
 | 
					  return (
 | 
				
			||||||
    <div
 | 
					    <div
 | 
				
			||||||
@@ -37,11 +48,22 @@ function SchemeItem({ item }: SchemeItemProps) {
 | 
				
			|||||||
      <div className={styles.name}>{item.name}</div>
 | 
					      <div className={styles.name}>{item.name}</div>
 | 
				
			||||||
      <div className={styles.status}>
 | 
					      <div className={styles.status}>
 | 
				
			||||||
        <SchemeSign scheme={item.type} short />
 | 
					        <SchemeSign scheme={item.type} short />
 | 
				
			||||||
        <div className={styles.create_time}>
 | 
					        {isActived && <Badge extendClassName={styles.active_badge}>ACTIVE</Badge>}
 | 
				
			||||||
          created at {dayjs(item.createdAt).format('YYYY-MM-DD')}
 | 
					 | 
				
			||||||
        </div>
 | 
					 | 
				
			||||||
        <div className="spacer"></div>
 | 
					        <div className="spacer"></div>
 | 
				
			||||||
        {isActived && <Icon icon="tabler:check" className={styles.active_icon} />}
 | 
					        {isSelected && (
 | 
				
			||||||
 | 
					          <>
 | 
				
			||||||
 | 
					            <ActionIcon
 | 
				
			||||||
 | 
					              icon="tabler:trash"
 | 
				
			||||||
 | 
					              extendClassName={styles.delete_btn}
 | 
				
			||||||
 | 
					              onClick={handleRemoveScheme}
 | 
				
			||||||
 | 
					            />
 | 
				
			||||||
 | 
					            <ActionIcon
 | 
				
			||||||
 | 
					              icon="tabler:checkbox"
 | 
				
			||||||
 | 
					              extendClassName={cx(styles.active_btn, isActived && styles.deactive)}
 | 
				
			||||||
 | 
					              onClick={handleActiveScheme}
 | 
				
			||||||
 | 
					            />
 | 
				
			||||||
 | 
					          </>
 | 
				
			||||||
 | 
					        )}
 | 
				
			||||||
      </div>
 | 
					      </div>
 | 
				
			||||||
    </div>
 | 
					    </div>
 | 
				
			||||||
  );
 | 
					  );
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -13,6 +13,10 @@
 | 
				
			|||||||
      flex-direction: row;
 | 
					      flex-direction: row;
 | 
				
			||||||
      align-items: center;
 | 
					      align-items: center;
 | 
				
			||||||
      gap: var(--spacing-m);
 | 
					      gap: var(--spacing-m);
 | 
				
			||||||
 | 
					      .create_time {
 | 
				
			||||||
 | 
					        font-size: var(--font-size-xs);
 | 
				
			||||||
 | 
					        color: var(--color-neutral);
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,3 +1,4 @@
 | 
				
			|||||||
 | 
					import dayjs from 'dayjs';
 | 
				
			||||||
import { isNil, set } from 'lodash-es';
 | 
					import { isNil, set } from 'lodash-es';
 | 
				
			||||||
import { useCallback, useEffect } from 'react';
 | 
					import { useCallback, useEffect } from 'react';
 | 
				
			||||||
import { useNavigate, useParams } from 'react-router-dom';
 | 
					import { useNavigate, useParams } from 'react-router-dom';
 | 
				
			||||||
@@ -43,6 +44,9 @@ export function SchemeDetail() {
 | 
				
			|||||||
      <EditableTitle title={scheme?.name} onChange={updateTitle} />
 | 
					      <EditableTitle title={scheme?.name} onChange={updateTitle} />
 | 
				
			||||||
      <div className={styles.badge_layout}>
 | 
					      <div className={styles.badge_layout}>
 | 
				
			||||||
        <SchemeSign scheme={scheme?.type} />
 | 
					        <SchemeSign scheme={scheme?.type} />
 | 
				
			||||||
 | 
					        <div className={styles.create_time}>
 | 
				
			||||||
 | 
					          created at {dayjs(scheme?.createdAt).format('YYYY-MM-DD')}
 | 
				
			||||||
 | 
					        </div>
 | 
				
			||||||
      </div>
 | 
					      </div>
 | 
				
			||||||
      <EditableDescription content={scheme?.description} onChange={updateDescription} />
 | 
					      <EditableDescription content={scheme?.description} onChange={updateDescription} />
 | 
				
			||||||
    </div>
 | 
					    </div>
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user