import { Heading, Text, Box, Spinner, Alert, AlertIcon, Table, Thead, Tbody, Tr, Th, Td, VStack, Select, HStack, Badge } from '@chakra-ui/react'; import { useQuery } from '@tanstack/react-query'; import { useMemo, useState } from 'react'; import AdminLayout from '../../layouts/AdminLayout'; import { assetUrl } from '../../utils/url'; import { TeamLogo } from '../../components/common/TeamLogo'; import { API_URL } from '../../services/api'; type TableRow = { rank?: string; team?: string; team_id?: string; team_logo_url?: string; played?: string; wins?: string; draws?: string; losses?: string; score?: string; points?: string; }; const StandingsAdminPage: React.FC = () => { const { data, isLoading, error } = useQuery({ queryKey: ['facr-tables-cache'], queryFn: async () => { const origin = new URL(API_URL, typeof window !== 'undefined' ? window.location.origin : 'http://localhost:3000').origin; const url = `${origin}/cache/prefetch/facr_tables.json`; const res = await fetch(url, { headers: { 'Cache-Control': 'no-cache' } }); if (!res.ok) throw new Error(`Failed to load cache: ${res.status}`); return res.json(); }, staleTime: 5 * 60 * 1000, }); const competitions: any[] = Array.isArray(data?.competitions) ? data!.competitions : []; // Optional category/code switcher based on competition code const [code, setCode] = useState(''); const options = useMemo(() => { const items = competitions.map((c) => ({ code: c.code, name: c.name })); const unique = new Map(items.map((i) => [i.code, i])); return Array.from(unique.values()); }, [competitions]); const filtered = code ? competitions.filter((c) => c.code === code) : competitions; return ( Standings (FAČR) Read-only view of standings from FACR cache. Fast and offline-friendly. {isLoading && ( Načítám tabulky… )} {Boolean(error) && ( Nepodařilo se načíst data z cache. )} {!isLoading && !error && ( Soutěž: {filtered.length} soutěží )} {!isLoading && !error && filtered.map((comp) => { const rows: TableRow[] = comp?.table?.overall || []; return ( {comp.name} {rows.map((r, idx) => ( ))}
# Tým Z V R P Skóre Body
{r.rank} {r.team?.substring(0, 2).toUpperCase() || '??'} } /> {r.team} {r.played} {r.wins} {r.draws} {r.losses} {r.score} {r.points}
); })}
); }; export default StandingsAdminPage;