From 10d4616601f8d48d97dedf1eca4ca64124eac720 Mon Sep 17 00:00:00 2001 From: samanhappy Date: Fri, 2 May 2025 12:40:11 +0800 Subject: [PATCH] Implement theme switching and enhance dark mode support (#43) --- frontend/src/App.tsx | 51 +++++++------ frontend/src/components/AddGroupForm.tsx | 2 +- frontend/src/components/AddServerForm.tsx | 2 +- frontend/src/components/EditGroupForm.tsx | 2 +- frontend/src/components/EditServerForm.tsx | 2 +- .../src/components/MarketServerDetail.tsx | 2 +- frontend/src/components/layout/Content.tsx | 4 +- frontend/src/components/layout/Header.tsx | 14 ++-- frontend/src/components/layout/Sidebar.tsx | 6 +- frontend/src/components/ui/ThemeSwitch.tsx | 51 +++++++++++++ frontend/src/contexts/ThemeContext.tsx | 76 +++++++++++++++++++ frontend/src/index.css | 48 +++++++++++- frontend/src/layouts/MainLayout.tsx | 2 +- frontend/src/locales/en.json | 6 ++ frontend/src/locales/zh.json | 6 ++ frontend/src/pages/LoginPage.tsx | 14 ++-- frontend/src/pages/SettingsPage.tsx | 14 ++-- frontend/tailwind.config.js | 12 +++ 18 files changed, 261 insertions(+), 53 deletions(-) create mode 100644 frontend/src/components/ui/ThemeSwitch.tsx create mode 100644 frontend/src/contexts/ThemeContext.tsx create mode 100644 frontend/tailwind.config.js diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 68db2b0..9cc9940 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -2,6 +2,7 @@ import React from 'react'; import { BrowserRouter as Router, Route, Routes, Navigate } from 'react-router-dom'; import { AuthProvider } from './contexts/AuthContext'; import { ToastProvider } from './contexts/ToastContext'; +import { ThemeProvider } from './contexts/ThemeContext'; import MainLayout from './layouts/MainLayout'; import ProtectedRoute from './components/ProtectedRoute'; import LoginPage from './pages/LoginPage'; @@ -13,31 +14,33 @@ import MarketPage from './pages/MarketPage'; function App() { return ( - - - - - {/* 公共路由 */} - } /> - - {/* 受保护的路由,使用 MainLayout 作为布局容器 */} - }> - }> - } /> - } /> - } /> - } /> - } /> - } /> + + + + + + {/* 公共路由 */} + } /> + + {/* 受保护的路由,使用 MainLayout 作为布局容器 */} + }> + }> + } /> + } /> + } /> + } /> + } /> + } /> + - - - {/* 未匹配的路由重定向到首页 */} - } /> - - - - + + {/* 未匹配的路由重定向到首页 */} + } /> + + + + + ); } diff --git a/frontend/src/components/AddGroupForm.tsx b/frontend/src/components/AddGroupForm.tsx index dc94c24..ad40ef6 100644 --- a/frontend/src/components/AddGroupForm.tsx +++ b/frontend/src/components/AddGroupForm.tsx @@ -65,7 +65,7 @@ const AddGroupForm = ({ onAdd, onCancel }: AddGroupFormProps) => { } return ( -
+

{t('groups.addNew')}

diff --git a/frontend/src/components/AddServerForm.tsx b/frontend/src/components/AddServerForm.tsx index 4a2d862..4d84a79 100644 --- a/frontend/src/components/AddServerForm.tsx +++ b/frontend/src/components/AddServerForm.tsx @@ -74,7 +74,7 @@ const AddServerForm = ({ onAdd }: AddServerFormProps) => { {modalVisible && ( -
+
{ } return ( -
+

{t('groups.edit')}

diff --git a/frontend/src/components/EditServerForm.tsx b/frontend/src/components/EditServerForm.tsx index 04893f7..3078be7 100644 --- a/frontend/src/components/EditServerForm.tsx +++ b/frontend/src/components/EditServerForm.tsx @@ -61,7 +61,7 @@ const EditServerForm = ({ server, onEdit, onCancel }: EditServerFormProps) => { } return ( -
+
= ({
{modalVisible && ( -
+
= ({ children }) => { return ( -
-
+
+
{children}
diff --git a/frontend/src/components/layout/Header.tsx b/frontend/src/components/layout/Header.tsx index 103ceba..1a718a8 100644 --- a/frontend/src/components/layout/Header.tsx +++ b/frontend/src/components/layout/Header.tsx @@ -2,6 +2,7 @@ import React from 'react'; import { useTranslation } from 'react-i18next'; import { useNavigate } from 'react-router-dom'; import { useAuth } from '@/contexts/AuthContext'; +import ThemeSwitch from '@/components/ui/ThemeSwitch'; interface HeaderProps { onToggleSidebar: () => void; @@ -18,13 +19,13 @@ const Header: React.FC = ({ onToggleSidebar }) => { }; return ( -
+
{/* 侧边栏切换按钮 */} {/* 应用标题 */} -

{t('app.title')}

+

{t('app.title')}

{/* 用户信息和操作 */}
+ {/* Theme Switch */} + + {auth.user && ( - + {t('app.welcomeUser', { username: auth.user.username })} )} @@ -47,7 +51,7 @@ const Header: React.FC = ({ onToggleSidebar }) => {
diff --git a/frontend/src/components/layout/Sidebar.tsx b/frontend/src/components/layout/Sidebar.tsx index 50c13b9..96111d8 100644 --- a/frontend/src/components/layout/Sidebar.tsx +++ b/frontend/src/components/layout/Sidebar.tsx @@ -68,7 +68,7 @@ const Sidebar: React.FC = ({ collapsed }) => { return (