feat: remove a saved game & redirect on missing/deleted game (#20)
CI / build + unit + e2e (pull_request) Successful in 1m14s
CI / build + unit + e2e (pull_request) Successful in 1m14s
- DELETE /api/games/:id route + Db.delete() (404 when absent) - PresetPicker: per-saved-game trash button + confirm dialog (Cancel/Delete) - App: runDeleteGame; useSse onError -> goHome on 'deleted'/'not found' (a deleted/missing game now returns the live tab and any deep link home) - DeleteGameResponse in shared/protocol.ts; api.deleteGame() - unit test (Db.delete) + 2 e2e tests (home-screen delete; in-flight delete returns the active tab home and a fresh deep link lands on home) - version 0.7.0 -> 0.8.0 + changelog Fixes #20
This commit is contained in:
@@ -5,6 +5,12 @@ import type { TurnResult } from '@shared/protocol';
|
||||
interface SseHandlers {
|
||||
onState?: (state: GameState) => void;
|
||||
onTurn?: (state: GameState, result: TurnResult) => void;
|
||||
/**
|
||||
* Fired for a server-sent NAMED `event: error` (a MessageEvent with a JSON
|
||||
* body `{ message }`) — e.g. the game was deleted or no longer exists. Pure
|
||||
* connection errors (no data) are ignored and EventSource auto-reconnects.
|
||||
*/
|
||||
onError?: (message: string) => void;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -37,8 +43,19 @@ export function useSse(id: string | null, handlers: SseHandlers): void {
|
||||
/* ignore malformed */
|
||||
}
|
||||
};
|
||||
const onError = (e: Event) => {
|
||||
if (e instanceof MessageEvent && e.data) {
|
||||
try {
|
||||
const d = JSON.parse(e.data) as { message?: string };
|
||||
if (d.message) handlersRef.current.onError?.(d.message);
|
||||
} catch {
|
||||
/* ignore malformed */
|
||||
}
|
||||
}
|
||||
};
|
||||
es.addEventListener('state', onState);
|
||||
es.addEventListener('turn', onTurn);
|
||||
es.addEventListener('error', onError);
|
||||
return () => es.close();
|
||||
}, [id]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user