From 73822f08ebe22a814fca12661378841d6063567e Mon Sep 17 00:00:00 2001 From: Buriburizaem0n Date: Sat, 5 Sep 2026 12:45:31 -0400 Subject: [PATCH] fix(dashboard): fix Total Domains filtering and theme switching, add form attributes --- src/App.tsx | 6 +++- src/components/DashCommand.tsx | 2 ++ src/components/ThemeProvider.tsx | 29 ++++++++++++----- src/components/ui/command.tsx | 2 ++ src/lib/custom-config.ts | 1 - src/pages/Server.tsx | 13 +++++--- src/test/app.test.tsx | 15 +++++++++ src/test/pages/Server.test.tsx | 53 +++++++++++++++++++++++++++++++- 8 files changed, 106 insertions(+), 15 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 2160bca..242c3a6 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -85,7 +85,11 @@ const MainApp: React.FC = () => { (window.ForceTheme as string) !== "" ? window.ForceTheme : undefined; useEffect(() => { - if (forceTheme === "dark" || forceTheme === "light") { + const savedTheme = localStorage.getItem("vite-ui-theme"); + if ( + (!savedTheme || savedTheme === "system") && + (forceTheme === "dark" || forceTheme === "light") + ) { setTheme(forceTheme); } }, [forceTheme, setTheme]); diff --git a/src/components/DashCommand.tsx b/src/components/DashCommand.tsx index 14ce314..c972f4f 100644 --- a/src/components/DashCommand.tsx +++ b/src/components/DashCommand.tsx @@ -91,6 +91,8 @@ export function DashCommand() { return ( { - localStorage.setItem(storageKey, theme); - setTheme(theme); + const handleSetTheme = useCallback( + (nextTheme: Theme) => { + localStorage.setItem(storageKey, nextTheme); + setTheme(nextTheme); }, - }; + [storageKey], + ); + + const value = useMemo( + () => ({ + theme, + setTheme: handleSetTheme, + }), + [theme, handleSetTheme], + ); return ( diff --git a/src/components/ui/command.tsx b/src/components/ui/command.tsx index 0ce02c6..fd5c327 100644 --- a/src/components/ui/command.tsx +++ b/src/components/ui/command.tsx @@ -46,6 +46,8 @@ const CommandInput = React.forwardRef< { - // 只有在 status 改变时才触发,避免无限循环 - const currentStatus = status || "all"; - if (currentStatus !== "all" || activeView === "domains") { - setActiveView("servers"); + if (prevStatusRef.current !== status) { + prevStatusRef.current = status; + if (activeView === "domains") { + setActiveView("servers"); + } } }, [status, activeView]); @@ -586,6 +587,8 @@ export default function Servers({