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 <noreply@anthropic.com>
This commit is contained in:
@@ -76,6 +76,9 @@ function useActionBarAnimation(combatantCount: number) {
|
|||||||
export function App() {
|
export function App() {
|
||||||
const {
|
const {
|
||||||
encounter,
|
encounter,
|
||||||
|
isEmpty,
|
||||||
|
hasCreatureCombatants,
|
||||||
|
canRollAllInitiative,
|
||||||
advanceTurn,
|
advanceTurn,
|
||||||
retreatTurn,
|
retreatTurn,
|
||||||
addCombatant,
|
addCombatant,
|
||||||
@@ -211,14 +214,6 @@ export function App() {
|
|||||||
sidePanel.showCreature,
|
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 (
|
return (
|
||||||
<div className="flex h-screen flex-col">
|
<div className="flex h-screen flex-col">
|
||||||
<div className="relative mx-auto flex w-full max-w-2xl flex-1 flex-col gap-3 px-4 min-h-0">
|
<div className="relative mx-auto flex w-full max-w-2xl flex-1 flex-col gap-3 px-4 min-h-0">
|
||||||
|
|||||||
@@ -371,9 +371,20 @@ export function useEncounter() {
|
|||||||
[makeStore, editCombatant],
|
[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 {
|
return {
|
||||||
encounter,
|
encounter,
|
||||||
events,
|
events,
|
||||||
|
isEmpty,
|
||||||
|
hasCreatureCombatants,
|
||||||
|
canRollAllInitiative,
|
||||||
advanceTurn,
|
advanceTurn,
|
||||||
retreatTurn,
|
retreatTurn,
|
||||||
addCombatant,
|
addCombatant,
|
||||||
|
|||||||
Reference in New Issue
Block a user