V1.25.0: the DM approves a level, each player takes their own
- "Level up..." beside Rest approves a level for any of the party at once; with XP tracked, those who have the XP start ticked - Each player is told with a notice and picks for themselves in the checklist: class (multiclass), subclass, Boon, spells within the level's allowance, the weapon upgrade; a waiting level shows on the sheet and campaign page - The DM sees who still has picks to make, and can finish or take back any - Hit points on a level up can be rolled (campaign setting): by the site, or at the table and typed in with physical dice - Toasts: notices that slide in over any page Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -4,6 +4,7 @@ import { useAuth } from '../auth/useAuth';
|
||||
import { useLastCampaignId, useRememberCampaign } from '../lib/lastCampaign';
|
||||
import { DiceRoller } from './DiceRoller';
|
||||
import { CharacterPanel } from './CharacterPanel';
|
||||
import { Toasts } from './Toasts';
|
||||
|
||||
export function Layout() {
|
||||
const { user, logout } = useAuth();
|
||||
@@ -70,6 +71,7 @@ export function Layout() {
|
||||
)}
|
||||
<DiceRoller />
|
||||
{user && <CharacterPanel />}
|
||||
<Toasts />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,135 @@
|
||||
import { useState } from 'react';
|
||||
import { useApproveLevelUps } from '../api/queries';
|
||||
import { classLabel, extractErrorMessage } from '../lib/format';
|
||||
import { Modal } from './Modal';
|
||||
import { ErrorBanner } from './Spinner';
|
||||
import type { CharacterSummary, LevelUpApproval } from '../api/types';
|
||||
|
||||
const MAX_LEVEL = 20;
|
||||
|
||||
// The DM's level-up button: approve a level for any of the party at once.
|
||||
// Each approval is a checklist waiting for its character: their player is
|
||||
// told and makes the picks themselves, so nobody queues for the DM. A
|
||||
// character without a player is the DM's to finish, from its sheet.
|
||||
// `trackXp`: with XP kept, those who have the XP for their next level start
|
||||
// ticked; without it (milestones) the DM ticks who levels.
|
||||
export function LevelUpBulkModal({
|
||||
campaignId,
|
||||
characters,
|
||||
trackXp,
|
||||
onClose,
|
||||
}: {
|
||||
campaignId: string;
|
||||
characters: CharacterSummary[];
|
||||
trackXp: boolean;
|
||||
onClose: () => void;
|
||||
}) {
|
||||
const approve = useApproveLevelUps(campaignId);
|
||||
const party = characters.filter((c) => c.buildStage === 'COMPLETE');
|
||||
const canLevel = (c: CharacterSummary) => c.level + c.levelUpsPending < MAX_LEVEL;
|
||||
const [picked, setPicked] = useState<Set<string>>(() => new Set(party.filter((c) => trackXp && c.xpProgress.levelUpDue && canLevel(c)).map((c) => c.id)));
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [done, setDone] = useState<LevelUpApproval[] | null>(null);
|
||||
|
||||
function toggle(id: string) {
|
||||
setPicked((current) => {
|
||||
const next = new Set(current);
|
||||
if (!next.delete(id)) next.add(id);
|
||||
return next;
|
||||
});
|
||||
}
|
||||
|
||||
async function send(characterIds: string[], revoke = false) {
|
||||
setError(null);
|
||||
try {
|
||||
const { results } = await approve.mutateAsync({ characterIds, revoke });
|
||||
if (!revoke) setDone(results);
|
||||
} catch (err) {
|
||||
setError(extractErrorMessage(err));
|
||||
}
|
||||
}
|
||||
|
||||
if (done) {
|
||||
return (
|
||||
<Modal title="Level ups approved" subtitle="Each player makes their own picks" onClose={onClose}>
|
||||
{done.map((result) => (
|
||||
<div key={result.characterId} className="reward-row">
|
||||
<strong>{result.name}</strong>
|
||||
{result.skipped ? (
|
||||
<div className="combatant-sub">{result.skipped}</div>
|
||||
) : (
|
||||
<div className="combatant-sub">
|
||||
Level {result.level} → {result.level + 1} is theirs to take.{' '}
|
||||
{result.userId ? 'Their player has been told and chooses what they gain.' : 'No player: finish it from the sheet.'}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
<div className="modal-foot">
|
||||
<button className="btn btn-primary" onClick={onClose}>
|
||||
Done
|
||||
</button>
|
||||
</div>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Modal title="Level up" subtitle="Approve a level for the party; each player then picks what they gain" wide onClose={onClose}>
|
||||
{error && <ErrorBanner message={error} />}
|
||||
<div className="flex-row flex-wrap gap-sm">
|
||||
<button className="btn" onClick={() => setPicked(new Set(party.filter(canLevel).map((c) => c.id)))}>
|
||||
Everyone
|
||||
</button>
|
||||
{trackXp && (
|
||||
<button className="btn" onClick={() => setPicked(new Set(party.filter((c) => c.xpProgress.levelUpDue && canLevel(c)).map((c) => c.id)))}>
|
||||
Those with the XP
|
||||
</button>
|
||||
)}
|
||||
<button className="btn btn-ghost" onClick={() => setPicked(new Set())}>
|
||||
Nobody
|
||||
</button>
|
||||
</div>
|
||||
<div className="mt-md">
|
||||
{party.length === 0 && <p className="combatant-sub">No finished characters yet.</p>}
|
||||
{party.map((c) => (
|
||||
<label key={c.id} className="checkbox-row level-choice" style={canLevel(c) ? undefined : { opacity: 0.55 }}>
|
||||
<input type="checkbox" checked={picked.has(c.id)} disabled={!canLevel(c)} onChange={() => toggle(c.id)} />
|
||||
<span style={{ flex: 1 }}>
|
||||
<strong>{c.name}</strong>{' '}
|
||||
<span className="combatant-sub">
|
||||
{classLabel(c.characterClass, c.subclassName, c.classes)} · Level {c.level}
|
||||
</span>
|
||||
{trackXp && c.xpProgress.levelUpDue && <span className="badge badge-live" style={{ marginLeft: 6 }}>has the XP</span>}
|
||||
{c.levelUpsPending > 0 && (
|
||||
<span className="badge" style={{ marginLeft: 6 }}>
|
||||
{c.levelUpsPending} waiting on their picks
|
||||
</span>
|
||||
)}
|
||||
{!c.userId && <span className="badge" style={{ marginLeft: 6 }}>no player: yours to finish</span>}
|
||||
</span>
|
||||
{c.levelUpsPending > 0 && (
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-ghost btn-sm"
|
||||
title="Takes back one approved level that has not been taken yet"
|
||||
disabled={approve.isPending}
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
send([c.id], true);
|
||||
}}
|
||||
>
|
||||
Take one back
|
||||
</button>
|
||||
)}
|
||||
</label>
|
||||
))}
|
||||
</div>
|
||||
<div className="modal-foot">
|
||||
<button className="btn btn-primary" disabled={picked.size === 0 || approve.isPending} onClick={() => send([...picked])}>
|
||||
{approve.isPending ? 'Approving…' : `Approve a level for ${picked.size} character${picked.size === 1 ? '' : 's'}`}
|
||||
</button>
|
||||
</div>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
@@ -2,8 +2,10 @@ import { useState, type ReactNode } from 'react';
|
||||
import { useLevelUp, useLevelUpPlan } from '../api/queries';
|
||||
import { CLASS_LABELS, classLabel, extractErrorMessage, slotLevelLabel, slotsSummary, spellLevelLabel } from '../lib/format';
|
||||
import { Modal } from './Modal';
|
||||
import { NumberInput } from './NumberInput';
|
||||
import { Spinner, ErrorBanner } from './Spinner';
|
||||
import type { CharacterClass, CharacterDetail, LevelUpPlan, Spell } from '../api/types';
|
||||
import { showToast } from '../lib/toasts';
|
||||
import type { CharacterClass, CharacterDetail, LevelUpPlan } from '../api/types';
|
||||
|
||||
// One numbered step of the checklist.
|
||||
function Step({ n, title, children }: { n: number; title: string; children: ReactNode }) {
|
||||
@@ -27,8 +29,10 @@ function allowance(spells: NonNullable<LevelUpPlan['spells']>): string {
|
||||
// The levelling-up checklist for one character, one level at a time: the
|
||||
// level, HP, the class's new special abilities (with a subclass or a Boon
|
||||
// where the level calls for one), new spells and fresh slots, and the free weapon upgrade. The
|
||||
// site does every step; the DM makes the choices and says yes.
|
||||
export function LevelUpModal({ character, campaignSpells, onClose }: { character: CharacterDetail; campaignSpells: Spell[]; onClose: () => void }) {
|
||||
// site does every step; whoever is levelling makes the choices and says yes:
|
||||
// the DM, or the character's own player once the DM has approved the level.
|
||||
// A player picks spells within what the level allows; the DM grants freely.
|
||||
export function LevelUpModal({ character, isDM, onClose }: { character: CharacterDetail; isDM: boolean; onClose: () => void }) {
|
||||
// The class taking the level: the first one, unless another is picked (multiclassing).
|
||||
const [toClass, setToClass] = useState<CharacterClass | null>(null);
|
||||
const { data: plan, isLoading, error: planError } = useLevelUpPlan(character.id, true, toClass);
|
||||
@@ -38,6 +42,7 @@ export function LevelUpModal({ character, campaignSpells, onClose }: { character
|
||||
// undefined until picked: the equipped weapon is offered first.
|
||||
const [weaponChoice, setWeaponChoice] = useState<string | undefined>(undefined);
|
||||
const [spellIds, setSpellIds] = useState<Set<string>>(new Set());
|
||||
const [hpRoll, setHpRoll] = useState('');
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
if (isLoading || !plan) {
|
||||
@@ -49,13 +54,16 @@ export function LevelUpModal({ character, campaignSpells, onClose }: { character
|
||||
}
|
||||
|
||||
const weaponId = weaponChoice ?? plan.weapons.find((w) => w.equipped)?.weaponId ?? plan.weapons[0]?.weaponId ?? '';
|
||||
const known = new Set(character.spells.map((s) => s.spellId));
|
||||
const grantable = plan.spells
|
||||
? campaignSpells.filter((s) => !known.has(s.id) && s.level <= plan.spells!.maxSpellLevel).sort((a, b) => a.level - b.level || a.name.localeCompare(b.name))
|
||||
: [];
|
||||
const grantable = plan.spellOptions;
|
||||
// A player picks up to the level's allowance; the DM is not held to it.
|
||||
const spellAllowance = plan.spells ? plan.spells.newSpells + plan.spells.newCantrips : 0;
|
||||
const spellsFull = !isDM && spellIds.size >= spellAllowance;
|
||||
const needsHpRoll = plan.hp.method === 'ROLL' && plan.hp.physical;
|
||||
const hpRollValid = Number.isInteger(Number(hpRoll)) && Number(hpRoll) >= 1 && Number(hpRoll) <= plan.hp.die;
|
||||
const pickedBoon = plan.boon?.find((b) => b.key === boon);
|
||||
const pickedSubclass = plan.subclass?.options.find((option) => option.key === subclass);
|
||||
const owed = plan.subclass && !subclass ? 'Choose a subclass first' : plan.boon && !boon ? 'Choose a Boon first' : null;
|
||||
const owed =
|
||||
plan.subclass && !subclass ? 'Choose a subclass first' : plan.boon && !boon ? 'Choose a Boon first' : needsHpRoll && !hpRollValid ? `Roll your d${plan.hp.die} for hit points` : null;
|
||||
|
||||
function toggleSpell(id: string) {
|
||||
setSpellIds((current) => {
|
||||
@@ -68,9 +76,14 @@ export function LevelUpModal({ character, campaignSpells, onClose }: { character
|
||||
async function handleLevelUp() {
|
||||
setError(null);
|
||||
try {
|
||||
await levelUp.mutateAsync({
|
||||
const { hpRolled } = await levelUp.mutateAsync({
|
||||
hpRoll: needsHpRoll ? Number(hpRoll) : undefined,
|
||||
characterClass: plan!.characterClass,
|
||||
subclass: plan!.subclass ? subclass : undefined, boon: plan!.boon ? boon : undefined, weaponId: weaponId || null, spellIds: [...spellIds] });
|
||||
showToast({
|
||||
tone: 'good',
|
||||
text: `${character.name} is level ${plan!.toLevel}!${hpRolled != null ? ` The d${plan!.hp.die} for hit points came up ${hpRolled}.` : ''}`,
|
||||
});
|
||||
onClose();
|
||||
} catch (err) {
|
||||
setError(extractErrorMessage(err));
|
||||
@@ -124,9 +137,32 @@ export function LevelUpModal({ character, campaignSpells, onClose }: { character
|
||||
</Step>
|
||||
|
||||
<Step n={2} title="Hit points">
|
||||
<p>
|
||||
Max HP <strong>{plan.maxHp.from}</strong> → <strong>{plan.maxHp.to}</strong>, and healed to full. One more Hit Die.
|
||||
</p>
|
||||
{plan.hp.method === 'AVERAGE' ? (
|
||||
<p>
|
||||
Max HP <strong>{plan.maxHp.from}</strong> → <strong>{plan.maxHp.to}</strong>, and healed to full. One more Hit Die (d{plan.hp.die}).
|
||||
</p>
|
||||
) : needsHpRoll ? (
|
||||
<div>
|
||||
<p style={{ marginBottom: '0.3rem' }}>
|
||||
This campaign rolls for hit points. Roll a <strong>d{plan.hp.die}</strong> at the table and enter what it shows; your Constitution
|
||||
modifier is added for you. Healed to full, and one more Hit Die.
|
||||
</p>
|
||||
<label className="flex-row gap-sm">
|
||||
I rolled
|
||||
<NumberInput min={1} max={plan.hp.die} placeholder={`1–${plan.hp.die}`} value={hpRoll} onChange={(e) => setHpRoll(e.target.value)} style={{ width: 80 }} />
|
||||
{hpRollValid && (
|
||||
<span className="combatant-sub">
|
||||
Max HP {plan.maxHp.from} → {plan.maxHp.to - plan.hp.average + Number(hpRoll)}
|
||||
</span>
|
||||
)}
|
||||
</label>
|
||||
</div>
|
||||
) : (
|
||||
<p>
|
||||
This campaign rolls for hit points: a <strong>d{plan.hp.die}</strong> is rolled when you confirm (between {plan.maxHp.to - plan.hp.average + 1} and{' '}
|
||||
{plan.maxHp.to - plan.hp.average + plan.hp.die} max HP), plus healing to full and one more Hit Die.
|
||||
</p>
|
||||
)}
|
||||
</Step>
|
||||
|
||||
<Step n={3} title="Special abilities">
|
||||
@@ -190,7 +226,9 @@ export function LevelUpModal({ character, campaignSpells, onClose }: { character
|
||||
</div>
|
||||
)}
|
||||
{(plan.features.length > 0 || plan.boon || plan.subclass) && (
|
||||
<p className="combatant-sub">Written into Special Abilities for you. Where a line says "choose", edit it there once the player has.</p>
|
||||
<p className="combatant-sub">
|
||||
Written into Special Abilities for you. {isDM ? 'Where a line says "choose", edit it there once the player has.' : 'Where a line says "choose", agree it with your DM.'}
|
||||
</p>
|
||||
)}
|
||||
</Step>
|
||||
|
||||
@@ -216,16 +254,22 @@ export function LevelUpModal({ character, campaignSpells, onClose }: { character
|
||||
<div className="level-spells">
|
||||
{grantable.map((spell) => (
|
||||
<label key={spell.id} className="checkbox-row level-choice">
|
||||
<input type="checkbox" checked={spellIds.has(spell.id)} onChange={() => toggleSpell(spell.id)} />
|
||||
<span>
|
||||
{spell.name} <span className="combatant-sub">{spellLevelLabel(spell.level)}</span>
|
||||
<input type="checkbox" checked={spellIds.has(spell.id)} disabled={spellsFull && !spellIds.has(spell.id)} onChange={() => toggleSpell(spell.id)} />
|
||||
<span title={spell.description ?? undefined}>
|
||||
{spell.name}{' '}
|
||||
<span className="combatant-sub">
|
||||
{spellLevelLabel(spell.level)}
|
||||
{spell.school ? ` · ${spell.school}` : ''}
|
||||
</span>
|
||||
</span>
|
||||
</label>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
<p className="combatant-sub">
|
||||
{spellIds.size > 0 && `${spellIds.size} picked. `}A player may also swap one known spell for another: take the old one away on the sheet.
|
||||
{isDM
|
||||
? `${spellIds.size > 0 ? `${spellIds.size} picked. ` : ''}A player may also swap one known spell for another: take the old one away on the sheet.`
|
||||
: `${spellIds.size} of ${spellAllowance} picked. Hover a spell to read what it does.`}
|
||||
</p>
|
||||
</>
|
||||
)}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
import { dismissToast, subscribeToasts, type Toast } from '../lib/toasts';
|
||||
|
||||
// The stack of toasts (lib/toasts.ts), mounted once in the layout.
|
||||
export function Toasts() {
|
||||
const [toasts, setToasts] = useState<Toast[]>([]);
|
||||
useEffect(() => subscribeToasts(setToasts), []);
|
||||
if (toasts.length === 0) return null;
|
||||
return (
|
||||
<div className="toasts" role="status" aria-live="polite">
|
||||
{toasts.map((toast) => (
|
||||
<div key={toast.id} className={`toast${toast.tone ? ` toast-${toast.tone}` : ''}`}>
|
||||
<span className="toast-text">{toast.text}</span>
|
||||
{toast.action && (
|
||||
<Link to={toast.action.to} className="btn btn-primary btn-sm" onClick={() => dismissToast(toast.id)}>
|
||||
{toast.action.label}
|
||||
</Link>
|
||||
)}
|
||||
<button className="btn btn-ghost btn-sm" aria-label="Dismiss" onClick={() => dismissToast(toast.id)}>
|
||||
✕
|
||||
</button>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user