Roll back renames on failed compound add operations
addFromBestiary and addFromPlayerCharacter rename existing combatants before adding the new one. If the add fails, the renames were applied without an undo entry. Restore the pre-operation snapshot on failure. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -328,7 +328,10 @@ export function useEncounter() {
|
|||||||
creatureId: cId,
|
creatureId: cId,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (isDomainError(result)) return null;
|
if (isDomainError(result)) {
|
||||||
|
store.save(snapshot);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
const newState = pushUndo(undoRedoRef.current, snapshot);
|
const newState = pushUndo(undoRedoRef.current, snapshot);
|
||||||
undoRedoRef.current = newState;
|
undoRedoRef.current = newState;
|
||||||
@@ -363,7 +366,10 @@ export function useEncounter() {
|
|||||||
playerCharacterId: pc.id,
|
playerCharacterId: pc.id,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (isDomainError(result)) return;
|
if (isDomainError(result)) {
|
||||||
|
store.save(snapshot);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const newState = pushUndo(undoRedoRef.current, snapshot);
|
const newState = pushUndo(undoRedoRef.current, snapshot);
|
||||||
undoRedoRef.current = newState;
|
undoRedoRef.current = newState;
|
||||||
|
|||||||
Reference in New Issue
Block a user