- La Carte du jour: one zoomed card shared by all players each Paris day, six guesses with collection and rarity hints, a fixed stardust reward and an emoji result to share. - The Guilde des Veilleurs lists the quests, with a menu entry, a home banner and an admin section for quest settings. - The section menu folds into a dropdown below 960 px; the home pairs the guild with the best pull and moves the opening reserve under the menu. - The shop pack share moves to the shop collection admin page, which recalls where the pack draws its cards. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
78 lines
4.2 KiB
JavaScript
78 lines
4.2 KiB
JavaScript
// Rôle : fournit le cadre commun des tableaux de bord joueur et administration (menu de sections et encart associé, compte, chiffres clés).
|
|
import { createContext, 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.
|
|
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 activeLabel = items.find(([id]) => id === active)?.[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]) => <a key={id} className="nebula-dashboard-nav-item" href={hrefFor(id)} aria-current={active === id ? "page" : undefined}>{itemLabel}{count > 0 && <span className="nds-badge" data-variant="gold">{count}</span>}</a>)}
|
|
</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>;
|
|
}
|
|
|
|
// 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>;
|
|
}
|