Show toast and open source panel when rolling initiative without loaded source
When a user clicks the d20 to roll initiative for a single combatant whose bestiary source isn't cached, show an informative toast and open the stat block panel so they can load the source directly. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -117,6 +117,7 @@ export function App() {
|
|||||||
const sidePanel = useSidePanelState();
|
const sidePanel = useSidePanelState();
|
||||||
|
|
||||||
const [rollSkippedCount, setRollSkippedCount] = useState(0);
|
const [rollSkippedCount, setRollSkippedCount] = useState(0);
|
||||||
|
const [rollSingleSkipped, setRollSingleSkipped] = useState(false);
|
||||||
|
|
||||||
const selectedCreature: Creature | null = sidePanel.selectedCreatureId
|
const selectedCreature: Creature | null = sidePanel.selectedCreatureId
|
||||||
? (getCreature(sidePanel.selectedCreatureId) ?? null)
|
? (getCreature(sidePanel.selectedCreatureId) ?? null)
|
||||||
@@ -145,9 +146,21 @@ export function App() {
|
|||||||
|
|
||||||
const handleRollInitiative = useCallback(
|
const handleRollInitiative = useCallback(
|
||||||
(id: CombatantId) => {
|
(id: CombatantId) => {
|
||||||
rollInitiativeUseCase(makeStore(), id, rollDice(), getCreature);
|
const result = rollInitiativeUseCase(
|
||||||
|
makeStore(),
|
||||||
|
id,
|
||||||
|
rollDice(),
|
||||||
|
getCreature,
|
||||||
|
);
|
||||||
|
if (isDomainError(result)) {
|
||||||
|
setRollSingleSkipped(true);
|
||||||
|
const combatant = encounter.combatants.find((c) => c.id === id);
|
||||||
|
if (combatant?.creatureId) {
|
||||||
|
sidePanel.showCreature(combatant.creatureId);
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
[makeStore, getCreature],
|
[makeStore, getCreature, encounter.combatants, sidePanel.showCreature],
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleRollAllInitiative = useCallback(() => {
|
const handleRollAllInitiative = useCallback(() => {
|
||||||
@@ -363,6 +376,14 @@ export function App() {
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{!!rollSingleSkipped && (
|
||||||
|
<Toast
|
||||||
|
message="Can't roll — bestiary source not loaded"
|
||||||
|
onDismiss={() => setRollSingleSkipped(false)}
|
||||||
|
autoDismissMs={4000}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
<PlayerCharacterSection
|
<PlayerCharacterSection
|
||||||
ref={playerCharacterRef}
|
ref={playerCharacterRef}
|
||||||
characters={playerCharacters}
|
characters={playerCharacters}
|
||||||
|
|||||||
Reference in New Issue
Block a user