import { Box, Button, Heading, HStack, Input, Spinner, Table, Tbody, Td, Th, Thead, Tr, Text, VStack, List, ListItem } from '@chakra-ui/react'; import { useEffect, useMemo, useState } from 'react'; import { useQuery } from '@tanstack/react-query'; import { facrApi } from '../services/facr/facrApi'; import type { ClubInfo, Competition, TableRow, SearchResult } from '../services/facr/types'; import { TeamLogo } from '../components/common/TeamLogo'; type SelectedClub = { clubId: string; clubType: 'football' | 'futsal' }; const STORAGE_KEY = 'facrClub'; const StandingsPage: React.FC = () => { const [query, setQuery] = useState(''); const [selected, setSelected] = useState(null); useEffect(() => { const saved = localStorage.getItem(STORAGE_KEY); if (saved) { try { setSelected(JSON.parse(saved)); } catch {} } }, []); useEffect(() => { if (selected) localStorage.setItem(STORAGE_KEY, JSON.stringify(selected)); }, [selected]); const { data: searchData, isFetching: searching } = useQuery({ queryKey: ['facr', 'search', query], queryFn: () => facrApi.searchClubs(query), enabled: query.trim().length >= 3, }); const { data: clubTable, isLoading, isError } = useQuery({ queryKey: ['facr', 'clubTable', selected?.clubType, selected?.clubId], queryFn: () => facrApi.getClubTable(selected!.clubId, selected!.clubType), enabled: !!selected, }); const tableRows: TableRow[] = useMemo(() => { if (!clubTable?.competitions) return []; // pick first competition that has table.overall const compWithTable: Competition | undefined = clubTable.competitions.find(c => c.table?.overall?.length) || clubTable.competitions[0]; return compWithTable?.table?.overall || []; }, [clubTable]); return ( Tabulka setQuery(e.target.value)} /> {searchData?.results?.length ? ( {searchData.results.slice(0, 8).map((r: SearchResult) => ( ))} ) : null} {!selected && ( Vyberte klub pro zobrazení tabulky soutěže. )} {selected && isLoading && } {selected && isError && Chyba při načítání tabulky} {selected && !isLoading && ( {tableRows.map((row) => ( ))} {tableRows.length === 0 && ( )}
# Tým Z V R P Skóre Body
{row.rank} {row.team} {row.played} {row.wins} {row.draws} {row.losses} {row.score} {row.points}
Tabulka není dostupná.
)}
); } export default StandingsPage;