diff --git a/apps/web/src/hooks/use-auto-stat-block.ts b/apps/web/src/hooks/use-auto-stat-block.ts index c5ab110..d1b4abe 100644 --- a/apps/web/src/hooks/use-auto-stat-block.ts +++ b/apps/web/src/hooks/use-auto-stat-block.ts @@ -1,4 +1,4 @@ -import { useEffect } from "react"; +import { useEffect, useRef } from "react"; import { useEncounterContext } from "../contexts/encounter-context.js"; import { useSidePanelContext } from "../contexts/side-panel-context.js"; @@ -8,10 +8,20 @@ export function useAutoStatBlock(): void { const activeCreatureId = encounter.combatants[encounter.activeIndex]?.creatureId; + const prevActiveIndexRef = useRef(encounter.activeIndex); useEffect(() => { - if (activeCreatureId && panelView.mode === "creature") { + const prevIndex = prevActiveIndexRef.current; + prevActiveIndexRef.current = encounter.activeIndex; + + // Only auto-update when the active turn changes (advance/retreat), + // not when the panel mode changes (user clicking a different creature). + if ( + encounter.activeIndex !== prevIndex && + activeCreatureId && + panelView.mode === "creature" + ) { updateCreature(activeCreatureId); } - }, [activeCreatureId, panelView.mode, updateCreature]); + }, [encounter.activeIndex, activeCreatureId, panelView.mode, updateCreature]); }