Add undo/redo for all encounter actions
Memento-based undo/redo with full encounter snapshots. Undo stack capped at 50 entries, persisted to localStorage. Triggered via buttons in the top bar (inboard of turn navigation) and keyboard shortcuts (Ctrl+Z / Ctrl+Shift+Z, Cmd on Mac, case-insensitive key matching). Clear encounter resets both stacks. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
24
packages/application/src/redo-use-case.ts
Normal file
24
packages/application/src/redo-use-case.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import {
|
||||
type DomainError,
|
||||
type Encounter,
|
||||
isDomainError,
|
||||
redo,
|
||||
} from "@initiative/domain";
|
||||
import type { EncounterStore, UndoRedoStore } from "./ports.js";
|
||||
|
||||
export function redoUseCase(
|
||||
encounterStore: EncounterStore,
|
||||
undoRedoStore: UndoRedoStore,
|
||||
): Encounter | DomainError {
|
||||
const current = encounterStore.get();
|
||||
const state = undoRedoStore.get();
|
||||
const result = redo(state, current);
|
||||
|
||||
if (isDomainError(result)) {
|
||||
return result;
|
||||
}
|
||||
|
||||
encounterStore.save(result.encounter);
|
||||
undoRedoStore.save(result.state);
|
||||
return result.encounter;
|
||||
}
|
||||
Reference in New Issue
Block a user