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(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) => ( `${className}${isActive ? ' is-active' : ''}`}> {d.icon} {d.label} )); return (
⚄ The Sunken Reach {user && ( )}
{/* The bars stay put while a page that has not been opened before downloads. */}
{user && ( )} {user && }
); }