import { lazy, Suspense, 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 { DealModal } from "./components/DealModal"; import { formatCredits } from "./format"; import { tabAttention } from "./layout/attention"; import { Layout } from "./layout/Layout"; import { SCREENS } from "./routes"; import { Contracts } from "./screens/Contracts"; import { Fleet } from "./screens/Fleet"; import { HQ } from "./screens/HQ"; import { Locations } from "./screens/Locations"; import { Market } from "./screens/Market"; import { Pilots } from "./screens/Pilots"; import { Settings } from "./screens/Settings"; import { useMotionPreference } from "./state/preferences"; import { StartScreen } from "./screens/StartScreen"; import { usePlayerState, useRefetchOnArrival } from "./state/player"; import { Button } from "./ui"; // The map pulls in PixiJS; load it only when the Map tab is opened. const MapScreen = lazy(() => import("./screens/MapScreen").then((m) => ({ default: m.MapScreen }))); const SCREEN_COMPONENTS: Record<(typeof SCREENS)[number]["path"], ReactNode> = { "/": , "/map": ( Loading map…

}>
), "/contracts": , "/fleet": , "/pilots": , "/market": , "/locations": , }; /** 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(); useMotionPreference(); const state = usePlayerState(); useRefetchOnArrival(state.data ?? null, state.refetch); const retry = () => void state.refetch(); if (state.isPending) { return (

Loading…

); } if (state.data === undefined) { // The first load failed: nothing to show yet. return (

Could not reach the server.

); } if (state.data === null) return ; // A later refresh failed: keep showing the last state, with a way to retry. const banner = state.isError ? (
Offline — showing last update.
) : null; return ( <> } > {SCREENS.map((screen) => ( ))} {/* Settings opens from the header gear, not a tab (CR-011). */} } /> ); }