import { useEffect, useState } from "react"; import { cn } from "@/lib/utils"; import { ExternalLink } from "lucide-react"; import { links } from "@/data/Sidebar"; import { VersionInfo } from "./VersionInfo"; interface SidebarProps { className?: string; onNavigate?: (page: string) => void; isOpen: boolean; onClose: () => void; } export function Sidebar({ className, onNavigate, isOpen, onClose }: SidebarProps) { const [currentPath, setCurrentPath] = useState(""); useEffect(() => { // Hydration happens here const path = window.location.pathname; setCurrentPath(path); }, []); // Listen for URL changes (browser back/forward) useEffect(() => { const handlePopState = () => { setCurrentPath(window.location.pathname); }; window.addEventListener('popstate', handlePopState); return () => window.removeEventListener('popstate', handlePopState); }, []); const handleNavigation = (href: string, event: React.MouseEvent) => { event.preventDefault(); // Don't navigate if already on the same page if (currentPath === href) return; // Update URL without page reload window.history.pushState({}, '', href); setCurrentPath(href); // Map href to page name for the parent component const pageMap: Record = { '/': 'dashboard', '/repositories': 'repositories', '/organizations': 'organizations', '/config': 'configuration', '/activity': 'activity-log' }; const pageName = pageMap[href] || 'dashboard'; onNavigate?.(pageName); // Close sidebar on mobile after navigation if (window.innerWidth < 1024) { onClose(); } }; return ( <> {/* Mobile Backdrop */} {isOpen && (
)} {/* Sidebar */} ); }