"use client"; import { useAuth } from "@/lib/auth-context"; import { usePathname } from "next/navigation"; import { useEffect } from "react"; import { Sidebar } from "./Sidebar"; import { TopBar } from "./TopBar"; import { TVLayout } from "./TVLayout"; import { BottomNavigation } from "./BottomNavigation"; import { UniversalPlayer } from "../player/UniversalPlayer"; import { MediaControlsHandler } from "../player/MediaControlsHandler"; import { PlayerModeWrapper } from "../player/PlayerModeWrapper"; import { ActivityPanel } from "./ActivityPanel"; import { GalaxyBackground } from "../ui/GalaxyBackground"; import { GradientSpinner } from "../ui/GradientSpinner"; import { PWAInstallPrompt } from "../PWAInstallPrompt"; import { PullToRefresh } from "../ui/PullToRefresh"; import { ReactNode } from "react"; import { useIsMobile, useIsTablet } from "@/hooks/useMediaQuery"; import { useIsTV } from "@/lib/tv-utils"; import { useActivityPanel } from "@/hooks/useActivityPanel"; const publicPaths = ["/login", "/register", "/onboarding", "/sync"]; export function AuthenticatedLayout({ children }: { children: ReactNode }) { const { isAuthenticated, isLoading } = useAuth(); const pathname = usePathname(); const isMobile = useIsMobile(); const isTablet = useIsTablet(); const isTV = useIsTV(); const isMobileOrTablet = isMobile || isTablet; const activityPanel = useActivityPanel(); // Listen for activity panel events (toggle/open/close/tab) useEffect(() => { const handleToggle = () => activityPanel.toggle(); const handleOpen = () => activityPanel.open(); const handleClose = () => activityPanel.close(); const handleSetTab = ( e: CustomEvent<{ tab: "notifications" | "active" | "history" }> ) => { activityPanel.setActiveTab(e.detail.tab); }; window.addEventListener("toggle-activity-panel", handleToggle); window.addEventListener("open-activity-panel", handleOpen); window.addEventListener("close-activity-panel", handleClose); window.addEventListener( "set-activity-panel-tab", handleSetTab as EventListener ); return () => { window.removeEventListener("toggle-activity-panel", handleToggle); window.removeEventListener("open-activity-panel", handleOpen); window.removeEventListener("close-activity-panel", handleClose); window.removeEventListener( "set-activity-panel-tab", handleSetTab as EventListener ); }; }, [activityPanel]); const isPublicPage = publicPaths.includes(pathname); // Show loading state only on protected pages if (!isPublicPage && isLoading) { return (
Loading...
Redirecting...