diff --git a/packages/webui/src/components/layout/main-layout.tsx b/packages/webui/src/components/layout/main-layout.tsx index 30dfe59e..42e5cceb 100644 --- a/packages/webui/src/components/layout/main-layout.tsx +++ b/packages/webui/src/components/layout/main-layout.tsx @@ -1,4 +1,4 @@ -import { useEffect, useState, type ReactNode } from 'react'; +import { useState, type ReactNode } from 'react'; import { motion, AnimatePresence } from 'motion/react'; import { useRouterState } from '@tanstack/react-router'; import { Minimize2 } from 'lucide-react'; @@ -21,14 +21,6 @@ interface MainLayoutProps { export function MainLayout({ status, onLogout, children }: MainLayoutProps) { const isMobile = !useMediaQuery('(min-width: 768px)'); const { appearance } = useTheme(); - const [collapsed, setCollapsed] = useState(() => { - // An explicit per-browser toggle wins; otherwise fall back to the - // operator's `sidebarDefaultCollapsed` appearance preference. - const explicit = localStorage.getItem('snowluma_sidebar_collapsed'); - if (explicit === '1') return true; - if (explicit === '0') return false; - return appearance.sidebarDefaultCollapsed; - }); const customBg = appearance.background.type !== 'none'; // Framer's reducedMotion only suppresses transforms, so the always-present // width + page-transition animations need an explicit opt-out to make the @@ -36,27 +28,44 @@ export function MainLayout({ status, onLogout, children }: MainLayoutProps) { const reduce = appearance.reduceMotion || appearance.disableMotion; const { editing } = useLayout(); const { kiosk, exit: exitKiosk } = useKiosk(); - // Force the sidebar open while editing layout so its drag-to-reorder list - // has room (it returns to the user's collapsed pref on 完成). - const effectiveCollapsed = collapsed && !editing; + // The sidebar rests as a slim icon rail and auto-expands on hover/focus (the + // peek logic below) — there's no collapse button. Layout-edit mode force- + // expands it so the drag-to-reorder list has room. + const effectiveCollapsed = !editing; + // Hover/focus peek: while collapsed, hovering (or keyboard-focusing) the rail + // temporarily expands it. The rail lives in the flex flow, so the page + // content is pushed right rather than overlaid. The pinned `collapsed` pref + // (and the TopBar toggle that reflects it) is untouched — this is transient. + const [hovered, setHovered] = useState(false); + const [focused, setFocused] = useState(false); + const peeking = hovered || focused; + const showCollapsed = effectiveCollapsed && !peeking; const [mobileOpen, setMobileOpen] = useState(false); const pathname = useRouterState({ select: (s) => s.location.pathname }); - useEffect(() => { - localStorage.setItem('snowluma_sidebar_collapsed', collapsed ? '1' : '0'); - }, [collapsed]); - return ( -