'use client'; import { useState, useEffect } from 'react'; import Card from '@/components/ui/Card'; import StandingsTable from '@/components/leagues/StandingsTable'; import type { DriverDTO } from '@gridpilot/racing/application/dto/DriverDTO'; import type { LeagueDriverSeasonStatsDTO } from '@gridpilot/racing/application/dto/LeagueDriverSeasonStatsDTO'; import { EntityMappers } from '@gridpilot/racing/application/mappers/EntityMappers'; import { getGetLeagueDriverSeasonStatsQuery, getDriverRepository } from '@/lib/di-container'; export default function LeagueStandingsPage({ params }: { params: { id: string } }) { const leagueId = params.id; const [standings, setStandings] = useState([]); const [drivers, setDrivers] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const loadData = async () => { try { const getLeagueDriverSeasonStatsQuery = getGetLeagueDriverSeasonStatsQuery(); const driverRepo = getDriverRepository(); const leagueStandings = await getLeagueDriverSeasonStatsQuery.execute({ leagueId }); setStandings(leagueStandings); const allDrivers = await driverRepo.findAll(); const driverDtos: DriverDTO[] = allDrivers .map((driver) => EntityMappers.toDriverDTO(driver)) .filter((dto): dto is DriverDTO => dto !== null); setDrivers(driverDtos); } catch (err) { setError(err instanceof Error ? err.message : 'Failed to load standings'); } finally { setLoading(false); } }; useEffect(() => { loadData(); // eslint-disable-next-line react-hooks/exhaustive-deps }, [leagueId]); if (loading) { return (
Loading standings...
); } if (error) { return (
{error}
); } return (

Standings

); }