Batch bestiary add produces a single undo entry
All checks were successful
CI / check (push) Successful in 1m10s
CI / build-image (push) Successful in 15s

Extract addOneFromBestiary (no undo) and build addMultipleFromBestiary
on top so confirming N creatures from the bestiary panel creates one
undo entry that restores the entire batch, not N individual entries.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Lukas
2026-03-27 00:07:25 +01:00
parent 541e04b732
commit 9437272fe0
3 changed files with 70 additions and 12 deletions

View File

@@ -26,8 +26,12 @@ export function creatureKey(r: SearchResult): string {
}
export function useActionBarState() {
const { addCombatant, addFromBestiary, addFromPlayerCharacter } =
useEncounterContext();
const {
addCombatant,
addFromBestiary,
addMultipleFromBestiary,
addFromPlayerCharacter,
} = useEncounterContext();
const { search: bestiarySearch, isLoaded: bestiaryLoaded } =
useBestiaryContext();
const { characters: playerCharacters } = usePlayerCharactersContext();
@@ -92,11 +96,24 @@ export function useActionBarState() {
const confirmQueued = useCallback(() => {
if (!queued) return;
for (let i = 0; i < queued.count; i++) {
if (queued.count === 1) {
handleAddFromBestiary(queued.result);
} else {
const creatureId = addMultipleFromBestiary(queued.result, queued.count);
const isDesktop = globalThis.matchMedia("(min-width: 1024px)").matches;
if (creatureId && panelView.mode === "closed" && isDesktop) {
showCreature(creatureId);
}
}
clearInput();
}, [queued, handleAddFromBestiary, clearInput]);
}, [
queued,
handleAddFromBestiary,
addMultipleFromBestiary,
panelView.mode,
showCreature,
clearInput,
]);
const parseNum = (v: string): number | undefined => {
if (v.trim() === "") return undefined;