import { createContext, useContext } from "solid-js"; import type { Accessor } from "solid-js"; import type { Me, PersonState } from "./api"; /** * What the routed pages need from the shell. * * A context rather than props because route components are constructed by the * router and cannot be handed anything. It holds the *live* store, so both pages * share one polling loop rather than starting one each. */ export interface SessionValue { me: Me; people: Record; order: Accessor; serverTime: Accessor; selected: Accessor; select: (id: number) => void; trail: Accessor<[number, number][] | null>; } export const SessionContext = createContext(); export function useSession(): SessionValue { const value = useContext(SessionContext); if (!value) throw new Error("useSession outside the shell"); return value; }