From 01f2bb3ff10a86af9d1aacbc7fc03348e1cb9347 Mon Sep 17 00:00:00 2001 From: Lukas Date: Sat, 14 Mar 2026 12:10:44 +0100 Subject: [PATCH] Move derived encounter flags into useEncounter() hook Relocate isEmpty, hasCreatureCombatants, and canRollAllInitiative from App.tsx into useEncounter(), reducing inline derivations in the component (Phase 5 of App decomposition plan). Co-Authored-By: Claude Opus 4.6 --- apps/web/src/App.tsx | 11 +++-------- apps/web/src/hooks/use-encounter.ts | 11 +++++++++++ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/apps/web/src/App.tsx b/apps/web/src/App.tsx index c459719..25ef71d 100644 --- a/apps/web/src/App.tsx +++ b/apps/web/src/App.tsx @@ -76,6 +76,9 @@ function useActionBarAnimation(combatantCount: number) { export function App() { const { encounter, + isEmpty, + hasCreatureCombatants, + canRollAllInitiative, advanceTurn, retreatTurn, addCombatant, @@ -211,14 +214,6 @@ export function App() { sidePanel.showCreature, ]); - const isEmpty = encounter.combatants.length === 0; - const hasCreatureCombatants = encounter.combatants.some( - (c) => c.creatureId != null, - ); - const canRollAllInitiative = encounter.combatants.some( - (c) => c.creatureId != null && c.initiative == null, - ); - return (
diff --git a/apps/web/src/hooks/use-encounter.ts b/apps/web/src/hooks/use-encounter.ts index 37a307a..9c077dc 100644 --- a/apps/web/src/hooks/use-encounter.ts +++ b/apps/web/src/hooks/use-encounter.ts @@ -371,9 +371,20 @@ export function useEncounter() { [makeStore, editCombatant], ); + const isEmpty = encounter.combatants.length === 0; + const hasCreatureCombatants = encounter.combatants.some( + (c) => c.creatureId != null, + ); + const canRollAllInitiative = encounter.combatants.some( + (c) => c.creatureId != null && c.initiative == null, + ); + return { encounter, events, + isEmpty, + hasCreatureCombatants, + canRollAllInitiative, advanceTurn, retreatTurn, addCombatant,