import { useEffect, type ReactNode } from "react"; import { Route, Routes } from "react-router"; import { useApi } from "./api/context"; import { startClockTicker, syncClock } from "./clock/clock"; import { AwaySummary } from "./components/AwaySummary"; import { formatCredits } from "./format"; import { Layout } from "./layout/Layout"; import { SCREENS } from "./routes"; import { HQ } from "./screens/HQ"; import { Placeholder } from "./screens/Placeholder"; import { StartScreen } from "./screens/StartScreen"; import { usePlayerState, useRefetchOnArrival } from "./state/player"; /** Built screens by path; the rest show a placeholder. */ const SCREEN_COMPONENTS: Partial> = { "/": , }; /** Syncs the clock with the server once, then ticks it every second. */ function useServerClock() { const api = useApi(); useEffect(() => { syncClock(api).catch(() => { // Offline or server down: keep the device clock until the next launch. }); return startClockTicker(); }, [api]); } /** The whole client. Router, API and query providers come from the caller. */ export function App() { useServerClock(); const state = usePlayerState(); useRefetchOnArrival(state.data ?? null, state.refetch); if (state.isPending) { return

Loading…

; } if (state.isError) { return (

Could not reach the server.

); } if (state.data === null) return ; return ( <> }> {SCREENS.map((screen) => ( } /> ))} ); }