import { useWeekendContext } from '../hooks/useWeekendContext' import { BetweenRacesView } from '../components/weekend/BetweenRacesView' import { BetweenSessionsView } from '../components/weekend/BetweenSessionsView' import { LiveHandoffView } from '../components/weekend/LiveHandoffView' import { PreSessionView } from '../components/weekend/PreSessionView' import { WeekendError, WeekendLimited, WeekendLoading } from '../components/weekend/StatusViews' import { resolveViewState } from '../lib/weekendContext' import type { WeekendBriefingItem, WeekendChampionshipImpact, WeekendContext, WeekendViewState, } from '../types' import '../styles/weekend.css' interface RenderArgs { context: WeekendContext now: Date championship?: WeekendChampionshipImpact briefing: WeekendBriefingItem[] /** When true (the /preview alias), foreground the preparation surface. */ preview: boolean } function renderState(view: WeekendViewState, args: RenderArgs) { const { context, now, championship, briefing, preview } = args // The /preview alias always resolves to the preparation surface as long as // there is a next event to prepare for, regardless of the temporal state. This // keeps saved /preview links and the "Prepare for …" CTA meaningful instead of // redirecting straight back to the same between-races screen. if (preview && context.next_meeting) { return } switch (view) { case 'no_season': return case 'between_weekends': case 'post_weekend': case 'season_complete': return ( ) case 'between_sessions': case 'session_settling': return case 'session_live': return case 'pre_session': return default: return } } export function WeekendPage({ preview = false }: { preview?: boolean }) { const { context, loadState, error, championship, briefing, now } = useWeekendContext() if (loadState === 'loading') { return (
) } if (loadState === 'error' || context == null) { return (
) } const view = resolveViewState(context) return (
{renderState(view, { context, now, championship, briefing, preview })}
) }