import { useState, useEffect } from 'react'; import { useNavigate, useLocation, Outlet } from 'react-router-dom'; import { Button } from '@/components/ui/button'; import { ScrollArea } from '@/components/ui/scroll-area'; import { Menu, Bot, GitBranch, Database } from 'lucide-react'; import { ProjectSidebar } from '@/components/ProjectSidebar'; import { useProjectsManager } from '@/hooks/useProjectsManager'; import { useIsMobile } from '@/hooks/useIsMobile'; import { type Project } from '@/lib/ProjectsManager'; import { useCallback } from 'react'; import { cn } from '@/lib/utils'; interface SettingsItem { id: string; title: string; description: string; icon: React.ComponentType<{ className?: string }>; href: string; } const settingsItems: SettingsItem[] = [ { id: 'ai', title: 'AI Settings', description: 'Configure AI providers and API keys', icon: Bot, href: '/settings/ai', }, { id: 'git', title: 'Git Settings', description: 'Configure Git credentials for HTTP authentication', icon: GitBranch, href: '/settings/git', }, { id: 'data', title: 'Data', description: 'Export files and manage local data', icon: Database, href: '/settings/data', }, ]; export function SettingsLayout() { const navigate = useNavigate(); const location = useLocation(); const isMobile = useIsMobile(); const projectsManager = useProjectsManager(); const [_projects, setProjects] = useState([]); const [isSidebarVisible, setIsSidebarVisible] = useState(!isMobile); const [hasSetInitialState, setHasSetInitialState] = useState(false); const loadProjects = useCallback(async () => { try { await projectsManager.init(); const projectList = await projectsManager.getProjects(); setProjects(projectList); // Set initial sidebar state based on projects and device type if (!hasSetInitialState && !isMobile) { // On desktop, show sidebar if there are projects setIsSidebarVisible(true); setHasSetInitialState(true); } else if (!hasSetInitialState && isMobile) { // On mobile, always start hidden setIsSidebarVisible(false); setHasSetInitialState(true); } } catch (error) { console.error('Failed to load projects:', error); if (!hasSetInitialState) { setHasSetInitialState(true); } } }, [projectsManager, hasSetInitialState, isMobile]); useEffect(() => { loadProjects(); }, [loadProjects]); const handleProjectSelect = (project: Project | null) => { if (project) { setIsSidebarVisible(false); // Collapse sidebar on mobile navigation navigate(`/project/${project.id}`); } else { navigate('/'); } }; // Get current settings page const currentPath = location.pathname; const currentSettingsId = settingsItems.find(item => item.href === currentPath)?.id; if (isMobile) { return (
{/* Mobile Header */}

Settings

{/* Mobile Sidebar Overlay */} {isSidebarVisible && (
setIsSidebarVisible(false)} />
{ setIsSidebarVisible(false); handleProjectSelect(project); }} onClose={() => setIsSidebarVisible(false)} />
)}
); } // Desktop 3-column layout return (
{/* Left Column - Projects Sidebar (optionally hidden) */} {isSidebarVisible && (
setIsSidebarVisible(false)} />
)} {/* Middle Column - Settings Navigation */}
{/* Header with toggle button */}
{!isSidebarVisible && ( )}

Settings

{/* Settings Navigation - Scrollable */}
{settingsItems.map((item) => { const Icon = item.icon; const isActive = currentSettingsId === item.id; return ( ); })}
{/* Right Column - Settings Content - Scrollable */}
); }