Open any toolbox from a list in Sokko TCG's toolbox drawer
All checks were successful
Validate and deploy Sokko G / validate (push) Successful in 23m40s
Validate and deploy Sokko G / deploy (push) Successful in 16s

Every Sokko TCG section now offers the top bar's toolbox button. Instead of
linking a toolbox, the drawer lists all toolboxes (linked to a game or not)
as wide rows with a large cover, opens the one chosen, and remembers it on
the device. Memos and alerts follow the toolbox shown.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Shinuwa 2026-11-30 14:31:53 +01:00
parent e8fe27a90f
commit 8253f74c90
17 changed files with 359 additions and 45 deletions

View file

@ -1,17 +1,17 @@
// Rôle : affiche en bas de page les mémos et alertes de tâches de la toolbox courante ou liée au jeu.
// Rôle : affiche en bas de page les mémos et alertes de tâches de la toolbox courante, liée au jeu, ou choisie dans Sokko TCG.
import { useEffect, useMemo, useState } from "react";
import { moduleStorageKey, normalizeMemosData } from "./storage/toolboxStorage.js";
import { MemosTicker } from "./modules/MemosTicker.jsx";
import { getPlannerTaskTickerItems, resolveMemosPlannerLink } from "./modules/memosPlannerUtils.js";
import { getDrawerToolboxId, getRouteToolboxTargetId } from "./toolboxTargets.js";
function getRouteToolboxId(route, links) {
function getRouteToolboxId(route, links, cardsToolboxId, toolboxes) {
const toolboxMatch = route.match(/^\/toolbox\/([^/]+)/);
if (toolboxMatch) return decodeURIComponent(toolboxMatch[1]);
const gameMatch = route.match(/^\/games\/([^/]+)/);
return gameMatch ? links[gameMatch[1]] || "" : "";
return getDrawerToolboxId(getRouteToolboxTargetId(route), links, cardsToolboxId, toolboxes);
}
export function GlobalMemosTicker({ route, toolboxes, links, moduleData, textContent }) {
export function GlobalMemosTicker({ route, toolboxes, links, cardsToolboxId = "", moduleData, textContent }) {
const [nowMs, setNowMs] = useState(() => Date.now());
useEffect(() => {
@ -20,7 +20,7 @@ export function GlobalMemosTicker({ route, toolboxes, links, moduleData, textCon
}, []);
const items = useMemo(() => {
const toolboxId = getRouteToolboxId(route, links);
const toolboxId = getRouteToolboxId(route, links, cardsToolboxId, toolboxes);
const toolbox = toolboxes.find((item) => item.id === toolboxId);
if (!toolbox) return [];
return toolbox.modules
@ -41,7 +41,7 @@ export function GlobalMemosTicker({ route, toolboxes, links, moduleData, textCon
...taskItems.map((item) => ({ ...item, id: `${module.id}:${item.id}` }))
];
});
}, [route, toolboxes, links, moduleData, nowMs, textContent?.taskAlertTemplate]);
}, [route, toolboxes, links, cardsToolboxId, moduleData, nowMs, textContent?.taskAlertTemplate]);
if (!items.length) return null;
return (

View file

@ -22,11 +22,23 @@ export function formatDate(value) {
return new Intl.DateTimeFormat("fr-FR", { dateStyle: "medium", timeStyle: "short" }).format(new Date(value));
}
export function ToolboxCard({ toolbox, game, actions, reorder }) {
// Couverture d'une toolbox : celle du jeu lié, sinon l'image choisie, sinon son icône. `rect` distingue une image (bandeau)
// d'une icône (à centrer sur le dégradé).
export function getToolboxCover(toolbox, game) {
const gameCoverImage = getGameCardCover(game);
const customCoverImage = !gameCoverImage && toolbox.customCover ? toolbox.customCover : "";
const coverImage = gameCoverImage || customCoverImage || toolbox.icon || DEFAULT_TOOLBOX_ICON;
const hasRectCover = Boolean(gameCoverImage || customCoverImage);
return {
src: gameCoverImage || customCoverImage || toolbox.icon || DEFAULT_TOOLBOX_ICON,
rect: Boolean(gameCoverImage || customCoverImage),
custom: Boolean(customCoverImage)
};
}
export function ToolboxCard({ toolbox, game, actions, reorder }) {
const cover = getToolboxCover(toolbox, game);
const customCoverImage = cover.custom ? cover.src : "";
const coverImage = cover.src;
const hasRectCover = cover.rect;
const className = [
"card",
"nds-card",

View file

@ -9,7 +9,7 @@ import { StorageQuota } from "../../components/StorageQuota.jsx";
import { useGroupedReorder } from "../../hooks/useGroupedReorder.js";
import { useInlineEdit } from "../../hooks/useInlineEdit.js";
import { compressImage } from "../../utils/imageCompression.js";
import { getGameCardCover, ToolboxCard, ToolboxGameIcon, ToolboxIconPicker } from "./ToolboxCard.jsx";
import { getGameCardCover, getToolboxCover, ToolboxCard, ToolboxGameIcon, ToolboxIconPicker } from "./ToolboxCard.jsx";
import { AddToolControls, ToolboxModules } from "./modules/index.jsx";
import { getMemosDataAfterPlannerRemoval } from "./modules/memosPlannerUtils.js";
import { ToolboxSpaces } from "./ToolboxSpaces.jsx";
@ -333,7 +333,7 @@ function ToolboxView({ siteContent, toolbox, toolboxGame, embedded, actions, sto
<EditableTitle className="toolbox-title" value={toolbox.name} fallback="Nouvelle toolbox" tutorialTarget="title" onSave={(name) => name !== toolbox.name && updateToolbox({ ...toolbox, name })} />
)}
</div>
{toolboxGame && (
{(embedded || toolboxGame) && (
<a
className="toolbox-hero-link nds-button"
data-size="sm"
@ -432,11 +432,14 @@ function ToolboxView({ siteContent, toolbox, toolboxGame, embedded, actions, sto
);
}
export function ToolboxDrawer({ gameId, game, siteContent, toolboxes, links, actions, storageUsage, storageReady = true, getModuleData, updateToolbox, updateModuleData, addImageFiles, visible = true, compact = false }) {
// Tiroir de toolbox. Sur une page de jeu, il montre la toolbox liée au jeu (`toolboxId`). Dans Sokko TCG (`chooser`), aucune liaison :
// il liste toutes les toolboxes, ouvre celle choisie et « Changer de toolbox » ramène à la liste.
export function ToolboxDrawer({ gameId, game, toolboxId = "", chooser = null, siteContent, toolboxes, links, actions, storageUsage, storageReady = true, getModuleData, updateToolbox, updateModuleData, addImageFiles, visible = true, compact = false }) {
const checklist = useGuideChecklist();
const guideChecklist = checklist.available && checklist.guideId.split("/")[0] === gameId ? checklist : undefined;
const selectedId = links[gameId] || "";
const guideChecklist = !chooser && checklist.available && checklist.guideId.split("/")[0] === gameId ? checklist : undefined;
const selectedId = toolboxId;
const toolbox = toolboxes.find((item) => item.id === selectedId);
const chooserText = siteContent.toolboxes.drawer.chooser;
const [width, setWidth] = useState(DRAWER_INITIAL_WIDTH);
const panelRef = useRef(null);
@ -479,19 +482,23 @@ export function ToolboxDrawer({ gameId, game, siteContent, toolboxes, links, act
<div className="drawer-content">
<header>
<div>
<p className="eyebrow">Toolbox liée</p>
<div className="drawer-toolbox-actions nds-toolbar" aria-label="Actions toolbox liée">
<p className="eyebrow">{chooser ? chooserText.eyebrow : "Toolbox liée"}</p>
{chooser ? toolbox && <div className="drawer-toolbox-actions nds-toolbar" aria-label={chooserText.actionsLabel}>
<button className="nds-button" data-size="sm" data-variant="secondary" type="button" onClick={() => chooser.onChoose("")}><Icon name="back" />{chooserText.changeLabel}</button>
<button className="drawer-action-button nds-icon-button" data-size="sm" onClick={() => actions.exportToolbox(selectedId)} aria-label={`Exporter ${toolbox.name}`} title="Exporter"><Icon name="export" /></button>
{actions.sharingEnabled && <button className="drawer-action-button nds-icon-button" data-size="sm" onClick={() => actions.openShareToolbox(selectedId)} aria-label={`Envoyer ${toolbox.name}`} title="Envoyer"><Icon name="share" /></button>}
</div> : <div className="drawer-toolbox-actions nds-toolbar" aria-label="Actions toolbox liée">
<button className="drawer-action-button nds-icon-button" data-size="sm" onClick={() => actions.setLinkModalGameId(gameId)} aria-label="Lier une toolbox" title="Lier"><Icon name="link" /></button>
<ImportButton className="drawer-action-button nds-icon-button import-icon-button" data-size="sm" ariaLabel="Importer une toolbox" title="Importer" icon="import" onFile={(file) => actions.importToolbox(file, gameId)} />
<button className="drawer-action-button nds-icon-button" data-size="sm" onClick={() => actions.exportToolbox(selectedId)} disabled={!selectedId} aria-label="Exporter la toolbox liée" title="Exporter"><Icon name="export" /></button>
{actions.sharingEnabled && <button className="drawer-action-button nds-icon-button" data-size="sm" onClick={() => actions.openShareToolbox(selectedId)} disabled={!selectedId} aria-label="Envoyer la toolbox liée" title="Envoyer"><Icon name="share" /></button>}
</div>
</div>}
</div>
<button className="drawer-close-button nds-icon-button" data-size="sm" onClick={() => actions.setDrawerGameId("")} aria-label="Fermer" title="Fermer"><Icon name="close" /></button>
</header>
{toolbox ? <ToolboxView siteContent={siteContent} toolbox={toolbox} toolboxGame={game} embedded actions={actions} storageUsage={storageUsage} storageReady={storageReady} getModuleData={getModuleData} updateToolbox={updateToolbox} updateModuleData={updateModuleData} addImageFiles={addImageFiles} guideChecklist={guideChecklist} /> : (
<ToolboxDrawerEmptyState gameId={gameId} toolboxes={toolboxes} links={links} actions={actions} content={siteContent.toolboxes.drawer} />
)}
{toolbox ? <ToolboxView key={toolbox.id} siteContent={siteContent} toolbox={toolbox} toolboxGame={game} embedded actions={actions} storageUsage={storageUsage} storageReady={storageReady} getModuleData={getModuleData} updateToolbox={updateToolbox} updateModuleData={updateModuleData} addImageFiles={addImageFiles} guideChecklist={guideChecklist} />
: chooser ? <ToolboxDrawerChooser toolboxes={toolboxes} getToolboxGame={chooser.getToolboxGame} onChoose={chooser.onChoose} actions={actions} content={chooserText} />
: <ToolboxDrawerEmptyState gameId={gameId} toolboxes={toolboxes} links={links} actions={actions} content={siteContent.toolboxes.drawer} />}
<StorageQuota usage={storageUsage} />
</div>
</section>
@ -499,6 +506,32 @@ export function ToolboxDrawer({ gameId, game, siteContent, toolboxes, links, act
);
}
// Liste du tiroir de Sokko TCG : une bande par toolbox (grande illustration, nom, jeu lié), dans l'ordre de la page Toolboxes.
// Une nouvelle toolbox s'ouvre aussitôt dans le tiroir, sans être liée à rien.
function ToolboxDrawerChooser({ toolboxes, getToolboxGame, onChoose, actions, content }) {
const create = () => actions.setCreateModal({ onCreated: (toolbox) => onChoose(toolbox.id) });
if (!toolboxes.length) return <section className="empty nds-empty-state drawer-toolbox-chooser-empty">
<p>{content.emptyText}</p>
<button className="nds-button" data-size="sm" data-variant="primary" type="button" onClick={create}><Icon name="add" />{content.createLabel}</button>
</section>;
return <section className="drawer-toolbox-chooser" aria-labelledby="drawer-toolbox-chooser-title">
<h2 id="drawer-toolbox-chooser-title">{content.title}</h2>
<ul className="drawer-toolbox-chooser-list">
{toolboxes.map((toolbox) => {
const game = getToolboxGame(toolbox);
const cover = getToolboxCover(toolbox, game);
return <li key={toolbox.id} className="nds-list-row drawer-toolbox-chooser-row">
<button type="button" onClick={() => onChoose(toolbox.id)}>
<span className="drawer-toolbox-chooser-cover" data-shape={cover.rect ? "image" : "icon"}><img src={cover.src} alt="" loading="lazy" /></span>
<span className="drawer-toolbox-chooser-text"><strong>{toolbox.name}</strong><small>{game ? game.title : content.freeLabel}</small></span>
</button>
</li>;
})}
</ul>
<button className="nds-button drawer-toolbox-chooser-create" data-size="sm" data-variant="dashed" type="button" onClick={create}><Icon name="add" />{content.createLabel}</button>
</section>;
}
function ToolboxDrawerEmptyState({ gameId, toolboxes, links, actions, content }) {
const linkedToolboxIds = useMemo(() => new Set(Object.values(links).filter(Boolean)), [links]);
const availableToolboxes = useMemo(

View file

@ -0,0 +1,19 @@
// Rôle : nomme les pages qui ouvrent le tiroir de toolbox : la page d'un jeu (sa toolbox liée), ou Sokko TCG dans toutes ses
// sections, où le joueur choisit n'importe laquelle de ses toolboxes dans une liste, sans liaison.
export const CARDS_TOOLBOX_TARGET_ID = "sokko-tcg";
// Le même tiroir reste ouvert d'une section de Sokko TCG à l'autre (Guilde, Expéditions, Collection…), administration comprise.
export function getRouteToolboxTargetId(route) {
const gameMatch = route.match(/^\/games\/([^/]+)/);
// `/games/sokko-tcg` n'est pas une page de jeu : elle n'ouvre pas le tiroir de Sokko TCG.
if (gameMatch) return gameMatch[1] === CARDS_TOOLBOX_TARGET_ID ? "" : gameMatch[1];
return route === "/cards" || route.startsWith("/cards/") ? CARDS_TOOLBOX_TARGET_ID : "";
}
// Toolbox affichée par le tiroir : celle liée au jeu, ou celle choisie dans Sokko TCG tant qu'elle existe encore.
export function getDrawerToolboxId(targetId, links, cardsToolboxId, toolboxes) {
if (!targetId) return "";
if (targetId !== CARDS_TOOLBOX_TARGET_ID) return links[targetId] || "";
return cardsToolboxId && toolboxes.some((toolbox) => toolbox.id === cardsToolboxId) ? cardsToolboxId : "";
}

View file

@ -0,0 +1,27 @@
// Rôle : retient, sur cet appareil, la toolbox choisie dans le tiroir de Sokko TCG, pour la rouvrir directement à la visite suivante.
// Une préférence d'affichage, pas une donnée de toolbox : elle n'entre ni dans les liaisons ni dans les exports.
import { useCallback, useState } from "react";
const CARDS_TOOLBOX_STORAGE_KEY = "sokkog:cards-toolbox";
function readChoice() {
try {
return globalThis.localStorage?.getItem(CARDS_TOOLBOX_STORAGE_KEY) || "";
} catch {
return "";
}
}
export function useCardsToolboxChoice() {
const [toolboxId, setToolboxId] = useState(readChoice);
const choose = useCallback((nextId) => {
setToolboxId(nextId || "");
try {
if (nextId) globalThis.localStorage?.setItem(CARDS_TOOLBOX_STORAGE_KEY, nextId);
else globalThis.localStorage?.removeItem(CARDS_TOOLBOX_STORAGE_KEY);
} catch {
// Stockage refusé (navigation privée, quota) : le choix vaut pour la session.
}
}, []);
return [toolboxId, choose];
}