A gold count now sits on the Sokko TCG menu icon while the opening reserve is full, so players notice it from any page. A light reserve route keeps it up to date outside the game, and the game page updates it with every state it gets. The opening stage also lists the remaining openings, apart for the automatic recharge and for openings bought one at a time, since the sidebar reserve is hidden there. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
108 lines
8.9 KiB
JavaScript
108 lines
8.9 KiB
JavaScript
// Rôle : structure le layout global avec sidebar, topbar, navigation et contenu.
|
|
import { useEffect, useRef } from "react";
|
|
import { useFullCardsReserve } from "../features/cards/cardsReserve.js";
|
|
import { Icon } from "./Icon.jsx";
|
|
import { ImportButton } from "./ImportButton.jsx";
|
|
import { Tooltip } from "./Tooltip.jsx";
|
|
|
|
export function Shell({ route, content, games, drawerGameId = "", drawerVisible = false, compactGameLayout = false, reducedSidebar = false, cardsEnabled = false, actions, onOpenAutoBackup, children }) {
|
|
const gameId = route.split("/")[1] === "games" ? route.split("/")[2] || "" : "";
|
|
const game = games.find((item) => item.id === gameId);
|
|
const topbarLabel = route === "/design-system" && import.meta.env.DEV ? "Design system" : route.startsWith("/toolbox") ? content.topbar.toolbox : route.startsWith("/games") ? content.topbar.games : route === "/library" ? content.topbar.library : route.startsWith("/cards") ? content.topbar.cards : content.topbar.dashboard;
|
|
const toolboxOpen = Boolean(game && drawerGameId === game.id && drawerVisible);
|
|
const toolboxLabel = toolboxOpen ? "Masquer la toolbox" : "Afficher la toolbox";
|
|
const compactSidebar = Boolean(reducedSidebar || (!compactGameLayout && toolboxOpen));
|
|
const compactToolboxVisible = Boolean(compactGameLayout && toolboxOpen);
|
|
const guideTabRef = useRef(null);
|
|
const toolboxTabRef = useRef(null);
|
|
const wideToolboxButtonRef = useRef(null);
|
|
const focusedViewControlRef = useRef("");
|
|
const previousCompactLayoutRef = useRef(compactGameLayout);
|
|
|
|
useEffect(() => {
|
|
const trackFocus = (event) => {
|
|
if (event.target.closest?.(".compact-game-view-switch")) focusedViewControlRef.current = "compact";
|
|
else if (event.target.closest?.(".toolbox-button")) focusedViewControlRef.current = "wide";
|
|
else focusedViewControlRef.current = "";
|
|
};
|
|
document.addEventListener("focusin", trackFocus);
|
|
return () => document.removeEventListener("focusin", trackFocus);
|
|
}, []);
|
|
|
|
useEffect(() => {
|
|
const activeElement = document.activeElement;
|
|
const layoutChanged = previousCompactLayoutRef.current !== compactGameLayout;
|
|
previousCompactLayoutRef.current = compactGameLayout;
|
|
if (layoutChanged && compactGameLayout && focusedViewControlRef.current === "wide") {
|
|
(compactToolboxVisible ? toolboxTabRef.current : guideTabRef.current)?.focus();
|
|
} else if (compactGameLayout && !compactToolboxVisible && activeElement?.closest?.("#toolbox-drawer")) {
|
|
guideTabRef.current?.focus();
|
|
} else if (layoutChanged && !compactGameLayout && focusedViewControlRef.current === "compact") {
|
|
wideToolboxButtonRef.current?.focus();
|
|
}
|
|
}, [compactGameLayout, compactToolboxVisible]);
|
|
|
|
const fullCardsReserve = useFullCardsReserve(cardsEnabled);
|
|
const cardsLabel = fullCardsReserve ? `${content.navigation.cards} (${content.navigation.cardsReserveFull})` : content.navigation.cards;
|
|
|
|
return (
|
|
<div className={`app-shell ${compactSidebar ? "sidebar-compact" : ""} ${!compactGameLayout && toolboxOpen ? "toolbox-drawer-open" : ""} ${compactToolboxVisible ? "compact-toolbox-visible" : ""}`}>
|
|
<aside className="sidebar" data-variant={compactSidebar ? "compact" : undefined}>
|
|
<a className="brand" href="#/" aria-label={content.brand.homeAriaLabel}>
|
|
<span className="brand-mark" aria-hidden="true" />
|
|
<span className="brand-name"><span className="brand-name-main">Sokko</span> <span className="brand-name-accent">G</span></span>
|
|
</a>
|
|
<nav className="nav" aria-label="Navigation principale">
|
|
<Tooltip as="a" className={`nav-item ${route === "/" ? "active" : ""}`} content={compactSidebar ? content.navigation.home : ""} position="right" href="#/" aria-label={content.navigation.home}><span className="nav-icon nav-icon-home" aria-hidden="true" /><strong>{content.navigation.home}</strong></Tooltip>
|
|
<Tooltip as="a" className={`nav-item ${route.startsWith("/games") ? "active" : ""}`} content={compactSidebar ? content.navigation.games : ""} position="right" href="#/games" aria-label={content.navigation.games}><span className="nav-icon nav-icon-controller" aria-hidden="true" /><strong>{content.navigation.games}</strong></Tooltip>
|
|
<Tooltip as="a" className={`nav-item ${route.startsWith("/toolboxes") || route.startsWith("/toolbox") ? "active" : ""}`} content={compactSidebar ? content.navigation.toolboxes : ""} position="right" href="#/toolboxes" aria-label={content.navigation.toolboxes}><span className="nav-icon nav-icon-toolbox" aria-hidden="true" /><strong>{content.navigation.toolboxes}</strong></Tooltip>
|
|
{cardsEnabled && <Tooltip as="a" className={`nav-item ${route.startsWith("/cards") ? "active" : ""}`} content={compactSidebar ? cardsLabel : ""} position="right" href="#/cards" aria-label={cardsLabel}><span className="nav-icon-slot" aria-hidden="true"><span className="nav-icon nav-icon-cards" />{fullCardsReserve && <span className="nav-icon-count">{fullCardsReserve}</span>}</span><strong>{content.navigation.cards}</strong></Tooltip>}
|
|
</nav>
|
|
<div className="sidebar-mascot" aria-hidden="true">
|
|
<img src="/static/img/dragon-sidebar.webp" alt="" />
|
|
</div>
|
|
<div className="sidebar-secondary-links">
|
|
<Tooltip as="a" className={`sidebar-about-link ${route === "/about" ? "active" : ""}`} content={compactSidebar ? content.navigation.about : ""} position="right" href="#/about" aria-label={content.navigation.about}><span className="sidebar-about-icon" aria-hidden="true">?</span><strong>{content.navigation.about}</strong></Tooltip>
|
|
<Tooltip as="a" className={`sidebar-about-link ${route === "/library" ? "active" : ""}`} content={compactSidebar ? content.library.eyebrow : ""} position="right" href="#/library" aria-label={content.library.eyebrow}><span className="sidebar-about-icon" aria-hidden="true"><Icon name="book" /></span><strong>{content.library.eyebrow}</strong></Tooltip>
|
|
{import.meta.env.DEV && (
|
|
<Tooltip as="a" className={`sidebar-about-link ${route === "/design-system" ? "active" : ""}`} content={compactSidebar ? "Design system" : ""} position="right" href="#/design-system" aria-label="Design system"><span className="sidebar-about-icon" aria-hidden="true"><Icon name="settings" /></span><strong>Design system</strong></Tooltip>
|
|
)}
|
|
</div>
|
|
<div className="sidebar-note">
|
|
<span className="badge">{content.sidebar.badge}</span>
|
|
<p>{cardsEnabled ? content.sidebar.cardsNote : content.sidebar.note}</p>
|
|
<div className="sidebar-storage-actions" aria-label="Actions globales de stockage">
|
|
<Tooltip as="button" className="sidebar-action-button sidebar-backup-button nds-button" content={compactSidebar ? content.toolboxes.autoBackup.title : ""} position="right" data-size="sm" data-variant="primary" type="button" onClick={onOpenAutoBackup} aria-label={content.toolboxes.autoBackup.title} title={compactSidebar ? undefined : content.toolboxes.autoBackup.title} data-toolbox-tutorial-target="backup">{compactSidebar && <Icon name="save" />}<span className="sidebar-storage-action-label">{content.toolboxes.autoBackup.sidebarLabel}</span></Tooltip>
|
|
<ImportButton className="sidebar-action-button nds-icon-button import-icon-button" data-size="sm" ariaLabel="Importer toutes les toolboxes" tooltip="Importer toutes les toolboxes" tooltipPosition="right" onFile={actions.importAllToolboxes} icon="import" />
|
|
</div>
|
|
</div>
|
|
</aside>
|
|
<div className="content-shell">
|
|
<header className="topbar">
|
|
<div><strong>{topbarLabel}</strong></div>
|
|
{game && (
|
|
<div className="topbar-actions">
|
|
{compactGameLayout ? <div className="compact-game-view-switch nds-radio-button-group" role="tablist" aria-label={content.topbar.gameViewLabel}>
|
|
<button ref={guideTabRef} type="button" role="tab" aria-selected={!compactToolboxVisible} className={!compactToolboxVisible ? "active" : ""} onClick={() => actions.setDrawerGameId("")}>{content.topbar.guideView}</button>
|
|
<button ref={toolboxTabRef} type="button" role="tab" aria-selected={compactToolboxVisible} className={compactToolboxVisible ? "active" : ""} onClick={() => actions.setDrawerGameId(game.id)}>{content.topbar.toolboxView}</button>
|
|
</div> : <button
|
|
className={`drawer-button toolbox-button nds-button ${toolboxOpen ? "active" : ""}`}
|
|
ref={wideToolboxButtonRef}
|
|
data-size="sm"
|
|
data-variant="primary"
|
|
onClick={() => actions.setDrawerGameId(toolboxOpen ? "" : game.id)}
|
|
aria-label={toolboxLabel}
|
|
aria-pressed={toolboxOpen}
|
|
title={toolboxLabel}
|
|
>
|
|
<img src="/static/icons/toolbox.svg" alt="" aria-hidden="true" />
|
|
<span>{toolboxLabel}</span>
|
|
</button>}
|
|
</div>
|
|
)}
|
|
</header>
|
|
<main>{children}</main>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|