feat: v0.10.0 — right Jobs & Market pane (contracts accept/dispatch, market buy/sell/refuel with live previews); catalog + economy constants exposed in /api/state; shared applySnapshot for instant action feedback

This commit is contained in:
2026-09-17 19:18:42 +00:00
parent 03653fc50e
commit cf811dcf4d
15 changed files with 894 additions and 14 deletions
+14 -1
View File
@@ -10,6 +10,11 @@ export interface GameStateResult {
error: string | null;
// Trigger an immediate refetch (used after POST /api/sim so the UI updates without waiting for the next tick).
refresh: () => void;
// Push a snapshot straight into the shared state (v0.10.0): every action endpoint returns
// the FULL post-action snapshot, so panes can render its result on click instead of waiting
// for the next poll tick. The polling loop keeps running and simply overwrites it with the
// server's truth on its next cycle (which also re-clears any transient pane error).
applySnapshot: (snapshot: StateSnapshot) => void;
}
// Single fetch of the full game-state snapshot. Exported separately from the hook so it can be unit-tested with a mocked fetch.
@@ -45,11 +50,19 @@ export function useGameState(intervalMs = 1000): GameStateResult {
});
}, []);
// v0.10.0 — instant action feedback: panes push the full snapshot returned by an
// action endpoint into the shared state here (see GameStateResult.applySnapshot).
const applySnapshot = useCallback((snapshot: StateSnapshot) => {
setState(snapshot);
setError(null);
setLoading(false);
}, []);
useEffect(() => {
refresh(); // fetch immediately on mount, don't wait for the first interval tick
const id = setInterval(refresh, intervalMs);
return () => clearInterval(id);
}, [intervalMs, refresh]);
return { state, loading, error, refresh };
return { state, loading, error, refresh, applySnapshot };
}