diff --git a/apps/ui/src/components/layout/sidebar/components/sidebar-navigation.tsx b/apps/ui/src/components/layout/sidebar/components/sidebar-navigation.tsx index e7fd179e..293fb7e4 100644 --- a/apps/ui/src/components/layout/sidebar/components/sidebar-navigation.tsx +++ b/apps/ui/src/components/layout/sidebar/components/sidebar-navigation.tsx @@ -1,10 +1,11 @@ -import { useState, useCallback, useEffect, useRef } from 'react'; +import { useCallback, useEffect, useRef } from 'react'; import type { NavigateOptions } from '@tanstack/react-router'; import { ChevronDown, Wrench, Github } from 'lucide-react'; import { cn } from '@/lib/utils'; -import { formatShortcut } from '@/store/app-store'; +import { formatShortcut, useAppStore } from '@/store/app-store'; import type { NavSection } from '../types'; import type { Project } from '@/lib/electron'; +import type { SidebarStyle } from '@automaker/types'; import { Spinner } from '@/components/ui/spinner'; import { DropdownMenu, @@ -23,6 +24,7 @@ const sectionIcons: Record> interface SidebarNavigationProps { currentProject: Project | null; sidebarOpen: boolean; + sidebarStyle: SidebarStyle; navSections: NavSection[]; isActiveRoute: (id: string) => boolean; navigate: (opts: NavigateOptions) => void; @@ -32,6 +34,7 @@ interface SidebarNavigationProps { export function SidebarNavigation({ currentProject, sidebarOpen, + sidebarStyle, navSections, isActiveRoute, navigate, @@ -39,21 +42,26 @@ export function SidebarNavigation({ }: SidebarNavigationProps) { const navRef = useRef(null); - // Track collapsed state for each collapsible section - const [collapsedSections, setCollapsedSections] = useState>({}); + // Get collapsed state from store (persisted across restarts) + const { collapsedNavSections, setCollapsedNavSections, toggleNavSection } = useAppStore(); // Initialize collapsed state when sections change (e.g., GitHub section appears) + // Only set defaults for sections that don't have a persisted state useEffect(() => { - setCollapsedSections((prev) => { - const updated = { ...prev }; - navSections.forEach((section) => { - if (section.collapsible && section.label && !(section.label in updated)) { - updated[section.label] = section.defaultCollapsed ?? false; - } - }); - return updated; + let hasNewSections = false; + const updated = { ...collapsedNavSections }; + + navSections.forEach((section) => { + if (section.collapsible && section.label && !(section.label in updated)) { + updated[section.label] = section.defaultCollapsed ?? false; + hasNewSections = true; + } }); - }, [navSections]); + + if (hasNewSections) { + setCollapsedNavSections(updated); + } + }, [navSections, collapsedNavSections, setCollapsedNavSections]); // Check scroll state const checkScrollState = useCallback(() => { @@ -77,14 +85,7 @@ export function SidebarNavigation({ nav.removeEventListener('scroll', checkScrollState); resizeObserver.disconnect(); }; - }, [checkScrollState, collapsedSections]); - - const toggleSection = useCallback((label: string) => { - setCollapsedSections((prev) => ({ - ...prev, - [label]: !prev[label], - })); - }, []); + }, [checkScrollState, collapsedNavSections]); // Filter sections: always show non-project sections, only show project sections when project exists const visibleSections = navSections.filter((section) => { @@ -97,10 +98,17 @@ export function SidebarNavigation({ }); return ( -