V1.2.0: archive/delete campaigns and encounters, encounter sorting, change password, fuller seed
- Campaigns: DM can archive/restore; owner can delete. Archived campaigns move off the main list and stop accepting invite codes. - Encounters: DM can archive/restore and delete, and arrange the campaign's own order; the list can also be sorted by name, status, type or date. Archived encounters are hidden from players' lists. - Account page with change password (POST /auth/password). - Seed is now additive (safe on a live database; --reset for the old wipe) and builds a fuller Aldenfell: earned weapons, item pool, spells, NPCs, and 28 battle/quest scenes with descriptions, DM notes and rewards. - Vite preview host config for the deployed site. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -9,6 +9,7 @@ import { PartyOverviewPage } from './pages/PartyOverviewPage';
|
||||
import { CharacterSheetPage } from './pages/CharacterSheetPage';
|
||||
import { CharacterBuilderPage } from './pages/CharacterBuilderPage';
|
||||
import { EncounterPage } from './pages/EncounterPage';
|
||||
import { AccountPage } from './pages/AccountPage';
|
||||
|
||||
function App() {
|
||||
return (
|
||||
@@ -24,6 +25,7 @@ function App() {
|
||||
<Route path="/characters/:characterId" element={<CharacterSheetPage />} />
|
||||
<Route path="/characters/:characterId/build" element={<CharacterBuilderPage />} />
|
||||
<Route path="/encounters/:encounterId" element={<EncounterPage />} />
|
||||
<Route path="/account" element={<AccountPage />} />
|
||||
</Route>
|
||||
</Route>
|
||||
<Route path="*" element={<Navigate to="/" replace />} />
|
||||
|
||||
@@ -62,7 +62,7 @@ export function useCreateCampaign() {
|
||||
export function useUpdateCampaign(campaignId: string) {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: async (data: Partial<Campaign>) =>
|
||||
mutationFn: async (data: Partial<Campaign> & { archived?: boolean }) =>
|
||||
(await apiClient.patch<{ campaign: Campaign }>(`/campaigns/${campaignId}`, data)).data.campaign,
|
||||
onSuccess: () => {
|
||||
qc.invalidateQueries({ queryKey: ['campaign', campaignId] });
|
||||
@@ -71,6 +71,31 @@ export function useUpdateCampaign(campaignId: string) {
|
||||
});
|
||||
}
|
||||
|
||||
// Archived campaigns stay whole; they only move off the main list.
|
||||
export function useSetCampaignArchived() {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: async ({ campaignId, archived }: { campaignId: string; archived: boolean }) =>
|
||||
(await apiClient.patch<{ campaign: Campaign }>(`/campaigns/${campaignId}`, { archived })).data.campaign,
|
||||
onSuccess: (campaign) => {
|
||||
qc.invalidateQueries({ queryKey: ['campaign', campaign.id] });
|
||||
qc.invalidateQueries({ queryKey: ['campaigns'] });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// Permanent: takes every character, encounter and note in the campaign with it.
|
||||
export function useDeleteCampaign() {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: async (campaignId: string) => apiClient.delete(`/campaigns/${campaignId}`),
|
||||
onSuccess: (_res, campaignId) => {
|
||||
qc.removeQueries({ queryKey: ['campaign', campaignId] });
|
||||
qc.invalidateQueries({ queryKey: ['campaigns'] });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useJoinCampaign() {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
@@ -579,6 +604,51 @@ export function useCreateEncounter(campaignId: string) {
|
||||
});
|
||||
}
|
||||
|
||||
// Sets the campaign's own encounter order to the ids given, first to last.
|
||||
export function useReorderEncounters(campaignId: string) {
|
||||
const qc = useQueryClient();
|
||||
const key = ['campaign', campaignId, 'encounters'];
|
||||
return useMutation({
|
||||
mutationFn: async (encounterIds: string[]) => apiClient.put(`/campaigns/${campaignId}/encounters/order`, { encounterIds }),
|
||||
// Show the move straight away; the refetch below confirms or undoes it.
|
||||
onMutate: (encounterIds) => {
|
||||
qc.setQueryData<Encounter[]>(key, (old) => {
|
||||
if (!old) return old;
|
||||
const byId = new Map(old.map((e) => [e.id, e]));
|
||||
return encounterIds.flatMap((id, sortOrder) => {
|
||||
const encounter = byId.get(id);
|
||||
return encounter ? [{ ...encounter, sortOrder }] : [];
|
||||
});
|
||||
});
|
||||
},
|
||||
onSettled: () => qc.invalidateQueries({ queryKey: key }),
|
||||
});
|
||||
}
|
||||
|
||||
export function useSetEncounterArchived(campaignId: string) {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: async ({ encounterId, archived }: { encounterId: string; archived: boolean }) =>
|
||||
(await apiClient.patch(`/encounters/${encounterId}`, { archived })).data,
|
||||
onSuccess: (_data, { encounterId }) => {
|
||||
qc.invalidateQueries({ queryKey: ['campaign', campaignId, 'encounters'] });
|
||||
qc.invalidateQueries({ queryKey: ['encounter', encounterId] });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// Permanent. Rewards already handed out stay with the characters.
|
||||
export function useDeleteEncounter(campaignId: string) {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: async (encounterId: string) => apiClient.delete(`/encounters/${encounterId}`),
|
||||
onSuccess: (_res, encounterId) => {
|
||||
qc.removeQueries({ queryKey: ['encounter', encounterId] });
|
||||
qc.invalidateQueries({ queryKey: ['campaign', campaignId, 'encounters'] });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useEncounter(encounterId: string | undefined) {
|
||||
return useQuery({
|
||||
queryKey: ['encounter', encounterId],
|
||||
|
||||
@@ -93,6 +93,7 @@ export interface Campaign {
|
||||
startingSpellCount: number;
|
||||
skipMotivationRoll: boolean;
|
||||
ownerId: string;
|
||||
archivedAt: string | null; // set while the campaign is archived
|
||||
role: 'DM' | 'PLAYER';
|
||||
createdAt: string;
|
||||
}
|
||||
@@ -413,6 +414,8 @@ export interface Encounter {
|
||||
activeParticipantId: string | null;
|
||||
description: string | null;
|
||||
dmNotes?: string | null; // DM only
|
||||
archivedAt: string | null; // archived encounters only reach the DM's list
|
||||
sortOrder: number; // place in the campaign's own order, lowest first
|
||||
createdAt: string;
|
||||
participants?: EncounterParticipant[];
|
||||
rewards?: EncounterReward[]; // players only receive the awarded ones
|
||||
|
||||
@@ -17,7 +17,9 @@ export function Layout() {
|
||||
<nav className="topbar-nav">
|
||||
{user && (
|
||||
<div className="topbar-user">
|
||||
<span>{user.displayName}</span>
|
||||
<Link to="/account" title="Account settings">
|
||||
{user.displayName}
|
||||
</Link>
|
||||
<button className="btn btn-ghost" onClick={logout}>
|
||||
Log out
|
||||
</button>
|
||||
|
||||
@@ -39,11 +39,16 @@ export function useCampaignSocket(campaignId: string | undefined) {
|
||||
const onRoundAdvanced = () => {
|
||||
qc.invalidateQueries({ queryKey: ['encounter'] });
|
||||
};
|
||||
const onCampaignDeleted = () => {
|
||||
qc.invalidateQueries({ queryKey: ['campaigns'] });
|
||||
qc.invalidateQueries({ queryKey: ['campaign', campaignId] });
|
||||
};
|
||||
|
||||
socket.on('character:updated', onCharacterUpdated);
|
||||
socket.on('character:created', onCharacterCreated);
|
||||
socket.on('encounter:participant-updated', onParticipantUpdated);
|
||||
socket.on('encounter:round-advanced', onRoundAdvanced);
|
||||
socket.on('campaign:deleted', onCampaignDeleted);
|
||||
|
||||
return () => {
|
||||
socket.emit('campaign:leave', campaignId);
|
||||
@@ -51,6 +56,7 @@ export function useCampaignSocket(campaignId: string | undefined) {
|
||||
socket.off('character:created', onCharacterCreated);
|
||||
socket.off('encounter:participant-updated', onParticipantUpdated);
|
||||
socket.off('encounter:round-advanced', onRoundAdvanced);
|
||||
socket.off('campaign:deleted', onCampaignDeleted);
|
||||
};
|
||||
}, [campaignId, token, qc]);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
import { useState, type FormEvent } from 'react';
|
||||
import { apiClient } from '../api/client';
|
||||
import { useAuth } from '../auth/AuthContext';
|
||||
import { extractErrorMessage } from '../lib/format';
|
||||
import { ErrorBanner } from '../components/Spinner';
|
||||
|
||||
export function AccountPage() {
|
||||
const { user } = useAuth();
|
||||
const [currentPassword, setCurrentPassword] = useState('');
|
||||
const [newPassword, setNewPassword] = useState('');
|
||||
const [confirmPassword, setConfirmPassword] = useState('');
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [saved, setSaved] = useState(false);
|
||||
const [submitting, setSubmitting] = useState(false);
|
||||
|
||||
async function handleSubmit(e: FormEvent) {
|
||||
e.preventDefault();
|
||||
setError(null);
|
||||
setSaved(false);
|
||||
if (newPassword !== confirmPassword) {
|
||||
setError('The two new passwords do not match.');
|
||||
return;
|
||||
}
|
||||
setSubmitting(true);
|
||||
try {
|
||||
await apiClient.post('/auth/password', { currentPassword, newPassword });
|
||||
setCurrentPassword('');
|
||||
setNewPassword('');
|
||||
setConfirmPassword('');
|
||||
setSaved(true);
|
||||
} catch (err) {
|
||||
setError(extractErrorMessage(err));
|
||||
} finally {
|
||||
setSubmitting(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div style={{ maxWidth: 480 }}>
|
||||
<div className="page-header">
|
||||
<div>
|
||||
<h1>Your Account</h1>
|
||||
<p className="subtitle">
|
||||
{user?.displayName} · {user?.email}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="card">
|
||||
<div className="card-title">Change Password</div>
|
||||
<form onSubmit={handleSubmit}>
|
||||
<div className="field">
|
||||
<label htmlFor="currentPassword">Current password</label>
|
||||
<input
|
||||
id="currentPassword"
|
||||
type="password"
|
||||
autoComplete="current-password"
|
||||
required
|
||||
value={currentPassword}
|
||||
onChange={(e) => setCurrentPassword(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<div className="field">
|
||||
<label htmlFor="newPassword">New password (at least 8 characters)</label>
|
||||
<input
|
||||
id="newPassword"
|
||||
type="password"
|
||||
autoComplete="new-password"
|
||||
required
|
||||
minLength={8}
|
||||
value={newPassword}
|
||||
onChange={(e) => setNewPassword(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<div className="field">
|
||||
<label htmlFor="confirmPassword">New password again</label>
|
||||
<input
|
||||
id="confirmPassword"
|
||||
type="password"
|
||||
autoComplete="new-password"
|
||||
required
|
||||
minLength={8}
|
||||
value={confirmPassword}
|
||||
onChange={(e) => setConfirmPassword(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
{error && <ErrorBanner message={error} />}
|
||||
{saved && <p className="subtitle">Password changed. Use the new one next time you log in.</p>}
|
||||
<button type="submit" className="btn btn-primary mt-md" disabled={submitting}>
|
||||
{submitting ? 'Saving…' : 'Change Password'}
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -7,6 +7,9 @@ import {
|
||||
useDeleteCharacter,
|
||||
useCampaignEncounters,
|
||||
useCreateEncounter,
|
||||
useReorderEncounters,
|
||||
useSetEncounterArchived,
|
||||
useDeleteEncounter,
|
||||
useCampaignMonsters,
|
||||
useCreateMonster,
|
||||
useDeleteMonster,
|
||||
@@ -23,6 +26,8 @@ import {
|
||||
useCampaignNotes,
|
||||
useCreateNote,
|
||||
useUpdateCampaign,
|
||||
useSetCampaignArchived,
|
||||
useDeleteCampaign,
|
||||
useRegenerateInvite,
|
||||
useCampaignLocations,
|
||||
useCreateLocation,
|
||||
@@ -39,7 +44,41 @@ import { usePagination, Pagination } from '../components/Paginated';
|
||||
import { SPELL_DAMAGE_GROUPS, SPELL_DAMAGE_SPECIALS, extractErrorMessage, spellLevelLabel, spellRequirementLabel } from '../lib/format';
|
||||
import { speciesIcon } from '../lib/speciesIcons';
|
||||
import { DAMAGE_SCALING_LABELS, MAX_GEAR_LEVEL } from '../lib/previewCalc';
|
||||
import type { CharacterSummary, EncounterMode, LibraryMonster, LibrarySpell, LibraryWeapon, NpcDisposition } from '../api/types';
|
||||
import type { CharacterSummary, Encounter, EncounterMode, LibraryMonster, LibrarySpell, LibraryWeapon, NpcDisposition } from '../api/types';
|
||||
|
||||
// How the encounter list can be ordered. "custom" is the campaign's own order,
|
||||
// which the DM arranges; the rest only change what this browser shows.
|
||||
type EncounterSort = 'custom' | 'name' | 'status' | 'type' | 'newest' | 'oldest';
|
||||
const ENCOUNTER_SORT_LABELS: Record<EncounterSort, string> = {
|
||||
custom: 'Campaign order',
|
||||
name: 'Name (A–Z)',
|
||||
status: 'Status (in progress first)',
|
||||
type: 'Type (battles first)',
|
||||
newest: 'Newest first',
|
||||
oldest: 'Oldest first',
|
||||
};
|
||||
const ENCOUNTER_SORT_KEY = 'dnd_encounter_sort';
|
||||
const STATUS_RANK = { ACTIVE: 0, PLANNING: 1, COMPLETE: 2 };
|
||||
|
||||
function storedEncounterSort(): EncounterSort {
|
||||
const stored = localStorage.getItem(ENCOUNTER_SORT_KEY);
|
||||
return stored && stored in ENCOUNTER_SORT_LABELS ? (stored as EncounterSort) : 'custom';
|
||||
}
|
||||
|
||||
// `encounters` arrives in campaign order, and the sort is stable, so ties
|
||||
// (same status, same type) stay in that order.
|
||||
function sortEncounters(encounters: Encounter[], sort: EncounterSort): Encounter[] {
|
||||
const time = (e: Encounter) => new Date(e.createdAt).getTime();
|
||||
const compare: Record<EncounterSort, (a: Encounter, b: Encounter) => number> = {
|
||||
custom: () => 0,
|
||||
name: (a, b) => a.name.localeCompare(b.name, undefined, { numeric: true, sensitivity: 'base' }),
|
||||
status: (a, b) => STATUS_RANK[a.status] - STATUS_RANK[b.status],
|
||||
type: (a, b) => Number(a.mode === 'QUEST') - Number(b.mode === 'QUEST'),
|
||||
newest: (a, b) => time(b) - time(a),
|
||||
oldest: (a, b) => time(a) - time(b),
|
||||
};
|
||||
return [...encounters].sort(compare[sort]);
|
||||
}
|
||||
|
||||
function CharacterRow({ character, isDM, onDelete }: { character: CharacterSummary; isDM: boolean; onDelete: () => void }) {
|
||||
const inProgress = character.buildStage !== 'COMPLETE';
|
||||
@@ -259,6 +298,9 @@ export function CampaignHomePage() {
|
||||
const createCharacter = useCreateCharacter(campaignId);
|
||||
const deleteCharacter = useDeleteCharacter(campaignId);
|
||||
const createEncounter = useCreateEncounter(campaignId);
|
||||
const reorderEncounters = useReorderEncounters(campaignId);
|
||||
const setEncounterArchived = useSetEncounterArchived(campaignId);
|
||||
const deleteEncounter = useDeleteEncounter(campaignId);
|
||||
const createMonster = useCreateMonster(campaignId);
|
||||
const deleteMonster = useDeleteMonster(campaignId);
|
||||
const createWeapon = useCreateWeapon(campaignId);
|
||||
@@ -275,6 +317,8 @@ export function CampaignHomePage() {
|
||||
const createNote = useCreateNote();
|
||||
const updateCampaign = useUpdateCampaign(campaignId);
|
||||
const regenerateInvite = useRegenerateInvite(campaignId);
|
||||
const setArchived = useSetCampaignArchived();
|
||||
const deleteCampaign = useDeleteCampaign();
|
||||
const createLocation = useCreateLocation(campaignId);
|
||||
const deleteLocation = useDeleteLocation(campaignId);
|
||||
const addWeaponFromLibrary = useAddWeaponFromLibrary(campaignId);
|
||||
@@ -284,12 +328,16 @@ export function CampaignHomePage() {
|
||||
const [newCharName, setNewCharName] = useState('');
|
||||
const [newEncounterName, setNewEncounterName] = useState('');
|
||||
const [newEncounterMode, setNewEncounterMode] = useState<EncounterMode>('BATTLE');
|
||||
const [encounterSort, setEncounterSort] = useState<EncounterSort>(storedEncounterSort);
|
||||
const [showArchivedEncounters, setShowArchivedEncounters] = useState(false);
|
||||
const [showNpcForm, setShowNpcForm] = useState(false);
|
||||
const [noteBody, setNoteBody] = useState('');
|
||||
const [dmNoteBody, setDmNoteBody] = useState('');
|
||||
const [newLocationName, setNewLocationName] = useState('');
|
||||
const [formError, setFormError] = useState<string | null>(null);
|
||||
const [showSettings, setShowSettings] = useState(false);
|
||||
const [showDelete, setShowDelete] = useState(false);
|
||||
const [deleteConfirmName, setDeleteConfirmName] = useState('');
|
||||
const [showMonsterForm, setShowMonsterForm] = useState(false);
|
||||
const [showWeaponForm, setShowWeaponForm] = useState(false);
|
||||
const [showSpellForm, setShowSpellForm] = useState(false);
|
||||
@@ -303,6 +351,9 @@ export function CampaignHomePage() {
|
||||
const itemsPage = usePagination(items, 8);
|
||||
const npcsPage = usePagination(npcs, 8);
|
||||
const monstersPage = usePagination(monsters, 8);
|
||||
const liveEncounters = encounters?.filter((e) => !e.archivedAt) || [];
|
||||
const archivedEncounters = encounters?.filter((e) => e.archivedAt) || [];
|
||||
const shownEncounters = sortEncounters(liveEncounters, encounterSort);
|
||||
const sharedNotes = notes?.filter((n) => n.visibility === 'SHARED');
|
||||
const dmNotes = notes?.filter((n) => n.visibility === 'DM_ONLY');
|
||||
const sharedNotesPage = usePagination(sharedNotes, 6);
|
||||
@@ -341,6 +392,17 @@ export function CampaignHomePage() {
|
||||
}
|
||||
}
|
||||
|
||||
// Swaps an encounter with its neighbour in the campaign's own order.
|
||||
function moveEncounter(index: number, step: -1 | 1) {
|
||||
const ids = liveEncounters.map((e) => e.id);
|
||||
const target = index + step;
|
||||
if (target < 0 || target >= ids.length) return;
|
||||
[ids[index], ids[target]] = [ids[target], ids[index]];
|
||||
reorderEncounters.mutate([...ids, ...archivedEncounters.map((e) => e.id)], {
|
||||
onError: (err) => setFormError(extractErrorMessage(err)),
|
||||
});
|
||||
}
|
||||
|
||||
async function handleCreateNote(e: FormEvent) {
|
||||
e.preventDefault();
|
||||
if (!noteBody.trim()) return;
|
||||
@@ -355,6 +417,26 @@ export function CampaignHomePage() {
|
||||
setDmNoteBody('');
|
||||
}
|
||||
|
||||
async function handleSetArchived(archived: boolean) {
|
||||
setFormError(null);
|
||||
try {
|
||||
await setArchived.mutateAsync({ campaignId, archived });
|
||||
} catch (err) {
|
||||
setFormError(extractErrorMessage(err));
|
||||
}
|
||||
}
|
||||
|
||||
async function handleDeleteCampaign(e: FormEvent) {
|
||||
e.preventDefault();
|
||||
setFormError(null);
|
||||
try {
|
||||
await deleteCampaign.mutateAsync(campaignId);
|
||||
navigate('/campaigns');
|
||||
} catch (err) {
|
||||
setFormError(extractErrorMessage(err));
|
||||
}
|
||||
}
|
||||
|
||||
async function handleCreateLocation(e: FormEvent) {
|
||||
e.preventDefault();
|
||||
if (!newLocationName.trim()) return;
|
||||
@@ -373,6 +455,7 @@ export function CampaignHomePage() {
|
||||
<Link to={`/campaigns/${campaignId}/party`} className="btn">
|
||||
📊 Party Overview
|
||||
</Link>
|
||||
{campaign.archivedAt && <span className="badge">Archived</span>}
|
||||
<span className={`badge ${isDM ? 'badge-dm' : 'badge-player'}`}>{isDM ? 'Dungeon Master' : 'Player'}</span>
|
||||
</div>
|
||||
</div>
|
||||
@@ -439,6 +522,53 @@ export function CampaignHomePage() {
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
<div className="mt-md">
|
||||
<div className="card-title" style={{ marginBottom: '0.4rem' }}>Archive or Delete</div>
|
||||
<p className="subtitle" style={{ marginTop: 0 }}>
|
||||
{campaign.archivedAt
|
||||
? 'This campaign is archived: it sits under “Archived” on your campaign list and its invite code is switched off. Nothing in it has been removed.'
|
||||
: 'Archiving moves the campaign off everyone’s main list and switches off its invite code. Nothing is removed, and you can restore it at any time.'}
|
||||
</p>
|
||||
<div className="flex-row flex-wrap">
|
||||
<button className="btn" disabled={setArchived.isPending} onClick={() => handleSetArchived(!campaign.archivedAt)}>
|
||||
{campaign.archivedAt ? 'Restore Campaign' : 'Archive Campaign'}
|
||||
</button>
|
||||
{campaign.ownerId === user?.id && (
|
||||
<button
|
||||
className="btn btn-danger"
|
||||
onClick={() => {
|
||||
setShowDelete((s) => !s);
|
||||
setDeleteConfirmName('');
|
||||
}}
|
||||
>
|
||||
{showDelete ? 'Cancel' : 'Delete Campaign…'}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
{showDelete && (
|
||||
<form className="mt-md" onSubmit={handleDeleteCampaign}>
|
||||
<div className="field">
|
||||
<label htmlFor="deleteConfirmName">
|
||||
This permanently deletes every character, encounter, note and pool entry in the campaign, for
|
||||
every player. There is no undo. Type <strong>{campaign.name}</strong> to confirm.
|
||||
</label>
|
||||
<input
|
||||
id="deleteConfirmName"
|
||||
autoComplete="off"
|
||||
value={deleteConfirmName}
|
||||
onChange={(e) => setDeleteConfirmName(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<button
|
||||
type="submit"
|
||||
className="btn btn-danger"
|
||||
disabled={deleteCampaign.isPending || deleteConfirmName.trim() !== campaign.name.trim()}
|
||||
>
|
||||
{deleteCampaign.isPending ? 'Deleting…' : 'Delete Forever'}
|
||||
</button>
|
||||
</form>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -484,6 +614,25 @@ export function CampaignHomePage() {
|
||||
<div className="mt-lg">
|
||||
<div className="page-header" style={{ marginBottom: '0.75rem' }}>
|
||||
<h2 style={{ fontSize: '1.1rem', margin: 0 }}>Encounters</h2>
|
||||
{liveEncounters.length > 1 && (
|
||||
<label className="flex-row subtitle">
|
||||
Sort by
|
||||
<select
|
||||
value={encounterSort}
|
||||
onChange={(e) => {
|
||||
const sort = e.target.value as EncounterSort;
|
||||
setEncounterSort(sort);
|
||||
localStorage.setItem(ENCOUNTER_SORT_KEY, sort);
|
||||
}}
|
||||
>
|
||||
{(Object.keys(ENCOUNTER_SORT_LABELS) as EncounterSort[]).map((sort) => (
|
||||
<option key={sort} value={sort}>
|
||||
{ENCOUNTER_SORT_LABELS[sort]}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
)}
|
||||
</div>
|
||||
{isDM && (
|
||||
<form onSubmit={handleCreateEncounter} className="flex-row flex-wrap" style={{ marginBottom: '0.75rem' }}>
|
||||
@@ -502,19 +651,103 @@ export function CampaignHomePage() {
|
||||
</button>
|
||||
</form>
|
||||
)}
|
||||
{encounters?.length === 0 && <div className="empty-state">No encounters yet.</div>}
|
||||
{encounters?.map((enc) => (
|
||||
<Link key={enc.id} to={`/encounters/${enc.id}`} className="card flex-between" style={{ display: 'flex' }}>
|
||||
<span>
|
||||
{isDM && encounterSort === 'custom' && liveEncounters.length > 1 && (
|
||||
<p className="subtitle" style={{ marginTop: 0 }}>
|
||||
This is the campaign's own order, which everyone sees by default. Use ▲ and ▼ to rearrange it.
|
||||
</p>
|
||||
)}
|
||||
{encounters && liveEncounters.length === 0 && (
|
||||
<div className="empty-state">{archivedEncounters.length > 0 ? 'Every encounter is archived.' : 'No encounters yet.'}</div>
|
||||
)}
|
||||
{shownEncounters.map((enc, index) => (
|
||||
<div key={enc.id} className="card flex-between flex-wrap">
|
||||
<Link to={`/encounters/${enc.id}`} style={{ flex: 1, minWidth: 200 }}>
|
||||
<span className="badge" style={{ marginRight: 8 }}>{MODE_LABELS[enc.mode]}</span>
|
||||
{enc.name}
|
||||
</Link>
|
||||
<span className="flex-row">
|
||||
<span className="badge">
|
||||
{enc.status}
|
||||
{enc.mode === 'BATTLE' && ` · Round ${enc.currentRound}`}
|
||||
</span>
|
||||
{isDM && encounterSort === 'custom' && (
|
||||
<>
|
||||
<button
|
||||
className="btn btn-ghost"
|
||||
aria-label={`Move ${enc.name} up`}
|
||||
title="Move up"
|
||||
disabled={index === 0 || reorderEncounters.isPending}
|
||||
onClick={() => moveEncounter(index, -1)}
|
||||
>
|
||||
▲
|
||||
</button>
|
||||
<button
|
||||
className="btn btn-ghost"
|
||||
aria-label={`Move ${enc.name} down`}
|
||||
title="Move down"
|
||||
disabled={index === shownEncounters.length - 1 || reorderEncounters.isPending}
|
||||
onClick={() => moveEncounter(index, 1)}
|
||||
>
|
||||
▼
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
{isDM && (
|
||||
<button
|
||||
className="btn btn-ghost"
|
||||
title="Archive: take it off the list without deleting it"
|
||||
disabled={setEncounterArchived.isPending}
|
||||
onClick={() => setEncounterArchived.mutate({ encounterId: enc.id, archived: true })}
|
||||
>
|
||||
Archive
|
||||
</button>
|
||||
)}
|
||||
</span>
|
||||
<span className="badge">
|
||||
{enc.status}
|
||||
{enc.mode === 'BATTLE' && ` · Round ${enc.currentRound}`}
|
||||
</span>
|
||||
</Link>
|
||||
</div>
|
||||
))}
|
||||
|
||||
{isDM && archivedEncounters.length > 0 && (
|
||||
<div className="mt-md">
|
||||
<div className="flex-between">
|
||||
<h3 className="section-label" style={{ margin: 0 }}>Archived ({archivedEncounters.length})</h3>
|
||||
<button className="btn btn-ghost" onClick={() => setShowArchivedEncounters((s) => !s)}>
|
||||
{showArchivedEncounters ? 'Hide' : 'Show'}
|
||||
</button>
|
||||
</div>
|
||||
{showArchivedEncounters && (
|
||||
<>
|
||||
<p className="subtitle" style={{ marginTop: 0 }}>Players don't see these in their list.</p>
|
||||
{archivedEncounters.map((enc) => (
|
||||
<div key={enc.id} className="card flex-between flex-wrap">
|
||||
<Link to={`/encounters/${enc.id}`} style={{ flex: 1, minWidth: 200 }}>
|
||||
<span className="badge" style={{ marginRight: 8 }}>{MODE_LABELS[enc.mode]}</span>
|
||||
{enc.name}
|
||||
</Link>
|
||||
<span className="flex-row">
|
||||
<button
|
||||
className="btn"
|
||||
disabled={setEncounterArchived.isPending}
|
||||
onClick={() => setEncounterArchived.mutate({ encounterId: enc.id, archived: false })}
|
||||
>
|
||||
Restore
|
||||
</button>
|
||||
<button
|
||||
className="btn btn-danger"
|
||||
disabled={deleteEncounter.isPending}
|
||||
onClick={() =>
|
||||
window.confirm(`Delete "${enc.name}" for good? Rewards already handed out stay with the characters.`) &&
|
||||
deleteEncounter.mutate(enc.id)
|
||||
}
|
||||
>
|
||||
Delete
|
||||
</button>
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{isDM && (
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useState, type FormEvent } from 'react';
|
||||
import { Link, useNavigate } from 'react-router-dom';
|
||||
import { useCampaigns, useCreateCampaign, useJoinCampaign } from '../api/queries';
|
||||
import { useCampaigns, useCreateCampaign, useJoinCampaign, useSetCampaignArchived } from '../api/queries';
|
||||
import { Spinner, ErrorBanner } from '../components/Spinner';
|
||||
import { extractErrorMessage } from '../lib/format';
|
||||
|
||||
@@ -8,6 +8,7 @@ export function CampaignListPage() {
|
||||
const { data: campaigns, isLoading, error } = useCampaigns();
|
||||
const createCampaign = useCreateCampaign();
|
||||
const joinCampaign = useJoinCampaign();
|
||||
const setArchived = useSetCampaignArchived();
|
||||
const navigate = useNavigate();
|
||||
|
||||
const [showCreate, setShowCreate] = useState(false);
|
||||
@@ -15,6 +16,10 @@ export function CampaignListPage() {
|
||||
const [description, setDescription] = useState('');
|
||||
const [inviteCode, setInviteCode] = useState('');
|
||||
const [formError, setFormError] = useState<string | null>(null);
|
||||
const [showArchived, setShowArchived] = useState(false);
|
||||
|
||||
const activeCampaigns = campaigns?.filter((c) => !c.archivedAt);
|
||||
const archivedCampaigns = campaigns?.filter((c) => c.archivedAt) || [];
|
||||
|
||||
async function handleCreate(e: FormEvent) {
|
||||
e.preventDefault();
|
||||
@@ -89,11 +94,15 @@ export function CampaignListPage() {
|
||||
<div className="mt-lg">
|
||||
{isLoading && <Spinner label="Consulting the tavern board…" />}
|
||||
{error && <ErrorBanner message="Could not load your campaigns." />}
|
||||
{campaigns && campaigns.length === 0 && (
|
||||
<div className="empty-state">No campaigns yet — found one, or join with an invite code above.</div>
|
||||
{activeCampaigns && activeCampaigns.length === 0 && (
|
||||
<div className="empty-state">
|
||||
{archivedCampaigns.length > 0
|
||||
? 'No active campaigns — found one, join with an invite code above, or restore one from the archive below.'
|
||||
: 'No campaigns yet — found one, or join with an invite code above.'}
|
||||
</div>
|
||||
)}
|
||||
<div className="grid grid-cols-2">
|
||||
{campaigns?.map((c) => (
|
||||
{activeCampaigns?.map((c) => (
|
||||
<Link key={c.id} to={`/campaigns/${c.id}`} className="card" style={{ display: 'block' }}>
|
||||
<div className="card-title">
|
||||
<span>{c.name}</span>
|
||||
@@ -104,6 +113,39 @@ export function CampaignListPage() {
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{archivedCampaigns.length > 0 && (
|
||||
<div className="mt-lg">
|
||||
<div className="flex-between">
|
||||
<h2 className="section-label" style={{ margin: 0 }}>Archived ({archivedCampaigns.length})</h2>
|
||||
<button className="btn btn-ghost" onClick={() => setShowArchived((s) => !s)}>
|
||||
{showArchived ? 'Hide' : 'Show'}
|
||||
</button>
|
||||
</div>
|
||||
{showArchived && (
|
||||
<div className="grid grid-cols-2 mt-sm">
|
||||
{archivedCampaigns.map((c) => (
|
||||
<div key={c.id} className="card">
|
||||
<div className="card-title">
|
||||
<Link to={`/campaigns/${c.id}`}>{c.name}</Link>
|
||||
<span className={`badge ${c.role === 'DM' ? 'badge-dm' : 'badge-player'}`}>{c.role}</span>
|
||||
</div>
|
||||
<p style={{ color: 'var(--text-muted)', marginTop: 0 }}>{c.description || 'No description yet.'}</p>
|
||||
{c.role === 'DM' && (
|
||||
<button
|
||||
className="btn"
|
||||
disabled={setArchived.isPending}
|
||||
onClick={() => setArchived.mutate({ campaignId: c.id, archived: false })}
|
||||
>
|
||||
Restore
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -344,7 +344,7 @@ export function CharacterSheetPage() {
|
||||
}
|
||||
}
|
||||
|
||||
const otherCampaigns = campaigns?.filter((c) => c.id !== character.campaignId) ?? [];
|
||||
const otherCampaigns = campaigns?.filter((c) => c.id !== character.campaignId && !c.archivedAt) ?? [];
|
||||
|
||||
const assignedWeaponIds = new Set(character.weapons.map((w) => w.weaponId));
|
||||
const assignedSpellIds = new Set(character.spells.map((s) => s.spellId));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useState, type ReactNode } from 'react';
|
||||
import { Link, useParams } from 'react-router-dom';
|
||||
import { Link, useNavigate, useParams } from 'react-router-dom';
|
||||
import {
|
||||
useEncounter,
|
||||
useCampaign,
|
||||
@@ -14,6 +14,8 @@ import {
|
||||
useAdvanceRound,
|
||||
useNextTurn,
|
||||
usePatchEncounter,
|
||||
useSetEncounterArchived,
|
||||
useDeleteEncounter,
|
||||
useAddReward,
|
||||
useDeleteReward,
|
||||
useAwardReward,
|
||||
@@ -592,6 +594,9 @@ export function EncounterPage() {
|
||||
const advanceRound = useAdvanceRound(encounterId);
|
||||
const nextTurn = useNextTurn(encounterId);
|
||||
const patchEncounter = usePatchEncounter(encounterId);
|
||||
const setArchived = useSetEncounterArchived(encounter?.campaignId ?? '');
|
||||
const deleteEncounter = useDeleteEncounter(encounter?.campaignId ?? '');
|
||||
const navigate = useNavigate();
|
||||
|
||||
const [pickType, setPickType] = useState<'character' | 'monster' | 'npc'>('character');
|
||||
const [pickId, setPickId] = useState('');
|
||||
@@ -656,6 +661,7 @@ export function EncounterPage() {
|
||||
<span className="badge badge-dm">{MODE_LABELS[encounter.mode]}</span>
|
||||
<span className={`badge ${encounter.status === 'ACTIVE' ? 'badge-live' : ''}`}>{STATUS_LABELS[encounter.status]}</span>
|
||||
{isBattle && <span className="badge">Round {encounter.currentRound}</span>}
|
||||
{encounter.archivedAt && <span className="badge">Archived</span>}
|
||||
{active && <span className="turn-marker">▶ {active.displayName}'s turn</span>}
|
||||
</div>
|
||||
</div>
|
||||
@@ -698,6 +704,24 @@ export function EncounterPage() {
|
||||
Reopen
|
||||
</button>
|
||||
)}
|
||||
<button
|
||||
className="btn btn-ghost"
|
||||
title={encounter.archivedAt ? 'Put it back on the campaign list' : 'Take it off the campaign list without deleting it'}
|
||||
disabled={setArchived.isPending}
|
||||
onClick={() => setArchived.mutate({ encounterId, archived: !encounter.archivedAt }, fail)}
|
||||
>
|
||||
{encounter.archivedAt ? 'Restore' : 'Archive'}
|
||||
</button>
|
||||
<button
|
||||
className="btn btn-ghost"
|
||||
disabled={deleteEncounter.isPending}
|
||||
onClick={() =>
|
||||
window.confirm(`Delete "${encounter.name}" for good? Rewards already handed out stay with the characters.`) &&
|
||||
deleteEncounter.mutate(encounterId, { ...fail, onSuccess: () => navigate(`/campaigns/${encounter.campaignId}`) })
|
||||
}
|
||||
>
|
||||
Delete
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -4,4 +4,10 @@ import { defineConfig } from 'vite'
|
||||
// https://vite.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [react()],
|
||||
|
||||
preview: {
|
||||
host: true,
|
||||
port: 5173,
|
||||
allowedHosts: ['the-sunken-reach.crosscode.co.za'],
|
||||
},
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user