import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; import { Outlet, Link, createRootRouteWithContext, useRouter, useNavigate, useLocation, HeadContent, Scripts, } from "@tanstack/react-router"; import { useEffect, useState, type ReactNode } from "react"; import appCss from "../styles.css?url"; import { reportLovableError } from "../lib/lovable-error-reporting"; import { BottomNav } from "../components/crapp/BottomNav"; import { CelebrazioneBadge } from "../components/crapp/CelebrazioneBadge"; import { Toaster } from "../components/ui/sonner"; import { TeamLogo } from "../components/crapp/ui-bits"; import { useGiocatoreBase } from "../lib/user-store"; import { useSessione } from "../lib/auth"; function NotFoundComponent() { return (

404

Page not found

The page you're looking for doesn't exist or has been moved.

Go home
); } function ErrorComponent({ error, reset }: { error: Error; reset: () => void }) { console.error(error); const router = useRouter(); useEffect(() => { reportLovableError(error, { boundary: "tanstack_root_error_component" }); }, [error]); return (

This page didn't load

Something went wrong on our end. You can try refreshing or head back home.

Go home
); } export const Route = createRootRouteWithContext<{ queryClient: QueryClient }>()({ head: () => ({ meta: [ { charSet: "utf-8" }, { name: "viewport", content: "width=device-width, initial-scale=1" }, { title: "CrAPP — L'app del CRAP Volley" }, { name: "description", content: "Convocazioni, presenze, statistiche e classifica del CRAP Volley in un'unica app mobile.", }, { name: "author", content: "CRAP Volley" }, { name: "theme-color", content: "#111111" }, { property: "og:title", content: "CrAPP — L'app del CRAP Volley" }, { property: "og:description", content: "Convocazioni, presenze, statistiche e classifica del CRAP Volley in un'unica app mobile.", }, { property: "og:type", content: "website" }, { name: "twitter:card", content: "summary_large_image" }, { name: "twitter:site", content: "@Lovable" }, { name: "twitter:title", content: "CrAPP — L'app del CRAP Volley" }, { name: "twitter:description", content: "Convocazioni, presenze, statistiche e classifica del CRAP Volley in un'unica app mobile.", }, { property: "og:image", content: "https://pub-bb2e103a32db4e198524a2e9ed8f35b4.r2.dev/fd5ebd0b-6661-43fa-936c-35856d1068c4/id-preview-2942946e--8d07b0e4-6bd2-4a17-9dd2-bb2cf13f9f7c.lovable.app-1785491191791.png", }, { name: "twitter:image", content: "https://pub-bb2e103a32db4e198524a2e9ed8f35b4.r2.dev/fd5ebd0b-6661-43fa-936c-35856d1068c4/id-preview-2942946e--8d07b0e4-6bd2-4a17-9dd2-bb2cf13f9f7c.lovable.app-1785491191791.png", }, ], links: [ { rel: "stylesheet", href: appCss, }, { rel: "preconnect", href: "https://fonts.googleapis.com" }, { rel: "preconnect", href: "https://fonts.gstatic.com", crossOrigin: "anonymous" }, { rel: "stylesheet", href: "https://fonts.googleapis.com/css2?family=Bebas+Neue&family=Barlow:wght@400;500;600;700;800&display=swap", }, { rel: "icon", href: "/favicon.png", type: "image/png" }, { rel: "apple-touch-icon", href: "/icon-192.png", sizes: "192x192" }, { rel: "manifest", href: "/manifest.webmanifest" }, ], }), shellComponent: RootShell, component: RootComponent, notFoundComponent: NotFoundComponent, errorComponent: ErrorComponent, }); function RootShell({ children }: { children: ReactNode }) { return ( {children} ); } function RootComponent() { const { queryClient } = Route.useRouteContext(); // `AppShell` legge la rosa da `giocatori_squadra` (useGiocatoreBase → DD-015): serve stare // dentro il QueryClientProvider, quindi il provider avvolge tutto fin da qui. return ( ); } function AppShell() { const navigate = useNavigate(); const location = useLocation(); const giocatore = useGiocatoreBase(); const { pronta, utenteId } = useSessione(); const [mounted, setMounted] = useState(false); const isBenvenuto = location.pathname === "/benvenuto"; // Senza sessione Google non si entra: l'identità la dà il login, non la scelta del nome // (DD-011). Si aspetta `pronta`, altrimenti il primo render sloggato rimbalzerebbe fuori // chi ha già la sessione in localStorage. useEffect(() => { setMounted(true); if (pronta && (!giocatore || !utenteId) && !isBenvenuto) { navigate({ to: "/benvenuto" }); } }, [giocatore, utenteId, pronta, isBenvenuto, navigate]); if (!mounted || !pronta) { return (
); } return ( <>
{/* Required: nested routes render here. Removing breaks all child routes. */}
{!isBenvenuto && } {!isBenvenuto && } ); }