From cb8e162f4ea57af3b6ed25ee028d607e7142b8b5 Mon Sep 17 00:00:00 2001 From: GyDi Date: Wed, 6 Apr 2022 01:13:06 +0800 Subject: [PATCH] refactor: update profile menu --- src/components/profile/enhanced.tsx | 35 ++++++++++++++++++++++--- src/components/profile/profile-more.tsx | 11 ++++---- 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/src/components/profile/enhanced.tsx b/src/components/profile/enhanced.tsx index 430e7c8..dc603c3 100644 --- a/src/components/profile/enhanced.tsx +++ b/src/components/profile/enhanced.tsx @@ -1,6 +1,7 @@ import useSWR from "swr"; import { useLockFn } from "ahooks"; -import { Box, Grid } from "@mui/material"; +import { Box, Grid, IconButton, Stack } from "@mui/material"; +import { RestartAltRounded } from "@mui/icons-material"; import { getProfiles, deleteProfile, @@ -22,7 +23,14 @@ const EnhancedMode = (props: Props) => { const { mutate } = useSWR("getProfiles", getProfiles); // handler - const onEnhance = useLockFn(enhanceProfiles); + const onEnhance = useLockFn(async () => { + try { + await enhanceProfiles(); + Notice.success("Refresh clash config", 2000); + } catch (err: any) { + Notice.error(err.message || err.toString()); + } + }); const onEnhanceEnable = useLockFn(async (uid: string) => { if (chain.includes(uid)) return; @@ -68,18 +76,39 @@ const EnhancedMode = (props: Props) => { return ( + + + + + + {/* + + */} + + {items.map((item) => ( onEnhanceEnable(item.uid)} onDisable={() => onEnhanceDisable(item.uid)} onDelete={() => onEnhanceDelete(item.uid)} onMoveTop={() => onMoveTop(item.uid)} onMoveEnd={() => onMoveEnd(item.uid)} - onEnhance={onEnhance} /> ))} diff --git a/src/components/profile/profile-more.tsx b/src/components/profile/profile-more.tsx index ed14028..2ead76a 100644 --- a/src/components/profile/profile-more.tsx +++ b/src/components/profile/profile-more.tsx @@ -35,12 +35,12 @@ const OS = getSystem(); interface Props { selected: boolean; itemData: CmdType.ProfileItem; + enableNum: number; onEnable: () => void; onDisable: () => void; onMoveTop: () => void; onMoveEnd: () => void; onDelete: () => void; - onEnhance: () => void; } // profile enhanced item @@ -48,12 +48,12 @@ const ProfileMore = (props: Props) => { const { selected, itemData, + enableNum, onEnable, onDisable, onMoveTop, onMoveEnd, onDelete, - onEnhance, } = props; const { uid, type } = itemData; @@ -95,14 +95,15 @@ const ProfileMore = (props: Props) => { return fn(); }; + const showMove = enableNum > 1 && !hasError; + const enableMenu = [ { label: "Disable", handler: fnWrapper(onDisable) }, - { label: "Refresh", handler: fnWrapper(onEnhance) }, { label: "Edit Info", handler: onEditInfo }, { label: "Edit File", handler: onEditFile }, { label: "Open File", handler: onOpenFile }, - { label: "To Top", show: !hasError, handler: fnWrapper(onMoveTop) }, - { label: "To End", show: !hasError, handler: fnWrapper(onMoveEnd) }, + { label: "To Top", show: showMove, handler: fnWrapper(onMoveTop) }, + { label: "To End", show: showMove, handler: fnWrapper(onMoveEnd) }, { label: "Delete", handler: fnWrapper(onDelete) }, ];