import React, { useState, useEffect } from "react"; import { useLocation } from "react-router-dom"; import { cn } from "@/lib/utils"; import Header from "./header"; import Sidebar from "./sidebar"; import Footer from "./watermark-footer"; import { useIsMobile } from "@/hooks/use-mobile"; import useKeyboardShortcuts from "@/hooks/useKeyboardShortcuts"; import { useAuth } from "@/lib/auth-context"; import GlobalWorkNotifications from "@/components/GlobalWorkNotifications"; interface LayoutProps { children: React.ReactNode; } const Layout = ({ children }: LayoutProps) => { const isMobile = useIsMobile(); const [isSidebarOpen, setIsSidebarOpen] = useState(!isMobile); const location = useLocation(); const { isAuthenticated } = useAuth(); // Check if we're on the download app page const isDownloadPage = location.pathname === "/download-app"; const isLoginPage = location.pathname === "/login"; // Initialize keyboard shortcuts useKeyboardShortcuts(); // Close sidebar on mobile when route changes useEffect(() => { if (isMobile) { setIsSidebarOpen(false); } }, [location, isMobile]); // Update sidebar state when screen size changes useEffect(() => { setIsSidebarOpen(!isMobile); }, [isMobile]); // Update sidebar state when authentication changes useEffect(() => { if (isAuthenticated && !isMobile) { setIsSidebarOpen(true); } }, [isAuthenticated, isMobile]); return (
{/* Only show sidebar when authenticated */} {isAuthenticated && ( )}
setIsSidebarOpen(!isSidebarOpen)} isSidebarOpen={isSidebarOpen} />
{children}
{/* Overlay for mobile sidebar */} {isSidebarOpen && isMobile && (
setIsSidebarOpen(false)} /> )} {/* Global Work Notifications - Show on all pages when authenticated */} {isAuthenticated && }
); }; export default Layout;