Auto-open stat block panel when adding first bestiary creature
When the side panel is in its initial closed state (not user-collapsed), adding a combatant from the bestiary now opens the panel to show its stat block. This makes the panel discoverable without overriding a deliberate collapse. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -128,9 +128,12 @@ export function App() {
|
|||||||
|
|
||||||
const handleAddFromBestiary = useCallback(
|
const handleAddFromBestiary = useCallback(
|
||||||
(result: SearchResult) => {
|
(result: SearchResult) => {
|
||||||
addFromBestiary(result);
|
const creatureId = addFromBestiary(result);
|
||||||
|
if (creatureId && sidePanel.panelView.mode === "closed") {
|
||||||
|
sidePanel.showCreature(creatureId);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
[addFromBestiary],
|
[addFromBestiary, sidePanel.panelView.mode, sidePanel.showCreature],
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleCombatantStatBlock = useCallback(
|
const handleCombatantStatBlock = useCallback(
|
||||||
|
|||||||
@@ -137,7 +137,9 @@ describe("useEncounter", () => {
|
|||||||
type: "humanoid",
|
type: "humanoid",
|
||||||
};
|
};
|
||||||
|
|
||||||
act(() => result.current.addFromBestiary(entry));
|
act(() => {
|
||||||
|
result.current.addFromBestiary(entry);
|
||||||
|
});
|
||||||
|
|
||||||
expect(result.current.hasCreatureCombatants).toBe(true);
|
expect(result.current.hasCreatureCombatants).toBe(true);
|
||||||
expect(result.current.canRollAllInitiative).toBe(true);
|
expect(result.current.canRollAllInitiative).toBe(true);
|
||||||
@@ -158,7 +160,9 @@ describe("useEncounter", () => {
|
|||||||
type: "humanoid",
|
type: "humanoid",
|
||||||
};
|
};
|
||||||
|
|
||||||
act(() => result.current.addFromBestiary(entry));
|
act(() => {
|
||||||
|
result.current.addFromBestiary(entry);
|
||||||
|
});
|
||||||
|
|
||||||
const combatant = result.current.encounter.combatants[0];
|
const combatant = result.current.encounter.combatants[0];
|
||||||
expect(combatant.name).toBe("Goblin");
|
expect(combatant.name).toBe("Goblin");
|
||||||
@@ -183,8 +187,12 @@ describe("useEncounter", () => {
|
|||||||
type: "humanoid",
|
type: "humanoid",
|
||||||
};
|
};
|
||||||
|
|
||||||
act(() => result.current.addFromBestiary(entry));
|
act(() => {
|
||||||
act(() => result.current.addFromBestiary(entry));
|
result.current.addFromBestiary(entry);
|
||||||
|
});
|
||||||
|
act(() => {
|
||||||
|
result.current.addFromBestiary(entry);
|
||||||
|
});
|
||||||
|
|
||||||
const names = result.current.encounter.combatants.map((c) => c.name);
|
const names = result.current.encounter.combatants.map((c) => c.name);
|
||||||
expect(names).toContain("Goblin 1");
|
expect(names).toContain("Goblin 1");
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import type {
|
|||||||
BestiaryIndexEntry,
|
BestiaryIndexEntry,
|
||||||
CombatantId,
|
CombatantId,
|
||||||
ConditionId,
|
ConditionId,
|
||||||
|
CreatureId,
|
||||||
DomainEvent,
|
DomainEvent,
|
||||||
Encounter,
|
Encounter,
|
||||||
PlayerCharacter,
|
PlayerCharacter,
|
||||||
@@ -265,7 +266,7 @@ export function useEncounter() {
|
|||||||
}, [makeStore]);
|
}, [makeStore]);
|
||||||
|
|
||||||
const addFromBestiary = useCallback(
|
const addFromBestiary = useCallback(
|
||||||
(entry: BestiaryIndexEntry) => {
|
(entry: BestiaryIndexEntry): CreatureId | null => {
|
||||||
const store = makeStore();
|
const store = makeStore();
|
||||||
const existingNames = store.get().combatants.map((c) => c.name);
|
const existingNames = store.get().combatants.map((c) => c.name);
|
||||||
const { newName, renames } = resolveCreatureName(
|
const { newName, renames } = resolveCreatureName(
|
||||||
@@ -284,7 +285,7 @@ export function useEncounter() {
|
|||||||
// Add combatant with resolved name
|
// Add combatant with resolved name
|
||||||
const id = combatantId(`c-${++nextId.current}`);
|
const id = combatantId(`c-${++nextId.current}`);
|
||||||
const addResult = addCombatantUseCase(makeStore(), id, newName);
|
const addResult = addCombatantUseCase(makeStore(), id, newName);
|
||||||
if (isDomainError(addResult)) return;
|
if (isDomainError(addResult)) return null;
|
||||||
|
|
||||||
// Set HP
|
// Set HP
|
||||||
const hpResult = setHpUseCase(makeStore(), id, entry.hp);
|
const hpResult = setHpUseCase(makeStore(), id, entry.hp);
|
||||||
@@ -317,6 +318,8 @@ export function useEncounter() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
setEvents((prev) => [...prev, ...addResult]);
|
setEvents((prev) => [...prev, ...addResult]);
|
||||||
|
|
||||||
|
return cId;
|
||||||
},
|
},
|
||||||
[makeStore],
|
[makeStore],
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user