// Client for the town.deception.listMaps XRPC query: the curated set of playable maps the server // offers (AT-URI + display name), used to populate a map chooser without the player pasting a raw // AT-URI. Public read — no session needed. // // The result is cached in a shared promise so the fetch can be kicked off *preemptively* (e.g. when // the user hovers/opens the Deduction folder) and is already resolved by the time the selector // renders on the takeover page. export interface MapRef { uri: string name: string } let mapsPromise: Promise | null = null async function fetchMaps(): Promise { const res = await fetch('/xrpc/town.deception.listMaps') if (!res.ok) throw new Error(`listMaps failed: ${res.status}`) const data = (await res.json()) as { maps?: MapRef[] } return data.maps ?? [] } /** * Start (or reuse) the curated-maps fetch and cache the promise. Idempotent — safe to call eagerly * and repeatedly (hover, click). A failed fetch clears the cache so a later call retries. */ export function prefetchMaps(): Promise { if (!mapsPromise) { mapsPromise = fetchMaps().catch((err) => { mapsPromise = null throw err }) } return mapsPromise } /** The curated maps — resolves from the prefetch cache when one is already in flight or done. */ export function listMaps(): Promise { return prefetchMaps() }