Refactor useEncounter from useState to useReducer

Replaces 18 useCallback wrappers with a typed action union and
encounterReducer. Undo/redo wrapping is now systematic per-case in
the reducer instead of ad-hoc per operation. Complex cases (undo/redo,
bestiary add, player character add) are extracted into helper functions.

The stat block auto-show on bestiary add now uses lastCreatureId from
reducer state instead of the synchronous return value, with a useEffect
in use-action-bar-state to react to changes.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Lukas
2026-03-28 18:41:40 +01:00
parent 896fd427ed
commit 80dd68752e
3 changed files with 460 additions and 292 deletions

View File

@@ -72,6 +72,7 @@ function mockContext(overrides: Partial<Encounter> = {}) {
setEncounter: vi.fn(),
setUndoRedoState: vi.fn(),
events: [],
lastCreatureId: null,
};
mockUseEncounterContext.mockReturnValue(