From 3251d69b92f4033f0997a6c3cdc879137af1ee91 Mon Sep 17 00:00:00 2001 From: Montia37 Date: Tue, 9 Sep 2025 23:50:18 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E4=BA=AE=E6=9A=97?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F=E5=88=87=E6=8D=A2=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/sections/Header.tsx | 174 +++++++++++++++++++--------- src/components/ui/dropdown-menu.tsx | 20 ++-- src/hooks/useTheme.ts | 83 ++++++++----- src/main.tsx | 29 +---- src/pages/Home.tsx | 9 +- 5 files changed, 190 insertions(+), 125 deletions(-) diff --git a/src/components/sections/Header.tsx b/src/components/sections/Header.tsx index e5ceef9..4fd24aa 100644 --- a/src/components/sections/Header.tsx +++ b/src/components/sections/Header.tsx @@ -6,6 +6,7 @@ import { Table2, Moon, Sun, + SunMoon, CircleUserIcon, Menu, } from "lucide-react"; @@ -18,23 +19,19 @@ import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, + DropdownMenuSub, + DropdownMenuSubContent, + DropdownMenuSubTrigger, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu"; interface HeaderProps { - viewMode: "grid" | "table"; - setViewMode: (mode: "grid" | "table") => void; searchTerm: string; setSearchTerm: (term: string) => void; } -export const Header = ({ - viewMode, - setViewMode, - searchTerm, - setSearchTerm, -}: HeaderProps) => { - const { appearance, setAppearance } = useTheme(); +export const Header = ({ searchTerm, setSearchTerm }: HeaderProps) => { + const { rawAppearance, setAppearance, viewMode, setViewMode } = useTheme(); const [isSearchOpen, setIsSearchOpen] = useState(false); const location = useLocation(); const isInstancePage = location.pathname.startsWith("/instance"); @@ -52,10 +49,6 @@ export const Header = ({ } }, [sitename]); - const toggleAppearance = () => { - setAppearance(appearance === "light" ? "dark" : "light"); - }; - return (
@@ -128,16 +121,35 @@ export const Header = ({ {viewMode === "grid" ? "表格视图" : "网格视图"} - - {appearance === "dark" ? ( - - ) : ( - - )} - - {appearance === "dark" ? "浅色模式" : "深色模式"} - - + + + {rawAppearance === "light" ? ( + + ) : rawAppearance === "dark" ? ( + + ) : ( + + )} + 切换主题 + + + setAppearance("light")}> + + 浅色模式 + + setAppearance("dark")}> + + 深色模式 + + setAppearance("system")}> + + 跟随系统 + + + {enableAdminButton && ( )} - + + + + + + setAppearance("light")}> + + 浅色模式 + + setAppearance("dark")}> + + 深色模式 + + setAppearance("system")}> + + 跟随系统 + + + {enableAdminButton && ( + + + + + + setAppearance("light")}> + + 浅色模式 + + setAppearance("dark")}> + + 深色模式 + + setAppearance("system")}> + + 跟随系统 + + + {enableAdminButton && (