- The scene description shows during a battle only between rounds (while the first in the order is on turn), and always before and after it - Combatant details start closed in a battle: the spotlight has whoever is on turn, or on a narrow screen their own card opens - While a battle is under way, Add to the scene, Experience and Rewards fold to their titles - Button labels wrap inside their buttons instead of spilling out - Sticky turn order and side column follow the measured top bar height - Phone: quick stats no longer sits on Log out, incoming rolls clear the bottom bar, the damage bar no longer scrolls on its own - Docs updated; all packages at version 1.32.0 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
91 lines
3.2 KiB
TypeScript
91 lines
3.2 KiB
TypeScript
import { Suspense, useEffect, useRef } from 'react';
|
|
import { Link, NavLink, Outlet, useMatch } from 'react-router-dom';
|
|
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();
|
|
|
|
// The campaign pages say which campaign they are in their address; sheets
|
|
// and encounters report theirs themselves (useRememberCampaign).
|
|
const onCampaign = useMatch('/campaigns/:campaignId/*');
|
|
useRememberCampaign(onCampaign?.params.campaignId);
|
|
const campaignId = useLastCampaignId();
|
|
|
|
// How tall the top bar really is, as --topbar-h, so that what sticks under
|
|
// it (the turn order in a battle) sits right below it on any screen.
|
|
const topbar = useRef<HTMLElement>(null);
|
|
useEffect(() => {
|
|
const bar = topbar.current;
|
|
if (!bar) return;
|
|
const measure = () => document.documentElement.style.setProperty('--topbar-h', `${bar.offsetHeight}px`);
|
|
measure();
|
|
const observer = new ResizeObserver(measure);
|
|
observer.observe(bar);
|
|
return () => observer.disconnect();
|
|
}, []);
|
|
|
|
// The same destinations twice: along the top bar on a wide screen, and as a
|
|
// bar along the bottom, in reach of a thumb, on a phone.
|
|
const destinations = [
|
|
{ to: '/campaigns', end: true, icon: '🗺', label: 'Campaigns' },
|
|
...(campaignId
|
|
? [
|
|
{ to: `/campaigns/${campaignId}`, end: true, icon: '🏰', label: 'Campaign' },
|
|
{ to: `/campaigns/${campaignId}/party`, end: true, icon: '👥', label: 'Party' },
|
|
]
|
|
: []),
|
|
{ to: '/account', end: true, icon: '👤', label: 'Account' },
|
|
];
|
|
const links = (className: string) =>
|
|
destinations.map((d) => (
|
|
<NavLink key={d.to} to={d.to} end={d.end} className={({ isActive }) => `${className}${isActive ? ' is-active' : ''}`}>
|
|
<span className="nav-icon" aria-hidden>
|
|
{d.icon}
|
|
</span>
|
|
<span>{d.label}</span>
|
|
</NavLink>
|
|
));
|
|
|
|
return (
|
|
<div className="app-shell">
|
|
<header className="topbar" ref={topbar}>
|
|
<Link to="/campaigns" className="topbar-brand">
|
|
<span className="die" aria-hidden>
|
|
⚄
|
|
</span>
|
|
The Sunken Reach
|
|
</Link>
|
|
{user && (
|
|
<nav className="topbar-nav" aria-label="Main">
|
|
<div className="topbar-links">{links('topbar-link')}</div>
|
|
<div className="topbar-user">
|
|
<span className="topbar-name">{user.displayName}</span>
|
|
<button className="btn btn-ghost" onClick={logout}>
|
|
Log out
|
|
</button>
|
|
</div>
|
|
</nav>
|
|
)}
|
|
</header>
|
|
<main className="page">
|
|
{/* The bars stay put while a page that has not been opened before downloads. */}
|
|
<Suspense fallback={null}>
|
|
<Outlet />
|
|
</Suspense>
|
|
</main>
|
|
{user && (
|
|
<nav className="bottom-nav" aria-label="Main">
|
|
{links('bottom-nav-link')}
|
|
</nav>
|
|
)}
|
|
<DiceRoller />
|
|
{user && <CharacterPanel />}
|
|
<Toasts />
|
|
</div>
|
|
);
|
|
}
|