From e417d3c77104dcca6136eb5460066af972656e90 Mon Sep 17 00:00:00 2001 From: Supra4E8C Date: Tue, 9 Dec 2025 00:59:40 +0800 Subject: [PATCH] feat: refactor MainLayout component to implement sidebar collapse functionality, enhance navigation item display, and improve layout responsiveness --- src/components/layout/MainLayout.tsx | 48 ++++++++-------------------- src/styles/layout.scss | 39 +++++++++++++++++++++- 2 files changed, 51 insertions(+), 36 deletions(-) diff --git a/src/components/layout/MainLayout.tsx b/src/components/layout/MainLayout.tsx index bfa23d4..fc0c21e 100644 --- a/src/components/layout/MainLayout.tsx +++ b/src/components/layout/MainLayout.tsx @@ -1,5 +1,5 @@ import { useEffect, useMemo, useState } from 'react'; -import { NavLink, Outlet, useNavigate } from 'react-router-dom'; +import { NavLink, Outlet } from 'react-router-dom'; import { useTranslation } from 'react-i18next'; import { Button } from '@/components/ui/Button'; import { useAuthStore, useConfigStore, useLanguageStore, useNotificationStore, useThemeStore } from '@/stores'; @@ -34,15 +34,12 @@ const compareVersions = (latest?: string | null, current?: string | null) => { export function MainLayout() { const { t, i18n } = useTranslation(); - const navigate = useNavigate(); const { showNotification } = useNotificationStore(); const apiBase = useAuthStore((state) => state.apiBase); const serverVersion = useAuthStore((state) => state.serverVersion); const serverBuildDate = useAuthStore((state) => state.serverBuildDate); const connectionStatus = useAuthStore((state) => state.connectionStatus); - const checkAuth = useAuthStore((state) => state.checkAuth); - const logout = useAuthStore((state) => state.logout); const config = useConfigStore((state) => state.config); const fetchConfig = useConfigStore((state) => state.fetchConfig); @@ -54,7 +51,7 @@ export function MainLayout() { const toggleLanguage = useLanguageStore((state) => state.toggleLanguage); const [sidebarOpen, setSidebarOpen] = useState(false); - const [checkingConnection, setCheckingConnection] = useState(false); + const [sidebarCollapsed, setSidebarCollapsed] = useState(false); const [checkingVersion, setCheckingVersion] = useState(false); const isLocal = useMemo(() => isLocalhost(window.location.hostname), []); @@ -96,22 +93,6 @@ export function MainLayout() { } }; - const handleCheckConnection = async () => { - setCheckingConnection(true); - try { - const ok = await checkAuth(); - if (ok) { - showNotification(t('common.connected_status'), 'success'); - } else { - showNotification(t('common.disconnected_status'), 'warning'); - } - } catch (error: any) { - showNotification(`${t('notification.login_failed')}: ${error?.message || ''}`, 'error'); - } finally { - setCheckingConnection(false); - } - }; - const handleVersionCheck = async () => { setCheckingVersion(true); try { @@ -141,15 +122,10 @@ export function MainLayout() { } }; - const handleLogout = () => { - logout(); - navigate('/login', { replace: true }); - }; - return (
-