Something went wrong. Try again.
A Social Deduction / Deception Game
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041// 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<MapRef[]> | null = null
async function fetchMaps(): Promise<MapRef[]> { 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<MapRef[]> { 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<MapRef[]> { return prefetchMaps()}