mirror of
https://github.com/AmanTahiliani/box-box.git
synced 2026-08-07 19:56:18 -04:00
Add an explicit Back to Weekend link that deep-links to /?meeting_key&session_key, restore that focus on the adaptive Weekend home with a Continue analysis CTA, and regenerate Race Hub visual baselines against the integrated #80 nav. Co-authored-by: Cursor <cursoragent@cursor.com>
114 lines
3.7 KiB
TypeScript
114 lines
3.7 KiB
TypeScript
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 { WeekendFocusBanner } from '../components/weekend/WeekendFocusBanner'
|
|
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 <PreSessionView context={context} now={now} />
|
|
}
|
|
|
|
switch (view) {
|
|
case 'no_season':
|
|
return <WeekendLimited season={context.season} />
|
|
case 'between_weekends':
|
|
case 'post_weekend':
|
|
case 'season_complete':
|
|
return (
|
|
<BetweenRacesView
|
|
context={context}
|
|
now={now}
|
|
view={view}
|
|
championship={championship}
|
|
briefing={briefing}
|
|
/>
|
|
)
|
|
case 'between_sessions':
|
|
case 'session_settling':
|
|
return <BetweenSessionsView context={context} now={now} view={view} briefing={briefing} />
|
|
case 'session_live':
|
|
return <LiveHandoffView context={context} />
|
|
case 'pre_session':
|
|
return <PreSessionView context={context} now={now} />
|
|
default:
|
|
return <WeekendLimited season={context.season} />
|
|
}
|
|
}
|
|
|
|
export function WeekendPage({
|
|
preview = false,
|
|
focusMeetingKey,
|
|
focusSessionKey,
|
|
}: {
|
|
preview?: boolean
|
|
/** Restored from `/?meeting_key=` when returning from Race Hub analysis. */
|
|
focusMeetingKey?: number
|
|
/** Restored from `/?session_key=` when returning from Race Hub analysis. */
|
|
focusSessionKey?: number
|
|
}) {
|
|
const { context, loadState, error, championship, briefing, now } = useWeekendContext()
|
|
const hasFocus =
|
|
(focusMeetingKey != null && focusMeetingKey > 0) ||
|
|
(focusSessionKey != null && focusSessionKey > 0)
|
|
|
|
if (loadState === 'loading') {
|
|
return (
|
|
<main className="wk-page" data-testid="weekend-page" data-state="loading">
|
|
<WeekendLoading />
|
|
</main>
|
|
)
|
|
}
|
|
|
|
if (loadState === 'error' || context == null) {
|
|
return (
|
|
<main className="wk-page" data-testid="weekend-page" data-state="error">
|
|
<WeekendError message={error?.message} />
|
|
</main>
|
|
)
|
|
}
|
|
|
|
const view = resolveViewState(context)
|
|
|
|
return (
|
|
<main
|
|
className="wk-page"
|
|
data-testid="weekend-page"
|
|
data-state={view}
|
|
data-temporal-state={context.temporal_state}
|
|
data-preview={preview ? 'true' : undefined}
|
|
data-meeting-key={focusMeetingKey ?? undefined}
|
|
data-session-key={focusSessionKey ?? undefined}
|
|
>
|
|
{hasFocus && (
|
|
<WeekendFocusBanner meetingKey={focusMeetingKey} sessionKey={focusSessionKey} />
|
|
)}
|
|
{renderState(view, { context, now, championship, briefing, preview })}
|
|
</main>
|
|
)
|
|
}
|