diff --git a/frontend/src/layouts/AppSidebar.css b/frontend/src/layouts/AppSidebar.css index 392b5b6a3..6a54a8b00 100644 --- a/frontend/src/layouts/AppSidebar.css +++ b/frontend/src/layouts/AppSidebar.css @@ -12,7 +12,7 @@ align-self: flex-start; } -.ant-sidebar > .ant-layout-sider:not(.ant-layout-sider-collapsed) { +.ant-sidebar:not(.sidebar-pinned) > .ant-layout-sider:not(.ant-layout-sider-collapsed) { box-shadow: 0 0 32px rgba(0, 0, 0, 0.22); } diff --git a/frontend/src/layouts/AppSidebar.tsx b/frontend/src/layouts/AppSidebar.tsx index 9a2965c4f..c464fc329 100644 --- a/frontend/src/layouts/AppSidebar.tsx +++ b/frontend/src/layouts/AppSidebar.tsx @@ -46,8 +46,8 @@ const DOCS_URL = 'https://docs.sanaei.dev/'; const REPO_URL = 'https://github.com/MHSanaei/3x-ui'; const LOGOUT_KEY = '__logout__'; const RAIL_WIDTH = 72; +const SIDER_WIDTH = 220; const SIDEBAR_PINNED_KEY = 'sidebar-pinned'; -const railStyle = { '--sider-rail': `${RAIL_WIDTH}px` } as CSSProperties; let hoveredAcrossRemounts = false; @@ -164,6 +164,10 @@ export default function AppSidebar() { const [pinned, setPinned] = useState(readSidebarPinned); const [drawerOpen, setDrawerOpen] = useState(false); const railCollapsed = !hovered && !pinned; + const railStyle = useMemo( + () => ({ '--sider-rail': `${pinned ? SIDER_WIDTH : RAIL_WIDTH}px` }) as CSSProperties, + [pinned], + ); const rootRef = useRef(null); const updateHovered = useCallback((value: boolean) => { @@ -172,12 +176,10 @@ export default function AppSidebar() { }, []); const togglePinned = useCallback(() => { - setPinned((value) => { - const next = !value; - saveSidebarPinned(next); - return next; - }); - }, []); + const next = !pinned; + saveSidebarPinned(next); + setPinned(next); + }, [pinned]); useEffect(() => { const timer = window.setTimeout(() => { @@ -287,14 +289,14 @@ export default function AppSidebar() { return (
updateHovered(true)} onMouseLeave={() => updateHovered(false)} > @@ -307,7 +309,7 @@ export default function AppSidebar() {