import React, { useEffect } from 'react'; import { useNavigate, useLocation } from 'react-router-dom'; import '@/styles/sidebar.css'; interface SidebarProps { isOpen?: boolean; onClose?: () => void; } export const Sidebar: React.FC = ({ isOpen, onClose }) => { const navigate = useNavigate(); const location = useLocation(); const currentPath = location.pathname.split('/')[1] || 'applications'; useEffect(() => { const previousOverflow = document.body.style.overflow; if (isOpen) { document.body.style.overflow = 'hidden'; } else { document.body.style.overflow = previousOverflow || ''; } return () => { document.body.style.overflow = previousOverflow; }; }, [isOpen]); // Active tab on a subpage (/applications/, ?page=3) stays clickable: it is the way back. const isOnPage = (page: string) => page === currentPath && location.pathname.replace(/\/+$/, '').split('/').length <= 2 && !location.search; const getButtonClass = (page: string) => { const baseClass = "sidebar-nav-button flex items-center"; if (page !== currentPath) return baseClass; return isOnPage(page) ? `${baseClass} active current` : `${baseClass} active`; }; const handleNavigation = (path: string) => { if (!isOnPage(path)) navigate(`/${path}`); onClose?.(); // close drawer on mobile after navigation }; // Drawer for mobile const Drawer = () => (
{/* Overlay */}
{/* Drawer panel */}
); return ( <> {/* Drawer only on mobile */} {/* Sidebar only on desktop */} ); };