The Campionato page showed hardcoded demo data. It now reads the real 2025/26 season (Campionato Open Misto Eccellenza, project 767, team 3359, Girone B) from the Livescore CSI Bologna portal. The portal has no documented API: we call the same endpoints its own pages call over ajax, so parsing must degrade gracefully. A single server route fetches them, caches for 6 hours and serves the last good payload on failure; the page falls back to the previous data when nothing is available. No browser ever contacts the portal, keeping the request count independent of how many players open the app. Also fixes the header, which claimed "Girone C - CSI Milano". Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
22 lines
561 B
TypeScript
22 lines
561 B
TypeScript
import { useQuery } from "@tanstack/react-query";
|
|
import type { DatiCsi } from "./csi-core";
|
|
|
|
export const CSI_KEY = ["csi"] as const;
|
|
|
|
/**
|
|
* Classifica e risultati ufficiali CSI. Il server tiene una cache di 6 ore:
|
|
* qui basta una lettura per sessione.
|
|
*/
|
|
export function useCsi() {
|
|
return useQuery<DatiCsi>({
|
|
queryKey: CSI_KEY,
|
|
queryFn: async () => {
|
|
const res = await fetch("/api/public/csi");
|
|
if (!res.ok) throw new Error("CSI non disponibile");
|
|
return res.json();
|
|
},
|
|
staleTime: 6 * 60 * 60_000,
|
|
retry: 1,
|
|
});
|
|
}
|