fix(race-day): keep local state while starting or timing a heat, keep count-down voice on time (1.46.1)

This commit is contained in:
larssand committed 2026-11-01 16:16:46 +01:00
1 parent 8d27072567
commit c4163441fc
8 files changed
+119 -10

No files matched your search

+9 -2
View File
@@ -156,12 +156,19 @@ export function applyPersistedStateHelper(persisted, deps) {
applyTheme();
}
export async function hydrateFromBackendHelper({ backend, t, getBackendUrl, applyPersistedState, saveState }) {
// keepLocal: true while this browser is running the race (count-down, start sequence, a
// live heat on its decoder). Then this browser's copy is the newest, and replacing it would
// turn a heat that just started back to "ready" or drop laps that came in meanwhile.
export async function hydrateFromBackendHelper({ backend, t, getBackendUrl, applyPersistedState, saveState, getLocalStateVersion = () => 0, getLocalStateDirty = () => false, keepLocal = () => false }) {
if (keepLocal()) return;
const versionAtFetch = getLocalStateVersion();
try {
const res = await fetch(`${getBackendUrl()}/api/state`);
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const payload = await res.json();
if (payload && payload.state && typeof payload.state === "object") {
// Something changed here while the request was out (a lap, a start): this copy is older.
const staleCopy = getLocalStateVersion() !== versionAtFetch || getLocalStateDirty() || keepLocal();
if (!staleCopy && payload && payload.state && typeof payload.state === "object") {
applyPersistedState(payload.state);
saveState({ skipBackend: true });
backend.lastSyncAt = payload.updatedAt || new Date().toISOString();