2026-08-06 08:36:47 +02:00
|
|
|
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";
|
2026-09-07 08:56:33 +02:00
|
|
|
import { useGiocatoriSquadra } from "../lib/giocatori-squadra";
|
2026-08-31 18:21:34 +02:00
|
|
|
import { useSessione } from "../lib/auth";
|
2026-09-06 14:24:07 +02:00
|
|
|
import { mantieniWorkerPushAggiornato } from "../lib/push-client";
|
2026-08-06 08:36:47 +02:00
|
|
|
|
|
|
|
|
function NotFoundComponent() {
|
|
|
|
|
return (
|
2026-09-05 14:50:32 +02:00
|
|
|
<div className="flex min-h-dvh items-center justify-center bg-background px-4">
|
2026-08-06 08:36:47 +02:00
|
|
|
<div className="max-w-md text-center">
|
2026-09-05 12:41:36 +02:00
|
|
|
<h1 className="font-display-lg text-7xl text-foreground">404</h1>
|
|
|
|
|
<h2 className="mt-4 text-xl font-semibold text-foreground">Pagina non trovata</h2>
|
2026-08-06 08:36:47 +02:00
|
|
|
<p className="mt-2 text-sm text-muted-foreground">
|
2026-09-05 12:41:36 +02:00
|
|
|
La pagina che cerchi non esiste o è stata spostata.
|
2026-08-06 08:36:47 +02:00
|
|
|
</p>
|
|
|
|
|
<div className="mt-6">
|
|
|
|
|
<Link
|
|
|
|
|
to="/"
|
2026-09-05 12:41:36 +02:00
|
|
|
className="premi inline-flex min-h-11 items-center justify-center rounded-2xl bg-primary px-4 py-2 text-sm font-semibold text-primary-foreground"
|
2026-08-06 08:36:47 +02:00
|
|
|
>
|
2026-09-05 12:41:36 +02:00
|
|
|
Torna alla home
|
2026-08-06 08:36:47 +02:00
|
|
|
</Link>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function ErrorComponent({ error, reset }: { error: Error; reset: () => void }) {
|
|
|
|
|
console.error(error);
|
|
|
|
|
const router = useRouter();
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
reportLovableError(error, { boundary: "tanstack_root_error_component" });
|
|
|
|
|
}, [error]);
|
|
|
|
|
|
|
|
|
|
return (
|
2026-09-05 14:50:32 +02:00
|
|
|
<div className="flex min-h-dvh items-center justify-center bg-background px-4">
|
2026-08-06 08:36:47 +02:00
|
|
|
<div className="max-w-md text-center">
|
|
|
|
|
<h1 className="text-xl font-semibold tracking-tight text-foreground">
|
2026-09-05 12:41:36 +02:00
|
|
|
Questa pagina non si è caricata
|
2026-08-06 08:36:47 +02:00
|
|
|
</h1>
|
|
|
|
|
<p className="mt-2 text-sm text-muted-foreground">
|
2026-09-05 12:41:36 +02:00
|
|
|
Qualcosa è andato storto da parte nostra. Puoi riprovare o tornare alla home.
|
2026-08-06 08:36:47 +02:00
|
|
|
</p>
|
|
|
|
|
<div className="mt-6 flex flex-wrap justify-center gap-2">
|
|
|
|
|
<button
|
2026-09-05 12:41:36 +02:00
|
|
|
type="button"
|
2026-08-06 08:36:47 +02:00
|
|
|
onClick={() => {
|
|
|
|
|
router.invalidate();
|
|
|
|
|
reset();
|
|
|
|
|
}}
|
2026-09-05 12:41:36 +02:00
|
|
|
className="premi inline-flex min-h-11 items-center justify-center rounded-2xl bg-primary px-4 py-2 text-sm font-semibold text-primary-foreground"
|
2026-08-06 08:36:47 +02:00
|
|
|
>
|
2026-09-05 12:41:36 +02:00
|
|
|
Riprova
|
2026-08-06 08:36:47 +02:00
|
|
|
</button>
|
|
|
|
|
<a
|
|
|
|
|
href="/"
|
2026-09-05 12:41:36 +02:00
|
|
|
className="premi inline-flex min-h-11 items-center justify-center rounded-2xl border border-border bg-card px-4 py-2 text-sm font-semibold text-foreground"
|
2026-08-06 08:36:47 +02:00
|
|
|
>
|
2026-09-05 12:41:36 +02:00
|
|
|
Torna alla home
|
2026-08-06 08:36:47 +02:00
|
|
|
</a>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const Route = createRootRouteWithContext<{ queryClient: QueryClient }>()({
|
|
|
|
|
head: () => ({
|
|
|
|
|
meta: [
|
|
|
|
|
{ charSet: "utf-8" },
|
2026-09-05 12:41:36 +02:00
|
|
|
// `viewport-fit=cover` è obbligatorio perché env(safe-area-inset-*) sia
|
|
|
|
|
// diverso da 0 su iOS: senza, la BottomNav finisce sotto la home bar.
|
|
|
|
|
{
|
|
|
|
|
name: "viewport",
|
|
|
|
|
content: "width=device-width, initial-scale=1, viewport-fit=cover",
|
|
|
|
|
},
|
2026-08-06 08:36:47 +02:00
|
|
|
{ title: "CrAPP — L'app del CRAP Volley" },
|
|
|
|
|
{
|
|
|
|
|
name: "description",
|
2026-09-01 13:38:33 +02:00
|
|
|
content:
|
|
|
|
|
"Convocazioni, presenze, statistiche e classifica del CRAP Volley in un'unica app mobile.",
|
2026-08-06 08:36:47 +02:00
|
|
|
},
|
|
|
|
|
{ name: "author", content: "CRAP Volley" },
|
2026-09-05 12:41:36 +02:00
|
|
|
// Deve combaciare con --background, altrimenti la barra di stato resta
|
|
|
|
|
// nera sopra un'interfaccia chiara.
|
2026-09-05 20:02:13 +02:00
|
|
|
{ name: "theme-color", content: "#e4e8ed" },
|
2026-08-06 08:36:47 +02:00
|
|
|
{ property: "og:title", content: "CrAPP — L'app del CRAP Volley" },
|
|
|
|
|
{
|
|
|
|
|
property: "og:description",
|
2026-09-01 13:38:33 +02:00
|
|
|
content:
|
|
|
|
|
"Convocazioni, presenze, statistiche e classifica del CRAP Volley in un'unica app mobile.",
|
2026-08-06 08:36:47 +02:00
|
|
|
},
|
|
|
|
|
{ property: "og:type", content: "website" },
|
2026-09-05 12:41:36 +02:00
|
|
|
// `summary` e non `summary_large_image`: l'unica immagine è l'icona
|
|
|
|
|
// quadrata della squadra, non una copertina 2:1.
|
|
|
|
|
{ name: "twitter:card", content: "summary" },
|
2026-08-06 08:36:47 +02:00
|
|
|
{ name: "twitter:title", content: "CrAPP — L'app del CRAP Volley" },
|
2026-09-01 13:38:33 +02:00
|
|
|
{
|
|
|
|
|
name: "twitter:description",
|
|
|
|
|
content:
|
|
|
|
|
"Convocazioni, presenze, statistiche e classifica del CRAP Volley in un'unica app mobile.",
|
|
|
|
|
},
|
2026-09-05 12:41:36 +02:00
|
|
|
{ property: "og:image", content: "/icon-512.png" },
|
|
|
|
|
{ name: "twitter:image", content: "/icon-512.png" },
|
2026-08-06 08:36:47 +02:00
|
|
|
],
|
|
|
|
|
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 (
|
2026-09-05 12:41:36 +02:00
|
|
|
<html lang="it">
|
2026-08-06 08:36:47 +02:00
|
|
|
<head>
|
|
|
|
|
<HeadContent />
|
|
|
|
|
</head>
|
|
|
|
|
<body>
|
|
|
|
|
{children}
|
|
|
|
|
<Scripts />
|
|
|
|
|
</body>
|
|
|
|
|
</html>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function RootComponent() {
|
|
|
|
|
const { queryClient } = Route.useRouteContext();
|
2026-09-03 10:16:40 +02:00
|
|
|
// `AppShell` legge la rosa da `giocatori_squadra` (useGiocatoreBase → DD-015): serve stare
|
|
|
|
|
// dentro il QueryClientProvider, quindi il provider avvolge tutto fin da qui.
|
|
|
|
|
return (
|
|
|
|
|
<QueryClientProvider client={queryClient}>
|
|
|
|
|
<AppShell />
|
|
|
|
|
</QueryClientProvider>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function AppShell() {
|
2026-08-06 08:36:47 +02:00
|
|
|
const navigate = useNavigate();
|
|
|
|
|
const location = useLocation();
|
|
|
|
|
const giocatore = useGiocatoreBase();
|
2026-09-07 08:56:33 +02:00
|
|
|
const { isPending: squadraInCorso } = useGiocatoriSquadra();
|
2026-08-31 18:21:34 +02:00
|
|
|
const { pronta, utenteId } = useSessione();
|
2026-08-06 08:36:47 +02:00
|
|
|
const [mounted, setMounted] = useState(false);
|
|
|
|
|
const isBenvenuto = location.pathname === "/benvenuto";
|
|
|
|
|
|
2026-09-06 14:24:07 +02:00
|
|
|
useEffect(mantieniWorkerPushAggiornato, []);
|
|
|
|
|
|
2026-08-31 18:21:34 +02:00
|
|
|
// 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
|
2026-09-07 08:56:33 +02:00
|
|
|
// chi ha già la sessione in localStorage. Si aspetta anche `squadraInCorso`: finché la
|
|
|
|
|
// rosa non è arrivata, `giocatore` risulta nullo anche per chi è già collegato (la rosa
|
|
|
|
|
// di riserva usa id diversi da quelli veri), e rimbalzerebbe su /benvenuto chi stava solo
|
|
|
|
|
// ricaricando una pagina profonda come /eventi.
|
2026-08-06 08:36:47 +02:00
|
|
|
useEffect(() => {
|
|
|
|
|
setMounted(true);
|
2026-09-07 08:56:33 +02:00
|
|
|
if (pronta && !squadraInCorso && (!giocatore || !utenteId) && !isBenvenuto) {
|
|
|
|
|
navigate({ to: "/benvenuto", search: { next: location.pathname } });
|
2026-08-06 08:36:47 +02:00
|
|
|
}
|
2026-09-07 08:56:33 +02:00
|
|
|
}, [giocatore, utenteId, pronta, squadraInCorso, isBenvenuto, navigate, location.pathname]);
|
2026-08-06 08:36:47 +02:00
|
|
|
|
2026-09-07 08:56:33 +02:00
|
|
|
if (!mounted || !pronta || squadraInCorso) {
|
2026-08-06 08:36:47 +02:00
|
|
|
return (
|
2026-09-05 14:50:32 +02:00
|
|
|
<div className="grid min-h-dvh place-items-center bg-background">
|
2026-08-06 08:36:47 +02:00
|
|
|
<TeamLogo className="h-16 w-16 animate-pulse" />
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
2026-09-03 10:16:40 +02:00
|
|
|
<>
|
2026-09-05 14:50:32 +02:00
|
|
|
<div className="spazio-nav mx-auto min-h-dvh max-w-md bg-background">
|
2026-08-06 08:36:47 +02:00
|
|
|
{/* Required: nested routes render here. Removing <Outlet /> breaks all child routes. */}
|
|
|
|
|
<Outlet />
|
|
|
|
|
</div>
|
|
|
|
|
{!isBenvenuto && <BottomNav />}
|
|
|
|
|
{!isBenvenuto && <CelebrazioneBadge />}
|
|
|
|
|
<Toaster position="top-center" duration={3500} closeButton />
|
2026-09-03 10:16:40 +02:00
|
|
|
</>
|
2026-08-06 08:36:47 +02:00
|
|
|
);
|
|
|
|
|
}
|