import { useEffect, useState } from "react"; import { useLocation, Link } from "react-router-dom"; import { useQuery } from "@tanstack/react-query"; import { getHealthUseCase } from "@/application/container"; import { AppSidebar } from "./AppSidebar"; import { AppMobileHeader } from "./AppMobileHeader"; import { PageBreadcrumb } from "./PageBreadcrumb"; import { AmbientBackground } from "./AmbientBackground"; import { AnimatedOutlet } from "./AnimatedOutlet"; import { ApiOfflineBanner } from "./ApiOfflineBanner"; import { ToastContainer } from "@/presentation/components/ui/toast"; import { allNavItems } from "./navConfig"; export function AppLayout() { const [mobileOpen, setMobileOpen] = useState(false); const [bannerDismissed, setBannerDismissed] = useState(false); const location = useLocation(); const { data: health, isError: healthError, isPending: healthPending, refetch: refetchHealth, } = useQuery({ queryKey: ["health"], queryFn: () => getHealthUseCase.execute(), staleTime: 60_000, retry: 1, }); useEffect(() => { setMobileOpen(false); }, [location.pathname]); useEffect(() => { if (!healthError) { setBannerDismissed(false); } }, [healthError]); useEffect(() => { document.title = pageTitle(location.pathname); }, [location.pathname]); return (
Ir para o conteúdo
setMobileOpen((v) => !v)} onClose={() => setMobileOpen(false)} health={health} healthPending={healthPending} healthError={healthError} />
{!healthPending && healthError && !bannerDismissed && ( refetchHealth()} onDismiss={() => setBannerDismissed(true)} /> )}
); } function pageTitle(pathname: string): string { const item = allNavItems.find((nav) => nav.end ? pathname === nav.to : pathname.startsWith(nav.to) && nav.to !== "/", ); if (pathname === "/" || !item) { return item?.label ? `${item.label} · Bolão AI` : "Bolão AI — Previsões Esportivas"; } return `${item.label} · Bolão AI`; }