// app/events/[event_id]/results/page.tsx // Event championship results page with auto-refresh import { query } from '@/lib/db'; import { TrophyIcon } from '@/components/ui/icons'; import Link from 'next/link'; import EventResultsClient from '@/components/events/EventResultsClient'; export const dynamic = "force-dynamic"; interface TeamStanding { team_id: number; team_name: string; total_points: number; races_participated: number; best_finish: number; drivers: { driver_guid: string; driver_name: string; position: number; points_awarded: number; }[]; } async function getEventResults(eventId: number) { if (eventId == undefined) { return { event: null, standings: [] }; } // Get event info const eventSql = ` SELECT event_id, event_name, event_track, event_date, event_status FROM events WHERE event_id = $1 `; const events = await query(eventSql, [String(eventId)]); const event = events[0]; // Get team standings with driver details const standingsSql = ` SELECT tcs.team_id, t.name as team_name, tcs.total_points, tcs.races_participated, tcs.best_finish, json_agg( json_build_object( 'driver_guid', u.driver_guid, 'driver_name', u.driver_name, 'position', er.position, 'points_awarded', er.points_awarded, 'laps_completed', er.laps_completed, 'dnf', er.dnf ) ORDER BY er.position ASC ) as drivers FROM team_championship_standings tcs JOIN teams t ON tcs.team_id = t.id LEFT JOIN event_results er ON tcs.event_id = er.event_id AND tcs.team_id = er.team_id LEFT JOIN users u ON er.driver_guid = u.driver_guid WHERE tcs.event_id = $1 GROUP BY tcs.team_id, t.name, tcs.total_points, tcs.races_participated, tcs.best_finish ORDER BY tcs.total_points DESC, tcs.best_finish ASC `; const standings = await query(standingsSql, [eventId]); return { event, standings }; } function getPositionColor(position: number): string { if (position === 1) return 'bg-yellow-500/20 border-yellow-500/50 text-yellow-400'; if (position === 2) return 'bg-gray-400/20 border-gray-400/50 text-gray-300'; if (position === 3) return 'bg-orange-600/20 border-orange-600/50 text-orange-400'; return 'bg-white/5 border-white/10 text-white/60'; } export default async function EventResultsPage({ params, }: { params: Promise<{ event_id: number }>; }) { const { event_id } = await params; console.log('Fetching results for event ID:', event_id); const { event, standings } = await getEventResults(event_id); if (!event) { return (
Event not found
{event.event_name}
Team points are the sum of all driver points from that team in the event • Updates every 5 seconds