#/mobile/cards shows the game without the site shell: a title, a footer with the account and a discreet "Version complète" link, and a tab bar fixed at the bottom. Phones opening #/cards are sent to the same section in mobile mode unless the player chose the full version. Account, History and Administration point to the computer. The panels are the computer ones, adapted under .nebula-mobile (and body.nebula-mobile-body for dialogs) for a 393×852 reference phone: small cards with names under them when opening packs, a revealed card shown large on tap, tap-to-pick team recruitment with a single Recruit button and large stars, row lists for explorers and commons in the expedition pickers, a race track and circuit that read at phone size, and full-width actions throughout. Firefox no longer shows a mirrored back on a flipped card. Phone Playwright journeys check that every section fits the screen with no button wrapping, then open a pack, run an expedition and recruit a team by touch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
111 lines
6 KiB
JavaScript
111 lines
6 KiB
JavaScript
/**
|
||
* @file Cadre commun des tableaux de bord joueur et administration de Sokko TCG : menu de sections (menu
|
||
* déroulant quand la place manque), encart sous le menu, compte et chiffres clés.
|
||
*
|
||
* Points d'entrée : `CardsDashboardLayout`, `CardsStackedSection` (section sans colonne de menu, en mode
|
||
* mobile), `DashboardAside` (encart sous le menu, déclaré par un panneau), `CardsAccount`, `DashboardStat`.
|
||
* Utilisé par : CardsPage.jsx, admin/AdminPanel.jsx et mobile/MobileCardsLayout.jsx ; `DashboardAside` par
|
||
* l'accueil, les paquets, l'album et la boutique.
|
||
*/
|
||
|
||
import { createContext, Fragment, useContext, useEffect, useId, useRef, useState } from "react";
|
||
import { createPortal } from "react-dom";
|
||
|
||
const AsideSlotContext = createContext(null);
|
||
|
||
/**
|
||
* Menu de sections : colonne toujours ouverte dans le tableau de bord large ; en demi-écran, un bouton
|
||
* qui affiche la section courante ouvre la liste, refermée au choix d'une entrée, par Échap ou par un clic ailleurs.
|
||
* Une entrée [id, libellé, compteur, sous-entrées] peut porter des sous-entrées { id, label, href, current }, en retrait sous elle.
|
||
*/
|
||
function DashboardMenu({ label, groups, active, hrefFor }) {
|
||
const [open, setOpen] = useState(false);
|
||
const menuRef = useRef(null);
|
||
const toggleRef = useRef(null);
|
||
const navId = useId();
|
||
const items = groups.flat();
|
||
const activeItem = items.find(([id]) => id === active);
|
||
const activeChild = activeItem?.[3]?.find((child) => child.current);
|
||
const activeLabel = activeItem ? (activeChild ? `${activeItem[1]} › ${activeChild.label}` : activeItem[1]) : label;
|
||
const pending = items.reduce((total, [, , count]) => total + (count || 0), 0);
|
||
|
||
useEffect(() => {
|
||
if (!open) return undefined;
|
||
const closeOutside = (event) => { if (!menuRef.current?.contains(event.target)) setOpen(false); };
|
||
document.addEventListener("pointerdown", closeOutside);
|
||
return () => document.removeEventListener("pointerdown", closeOutside);
|
||
}, [open]);
|
||
|
||
const closeOnEscape = (event) => {
|
||
if (event.key !== "Escape" || !open) return;
|
||
setOpen(false);
|
||
toggleRef.current?.focus();
|
||
};
|
||
|
||
return <div ref={menuRef} className="nebula-dashboard-menu" onKeyDown={closeOnEscape}>
|
||
<button ref={toggleRef} className="nebula-dashboard-menu-toggle" type="button" aria-expanded={open} aria-controls={navId} onClick={() => setOpen((value) => !value)}>
|
||
<span className="nebula-dashboard-menu-icon" aria-hidden="true" />
|
||
<span className="nebula-dashboard-menu-current"><span className="sr-only">{label} : </span>{activeLabel}</span>
|
||
{pending > 0 && !open && <span className="nds-badge" data-variant="gold">{pending}</span>}
|
||
</button>
|
||
<nav id={navId} className="nebula-dashboard-nav" aria-label={label} data-open={open || undefined} onClick={(event) => { if (event.target.closest("a")) setOpen(false); }}>
|
||
{groups.map((group) => <div key={group[0][0]} className="nebula-dashboard-nav-group">
|
||
{group.map(([id, itemLabel, count, children]) => <Fragment key={id}>
|
||
<a className="nebula-dashboard-nav-item" href={hrefFor(id)} aria-current={active === id && !activeChild ? "page" : undefined} data-expanded={children?.length ? true : undefined}>{itemLabel}{count > 0 && <span className="nds-badge" data-variant="gold">{count}</span>}</a>
|
||
{children?.length > 0 && <div className="nebula-dashboard-nav-sub">
|
||
{children.map((child) => <a key={child.id} className="nebula-dashboard-nav-item" data-level="sub" href={child.href} aria-current={child.current ? "page" : undefined}>{child.label}</a>)}
|
||
</div>}
|
||
</Fragment>)}
|
||
</div>)}
|
||
</nav>
|
||
</div>;
|
||
}
|
||
|
||
export function CardsDashboardLayout({ label, groups, active, hrefFor, switchLink = null, busy = false, children }) {
|
||
const [asideSlot, setAsideSlot] = useState(null);
|
||
return <div className="nebula-dashboard-shell">
|
||
<div className="nebula-dashboard-aside">
|
||
{switchLink && <a className="nds-button" data-size="sm" data-variant="secondary" href={switchLink.href}>{switchLink.label}</a>}
|
||
<DashboardMenu label={label} groups={groups} active={active} hrefFor={hrefFor} />
|
||
<div ref={setAsideSlot} className="nebula-dashboard-aside-slot" />
|
||
</div>
|
||
<div className="nebula-dashboard-section" data-section={active} aria-busy={busy || undefined}>
|
||
<AsideSlotContext.Provider value={asideSlot}>{children}</AsideSlotContext.Provider>
|
||
</div>
|
||
</div>;
|
||
}
|
||
|
||
/**
|
||
* Section seule, sans colonne de menu : l'encart déclaré par le panneau (`DashboardAside`) passe au-dessus d'elle.
|
||
* Utilisé par le mode mobile, dont le menu est une barre d'onglets.
|
||
*/
|
||
export function CardsStackedSection({ active, busy = false, children }) {
|
||
const [asideSlot, setAsideSlot] = useState(null);
|
||
return <>
|
||
<div ref={setAsideSlot} className="nebula-dashboard-aside-slot" />
|
||
<div className="nebula-dashboard-section" data-section={active} aria-busy={busy || undefined}>
|
||
<AsideSlotContext.Provider value={asideSlot}>{children}</AsideSlotContext.Provider>
|
||
</div>
|
||
</>;
|
||
}
|
||
|
||
/** Place un encart propre à la section sous le menu, tout en gardant son état dans le panneau qui le déclare. */
|
||
export function DashboardAside({ children }) {
|
||
const slot = useContext(AsideSlotContext);
|
||
return slot ? createPortal(children, slot) : null;
|
||
}
|
||
|
||
export function CardsAccount({ player, onLogout }) {
|
||
return <div className="nebula-dashboard-account">
|
||
<span className="nebula-dashboard-account-player">{player.avatarUrl ? <img src={player.avatarUrl} alt="" referrerPolicy="no-referrer" /> : <i aria-hidden="true">✦</i>}<span>{player.displayName}</span></span>
|
||
{onLogout && <button className="nds-button" data-size="sm" data-variant="secondary" type="button" onClick={onLogout}>Déconnexion</button>}
|
||
</div>;
|
||
}
|
||
|
||
export function DashboardStat({ value, label, detail }) {
|
||
return <article className="nds-panel nebula-dashboard-stat">
|
||
<span className="nebula-dashboard-stat-label">{label}</span>
|
||
<strong>{value}</strong>
|
||
{detail && <small>{detail}</small>}
|
||
</article>;
|
||
}
|