import { useState, useEffect, useRef } from 'react'; import { Link, useLocation, Outlet, Navigate } from 'react-router-dom'; import { useGetMe } from '../generated/anthoLumeAPIV1'; import { useAuth } from '../auth/AuthContext'; import { UserIcon, DropdownIcon } from '../icons'; import HamburgerMenu from './HamburgerMenu'; export default function Layout() { const location = useLocation(); const { isAuthenticated, user, logout, isCheckingAuth } = useAuth(); const { data } = useGetMe(isAuthenticated ? {} : undefined); const userData = data?.data || user; const [isUserDropdownOpen, setIsUserDropdownOpen] = useState(false); const dropdownRef = useRef(null); const handleLogout = () => { logout(); setIsUserDropdownOpen(false); }; // Close dropdown when clicking outside useEffect(() => { const handleClickOutside = (event: MouseEvent) => { if (dropdownRef.current && !dropdownRef.current.contains(event.target as Node)) { setIsUserDropdownOpen(false); } }; document.addEventListener('mousedown', handleClickOutside); return () => { document.removeEventListener('mousedown', handleClickOutside); }; }, []); // Get current page title const navItems = [ { path: '/', title: 'Home' }, { path: '/documents', title: 'Documents' }, { path: '/progress', title: 'Progress' }, { path: '/activity', title: 'Activity' }, { path: '/search', title: 'Search' }, { path: '/settings', title: 'Settings' }, ]; const currentPageTitle = navItems.find(item => location.pathname === item.path)?.title || 'Documents'; // Show loading while checking authentication status if (isCheckingAuth) { return
Loading...
; } // Redirect to login if not authenticated if (!isAuthenticated) { return ; } return (
{/* Header */}
{/* Mobile Navigation Button with CSS animations */} {/* Header Title */}

{currentPageTitle}

{/* User Dropdown */}
{isUserDropdownOpen && (
setIsUserDropdownOpen(false)} className="block px-4 py-2 text-gray-700 hover:bg-gray-100 hover:text-gray-900 dark:text-gray-100 dark:hover:bg-gray-600 dark:hover:text-white" role="menuitem" > Settings
)}
{/* Main Content */}
); }