diff --git a/.beads/interactions.jsonl b/.beads/interactions.jsonl index 5a35d4b..50ba43e 100644 --- a/.beads/interactions.jsonl +++ b/.beads/interactions.jsonl @@ -501,3 +501,4 @@ {"id":"int-c432affacccf11095a7349e6a9cf1107","kind":"field_change","created_at":"2026-11-30T10:29:14.693613904Z","actor":"Shinuwa","issue_id":"sokko-g-akg7","extra":{"field":"status","new_value":"closed","old_value":"open","reason":"Pastille ajoutée (CardsPage navigationCounts.packs), test e2e mis à jour"}} {"id":"int-622c82c7a1fac1f9758f971874d8a80f","kind":"field_change","created_at":"2026-11-30T11:15:28.399226475Z","actor":"Shinuwa","issue_id":"sokko-g-wqfj","extra":{"field":"status","new_value":"closed","old_value":"open","reason":"bonusOffers côté serveur + BonusOffers dans le planificateur. npm run check 463/463, e2e cards 15/15."}} {"id":"int-e75296b6fbef720fbc6ae7cf1f92fb25","kind":"field_change","created_at":"2026-11-30T12:14:21.343085085Z","actor":"Shinuwa","issue_id":"sokko-g-8qjt","extra":{"field":"status","new_value":"closed","old_value":"open","reason":"npm run check 463/463, e2e cards 15/15."}} +{"id":"int-5f9231ef4e37eb6f4a922438fd43ef78","kind":"field_change","created_at":"2026-11-30T13:00:01.89545152Z","actor":"Shinuwa","issue_id":"sokko-g-p2gx","extra":{"field":"status","new_value":"closed","old_value":"open","reason":"Tiroir de toolbox ouvert sur toutes les routes /cards via la clé sokko-tcg ; tests unitaires et e2e ajoutés."}} diff --git a/docs/STORAGE_SCHEMA.md b/docs/STORAGE_SCHEMA.md index 277941d..314f19d 100644 --- a/docs/STORAGE_SCHEMA.md +++ b/docs/STORAGE_SCHEMA.md @@ -822,6 +822,10 @@ Les associations entre pages jeux et toolboxes sont stockées dans `kv/links`. } ``` +Sokko TCG n'a pas de liaison : son tiroir liste toutes les toolboxes, liées à un jeu ou non. `localStorage["sokkog:cards-toolbox"]` +retient l'identifiant de la dernière toolbox choisie, pour la rouvrir directement ; une préférence de l'appareil, jamais exportée +ni sauvegardée. Une toolbox supprimée depuis ramène simplement à la liste. + ## Outil Bloc Note Type : `notepad` diff --git a/e2e/nebula-cards.spec.js b/e2e/nebula-cards.spec.js index ad7ab8f..26d377f 100644 --- a/e2e/nebula-cards.spec.js +++ b/e2e/nebula-cards.spec.js @@ -4,6 +4,7 @@ import { tmpdir } from "node:os"; import { join } from "node:path"; import { DatabaseSync } from "node:sqlite"; import { expect, test } from "@playwright/test"; +import { readStoredSnapshot } from "./helpers/storage.js"; // Sélecteurs à choix unique du design system (`SelectDropdown`). const selectTrigger = (scope, label) => scope.getByRole("button", { name: new RegExp(`^${label} : `) }); @@ -2705,3 +2706,58 @@ test("an administrator opens the broken mirror and a player rebuilds the easy an await page.getByRole("dialog").getByRole("button", { name: "Fermer", exact: true }).click(); await expect(status).toContainText("Fermé aux joueurs"); }); + +test("the Sokko TCG drawer opens any toolbox from a list and remembers the choice", async ({ page }) => { + test.setTimeout(60_000); + await page.setViewportSize({ width: 1600, height: 900 }); + await page.goto("/#/cards/guild"); + await page.getByRole("button", { name: "Version développement", exact: true }).click(); + await expect(page.locator(".nebula-quests")).toBeVisible(); + const drawer = page.locator("#toolbox-drawer"); + const openedTitle = (name) => drawer.getByRole("heading", { level: 1, name, exact: true }); + const createInDrawer = async (name) => { + await drawer.getByRole("button", { name: "Nouvelle toolbox", exact: true }).click(); + await page.getByRole("textbox", { name: "Nom", exact: true }).fill(name); + await page.getByRole("button", { name: "Créer", exact: true }).click(); + await expect(openedTitle(name)).toBeVisible(); + }; + + // Sans toolbox, le tiroir propose d'en créer une : elle s'y ouvre sans quitter le jeu. + await page.getByRole("button", { name: "Afficher la toolbox", exact: true }).click(); + await expect(drawer).toContainText("Aucune toolbox pour l’instant."); + await createInDrawer("Notes TCG"); + await expect(page).toHaveURL(/#\/cards\/guild$/); + + // Passer de la Guilde aux Expéditions garde la toolbox ouverte. + await page.goto("/#/cards/expeditions"); + await expect(page.getByRole("button", { name: "Masquer la toolbox", exact: true })).toHaveAttribute("aria-pressed", "true"); + await expect(openedTitle("Notes TCG")).toBeVisible(); + + // « Changer de toolbox » ramène à la liste, d'où l'on en crée ou en ouvre une autre. + await drawer.getByRole("button", { name: "Changer de toolbox", exact: true }).click(); + await expect(drawer.getByRole("heading", { name: "Quelle toolbox ouvrir ?" })).toBeVisible(); + await expect(drawer.locator(".drawer-toolbox-chooser-row")).toHaveText(["Notes TCGToolbox libre"]); + await createInDrawer("Build"); + + // Le choix est retenu : après un rechargement, le tiroir rouvre directement « Build » (une fois la toolbox enregistrée). + await expect.poll(async () => (await readStoredSnapshot(page)).toolboxes.map((toolbox) => toolbox.name)).toContain("Build"); + await page.reload(); + await page.getByRole("button", { name: "Afficher la toolbox", exact: true }).click(); + await expect(openedTitle("Build")).toBeVisible(); + + // Une toolbox liée à un jeu reste disponible dans Sokko TCG, sans perdre sa liaison. La liste suit l'ordre de la page Toolboxes. + await page.goto("/#/games/mhwilds"); + await page.getByRole("button", { name: "Afficher la toolbox", exact: true }).click(); + await drawer.getByLabel("Toolbox disponible").selectOption({ label: "Notes TCG" }); + await drawer.getByRole("button", { name: "Associer", exact: true }).click(); + await expect(openedTitle("Notes TCG")).toBeVisible(); + await page.goto("/#/cards/collection"); + await page.getByRole("button", { name: "Afficher la toolbox", exact: true }).click(); + await drawer.getByRole("button", { name: "Changer de toolbox", exact: true }).click(); + await expect(drawer.locator(".drawer-toolbox-chooser-row")).toHaveText(["BuildToolbox libre", "Notes TCGMonster Hunter Wilds"]); + await drawer.getByRole("button", { name: /^Notes TCG/ }).click(); + await expect(openedTitle("Notes TCG")).toBeVisible(); + await page.goto("/#/games/mhwilds"); + await page.getByRole("button", { name: "Afficher la toolbox", exact: true }).click(); + await expect(openedTitle("Notes TCG")).toBeVisible(); +}); diff --git a/tests/helpers/data-validation.mjs b/tests/helpers/data-validation.mjs index ce40a4f..8c677e3 100644 --- a/tests/helpers/data-validation.mjs +++ b/tests/helpers/data-validation.mjs @@ -101,6 +101,7 @@ export function validateSiteContent(site) { "topbar.cards", "topbar.gameViewLabel", "topbar.guideView", + "topbar.cardsView", "topbar.toolboxView", "gamesPage.eyebrow", "gamesPage.title", @@ -942,6 +943,13 @@ export function validateSiteContent(site) { "toolboxes.drawer.selectPlaceholder", "toolboxes.drawer.noAvailable", "toolboxes.drawer.linkLabel", + "toolboxes.drawer.chooser.eyebrow", + "toolboxes.drawer.chooser.title", + "toolboxes.drawer.chooser.actionsLabel", + "toolboxes.drawer.chooser.changeLabel", + "toolboxes.drawer.chooser.freeLabel", + "toolboxes.drawer.chooser.emptyText", + "toolboxes.drawer.chooser.createLabel", "toolboxes.title", "toolboxes.newButton", "toolboxes.createShortButton", diff --git a/tests/toolbox-alert-visibility.test.mjs b/tests/toolbox-alert-visibility.test.mjs index 3f6ab85..b779ac7 100644 --- a/tests/toolbox-alert-visibility.test.mjs +++ b/tests/toolbox-alert-visibility.test.mjs @@ -4,11 +4,14 @@ import assert from "node:assert/strict"; import { getVisibleToolboxIds } from "../website/src/hooks/useToolboxAlerts.js"; test("a mounted compact drawer is visible only while its toolbox view is selected", () => { - const links = { mhwilds: "linked" }; - assert.deepEqual([...getVisibleToolboxIds("/games/mhwilds/monsters", "", links)], []); - assert.deepEqual([...getVisibleToolboxIds("/games/mhwilds/monsters", "mhwilds", links)], ["linked"]); + assert.deepEqual([...getVisibleToolboxIds("/games/mhwilds/monsters", "")], []); + assert.deepEqual([...getVisibleToolboxIds("/games/mhwilds/monsters", "linked")], ["linked"]); +}); + +test("the toolbox chosen in the Sokko TCG drawer is visible like a linked one", () => { + assert.deepEqual([...getVisibleToolboxIds("/cards/guild", "chosen")], ["chosen"]); }); test("a full toolbox page remains visible independently of the game drawer", () => { - assert.deepEqual([...getVisibleToolboxIds("/toolbox/personal", "", {})], ["personal"]); + assert.deepEqual([...getVisibleToolboxIds("/toolbox/personal", "")], ["personal"]); }); diff --git a/tests/toolbox-targets.test.mjs b/tests/toolbox-targets.test.mjs new file mode 100644 index 0000000..02a39fe --- /dev/null +++ b/tests/toolbox-targets.test.mjs @@ -0,0 +1,38 @@ +// Rôle : vérifie quelles pages ouvrent le tiroir de toolbox et quelle toolbox il affiche : la toolbox liée d'un jeu, ou celle +// choisie dans Sokko TCG, sans liaison. +import { test } from "node:test"; +import assert from "node:assert/strict"; +import { CARDS_TOOLBOX_TARGET_ID, getDrawerToolboxId, getRouteToolboxTargetId } from "../website/src/features/toolboxes/toolboxTargets.js"; + +test("a game page targets its game", () => { + assert.equal(getRouteToolboxTargetId("/games/mhwilds"), "mhwilds"); + assert.equal(getRouteToolboxTargetId("/games/mhwilds/monsters"), "mhwilds"); +}); + +test("every Sokko TCG section shares the same target", () => { + for (const route of ["/cards", "/cards/guild", "/cards/expeditions", "/cards/expeditions/abc", "/cards/admin/catalog"]) { + assert.equal(getRouteToolboxTargetId(route), CARDS_TOOLBOX_TARGET_ID, route); + } +}); + +test("other pages have no target", () => { + for (const route of ["/", "/games", "/toolboxes", "/toolbox/abc", "/library", "/cardsx", "/games/sokko-tcg"]) { + assert.equal(getRouteToolboxTargetId(route), "", route); + } +}); + +test("a game drawer shows the toolbox linked to the game", () => { + const links = { mhwilds: "tbx1" }; + assert.equal(getDrawerToolboxId("mhwilds", links, "tbx2", [{ id: "tbx1" }, { id: "tbx2" }]), "tbx1"); + assert.equal(getDrawerToolboxId("diablo4", links, "tbx2", [{ id: "tbx1" }, { id: "tbx2" }]), ""); + assert.equal(getDrawerToolboxId("", links, "tbx2", [{ id: "tbx1" }, { id: "tbx2" }]), ""); +}); + +test("the Sokko TCG drawer shows the chosen toolbox, linked to a game or not, until it is deleted", () => { + const links = { mhwilds: "tbx1" }; + const toolboxes = [{ id: "tbx1" }, { id: "tbx2" }]; + assert.equal(getDrawerToolboxId(CARDS_TOOLBOX_TARGET_ID, links, "tbx1", toolboxes), "tbx1"); + assert.equal(getDrawerToolboxId(CARDS_TOOLBOX_TARGET_ID, links, "tbx2", toolboxes), "tbx2"); + assert.equal(getDrawerToolboxId(CARDS_TOOLBOX_TARGET_ID, links, "", toolboxes), ""); + assert.equal(getDrawerToolboxId(CARDS_TOOLBOX_TARGET_ID, links, "deleted", toolboxes), ""); +}); diff --git a/website/public/data/site.json b/website/public/data/site.json index 825ec49..26fdc96 100644 --- a/website/public/data/site.json +++ b/website/public/data/site.json @@ -25,6 +25,7 @@ "cards": "Sokko TCG", "gameViewLabel": "Vue de la page jeu", "guideView": "Guide", + "cardsView": "Jeu", "toolboxView": "Toolbox" }, "gamesPage": { @@ -2922,7 +2923,16 @@ "selectLabel": "Toolbox disponible", "selectPlaceholder": "Choisir une toolbox", "noAvailable": "Aucune toolbox disponible", - "linkLabel": "Associer" + "linkLabel": "Associer", + "chooser": { + "eyebrow": "Toolbox", + "title": "Quelle toolbox ouvrir ?", + "actionsLabel": "Actions de la toolbox ouverte", + "changeLabel": "Changer de toolbox", + "freeLabel": "Toolbox libre", + "emptyText": "Aucune toolbox pour l’instant.", + "createLabel": "Nouvelle toolbox" + } }, "storageStatus": { "loadingTitle": "Chargement des données locales", diff --git a/website/src/components/AppOverlays.jsx b/website/src/components/AppOverlays.jsx index 77e9b59..458bbcc 100644 --- a/website/src/components/AppOverlays.jsx +++ b/website/src/components/AppOverlays.jsx @@ -65,7 +65,9 @@ export function AppOverlays({ if (!name) return; const toolbox = actions.createToolbox(name, gameId, { tutorial: createModal.tutorial === true }); if (toolbox && createModal.tutorial === true) setPendingTutorialToolboxId?.(toolbox.id); - if (toolbox && gameId) setDrawerGameId(gameId); + // Créée depuis le tiroir de Sokko TCG : elle s'y ouvre, sans liaison ni changement de page. + if (toolbox && createModal.onCreated) createModal.onCreated(toolbox); + else if (toolbox && gameId) setDrawerGameId(gameId); else if (toolbox) { navigate(`/toolbox/${toolbox.id}`); scrollToTopAfterNavigation(); diff --git a/website/src/components/Shell.jsx b/website/src/components/Shell.jsx index 8ec0041..6a20e1f 100644 --- a/website/src/components/Shell.jsx +++ b/website/src/components/Shell.jsx @@ -5,11 +5,10 @@ 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); +// `toolboxTargetId` : le jeu (sa toolbox liée) ou Sokko TCG (une toolbox au choix) dont la page ouvre le tiroir, sinon vide. +export function Shell({ route, content, toolboxTargetId = "", drawerGameId = "", drawerVisible = false, compactGameLayout = false, reducedSidebar = false, cardsEnabled = false, actions, onOpenAutoBackup, children }) { const topbarLabel = route === "/design-system" && import.meta.env.DEV ? "Design system" : route.startsWith("/toolbox") || route.startsWith("/receive/") ? 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 toolboxOpen = Boolean(toolboxTargetId && drawerGameId === toolboxTargetId && drawerVisible); const toolboxLabel = toolboxOpen ? "Masquer la toolbox" : "Afficher la toolbox"; const compactSidebar = Boolean(reducedSidebar || (!compactGameLayout && toolboxOpen)); const compactToolboxVisible = Boolean(compactGameLayout && toolboxOpen); @@ -80,17 +79,17 @@ export function Shell({ route, content, games, drawerGameId = "", drawerVisible
{topbarLabel}
- {game && ( + {toolboxTargetId && (
{compactGameLayout ?
- - + +
:
- {toolboxGame && ( + {(embedded || toolboxGame) && ( 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
-

Toolbox liée

-
+

{chooser ? chooserText.eyebrow : "Toolbox liée"}

+ {chooser ? toolbox &&
+ + + {actions.sharingEnabled && } +
:
actions.importToolbox(file, gameId)} /> {actions.sharingEnabled && } -
+
}
- {toolbox ? : ( - - )} + {toolbox ? + : chooser ? + : }
@@ -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
+

{content.emptyText}

+ +
; + return
+

{content.title}

+
    + {toolboxes.map((toolbox) => { + const game = getToolboxGame(toolbox); + const cover = getToolboxCover(toolbox, game); + return
  • + +
  • ; + })} +
+ +
; +} + function ToolboxDrawerEmptyState({ gameId, toolboxes, links, actions, content }) { const linkedToolboxIds = useMemo(() => new Set(Object.values(links).filter(Boolean)), [links]); const availableToolboxes = useMemo( diff --git a/website/src/features/toolboxes/toolboxTargets.js b/website/src/features/toolboxes/toolboxTargets.js new file mode 100644 index 0000000..d6508a3 --- /dev/null +++ b/website/src/features/toolboxes/toolboxTargets.js @@ -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 : ""; +} diff --git a/website/src/features/toolboxes/useCardsToolboxChoice.js b/website/src/features/toolboxes/useCardsToolboxChoice.js new file mode 100644 index 0000000..d634933 --- /dev/null +++ b/website/src/features/toolboxes/useCardsToolboxChoice.js @@ -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]; +} diff --git a/website/src/hooks/useToolboxAlerts.js b/website/src/hooks/useToolboxAlerts.js index a95aeb2..328a673 100644 --- a/website/src/hooks/useToolboxAlerts.js +++ b/website/src/hooks/useToolboxAlerts.js @@ -4,11 +4,11 @@ import { getCalendarAlertOffsets, getCurrentCalendarOccurrence, getNextCalendarA import { getCountdownTargetMs } from "../features/toolboxes/modules/timerUtils.js"; import { moduleStorageKey } from "../features/toolboxes/storage/toolboxStorage.js"; -export function getVisibleToolboxIds(route, drawerGameId, links) { +// `drawerToolboxId` : la toolbox affichée par le tiroir (liée au jeu, ou choisie dans Sokko TCG), vide tant qu'il est masqué. +export function getVisibleToolboxIds(route, drawerToolboxId) { const visibleIds = new Set(); const toolboxMatch = route.match(/^\/toolbox\/([^/]+)/); if (toolboxMatch?.[1]) visibleIds.add(toolboxMatch[1]); - const drawerToolboxId = drawerGameId ? links[drawerGameId] : ""; if (drawerToolboxId) visibleIds.add(drawerToolboxId); return visibleIds; } @@ -25,13 +25,13 @@ function formatAlertMessage(template, toolbox, label) { .replaceAll("{toolbox}", toolbox.name); } -export function useToolboxAlerts({ toolboxes, moduleData, links, route, drawerGameId, normalizeTimerData, normalizeCalendarData, textContent, notify }) { +export function useToolboxAlerts({ toolboxes, moduleData, route, drawerToolboxId, normalizeTimerData, normalizeCalendarData, textContent, notify }) { const previousTargetsRef = useRef(new Map()); const resumedCalendarEventsRef = useRef(new Set()); const lastTickRef = useRef(null); useEffect(() => { - const visibleToolboxIds = getVisibleToolboxIds(route, drawerGameId, links); + const visibleToolboxIds = getVisibleToolboxIds(route, drawerToolboxId); const timerAlertTemplate = textContent?.timer?.alertMessage || "Compte à rebours terminé : {label}"; const calendarAlertTemplate = textContent?.calendar?.alertMessage || "Événement à venir : {label}"; const calendarResumeTemplate = textContent?.calendar?.resumeAlertMessage || "Événement en cours : {label}"; @@ -96,5 +96,5 @@ export function useToolboxAlerts({ toolboxes, moduleData, links, route, drawerGa tick(); const intervalId = window.setInterval(tick, 500); return () => window.clearInterval(intervalId); - }, [drawerGameId, links, moduleData, normalizeCalendarData, normalizeTimerData, notify, route, textContent, toolboxes]); + }, [drawerToolboxId, moduleData, normalizeCalendarData, normalizeTimerData, notify, route, textContent, toolboxes]); } diff --git a/website/src/main.jsx b/website/src/main.jsx index 2d2d6dd..26b64dc 100644 --- a/website/src/main.jsx +++ b/website/src/main.jsx @@ -19,6 +19,8 @@ import { useHashRoute } from "./router/hashRouter.js"; import { normalizeCalendarData, normalizeTimerData } from "./features/toolboxes/storage/toolboxStorage.js"; import { useAutoBackup } from "./features/toolboxes/storage/useAutoBackup.js"; import { GlobalMemosTicker } from "./features/toolboxes/GlobalMemosTicker.jsx"; +import { CARDS_TOOLBOX_TARGET_ID, getDrawerToolboxId, getRouteToolboxTargetId } from "./features/toolboxes/toolboxTargets.js"; +import { useCardsToolboxChoice } from "./features/toolboxes/useCardsToolboxChoice.js"; import { useMediaQuery } from "./hooks/useMediaQuery.js"; import { useCardsConfig } from "./features/cards/useCardsConfig.js"; import { useSharesConfig } from "./features/toolboxes/sharing/useSharesConfig.js"; @@ -70,6 +72,7 @@ function App() { const [drawerGameId, setDrawerGameId] = useState(""); const [drawerVisible, setDrawerVisible] = useState(false); const [drawerContext, setDrawerContext] = useState({ route, compactGameLayout }); + const [cardsToolboxId, setCardsToolboxId] = useCardsToolboxChoice(); const [image, setImage] = useState(null); const [pendingTutorialToolboxId, setPendingTutorialToolboxId] = useState(""); const [notifications, setNotifications] = useState([]); @@ -100,7 +103,7 @@ function App() { if (drawerContext.route !== route || drawerContext.compactGameLayout !== compactGameLayout) { setDrawerContext({ route, compactGameLayout }); - const activeGameId = route.match(/^\/games\/([^/]+)/)?.[1] || ""; + const activeGameId = getRouteToolboxTargetId(route); if (activeGameId !== drawerGameId) { setDrawerGameId(""); setDrawerVisible(false); @@ -157,6 +160,11 @@ function App() { return capitalize ? value.charAt(0).toUpperCase() + value.slice(1) : value; }; const getGame = (gameId) => games.find((item) => item.id === gameId); + // La page courante propose le tiroir : un jeu connu (sa toolbox liée), ou Sokko TCG quand le jeu est ouvert (une toolbox au choix). + const routeToolboxTargetId = getRouteToolboxTargetId(route); + const shellToolboxTargetId = routeToolboxTargetId === CARDS_TOOLBOX_TARGET_ID ? (cardsConfig.enabled ? routeToolboxTargetId : "") : getGame(routeToolboxTargetId) ? routeToolboxTargetId : ""; + const drawerToolboxId = getDrawerToolboxId(drawerGameId, store.links, cardsToolboxId, store.toolboxes); + const cardsDrawer = drawerGameId === CARDS_TOOLBOX_TARGET_ID; const getToolboxGameId = (toolbox) => Object.entries(store.links).find(([, toolboxId]) => toolboxId === toolbox?.id)?.[0] || ""; const getToolboxGame = (toolbox) => getGame(getToolboxGameId(toolbox)); @@ -177,9 +185,8 @@ function App() { useToolboxAlerts({ toolboxes: store.toolboxes, moduleData: store.moduleData, - links: store.links, route, - drawerGameId: drawerVisible ? drawerGameId : "", + drawerToolboxId: drawerVisible ? drawerToolboxId : "", normalizeTimerData, normalizeCalendarData, textContent: siteContent?.toolboxes?.modules, @@ -223,7 +230,7 @@ function App() { diff --git a/website/src/styles/overlays/_drawers.scss b/website/src/styles/overlays/_drawers.scss index 1f405d5..ebd5d8a 100644 --- a/website/src/styles/overlays/_drawers.scss +++ b/website/src/styles/overlays/_drawers.scss @@ -71,6 +71,98 @@ body.is-resizing-drawer * { gap: var(--space-4); } +/* Tiroir de Sokko TCG : une bande par toolbox. L'illustration occupe une large part de la bande (bandeau 2:1 comme les + couvertures de jeu, jusqu'à leur taille native de 240 × 120), puis le nom et le jeu lié. */ +.drawer-toolbox-chooser { + display: grid; + gap: var(--space-4); +} + +.drawer-toolbox-chooser h2 { + font-size: var(--font-size-md); +} + +.drawer-toolbox-chooser-list { + display: grid; + gap: var(--space-3); + margin: 0; + padding: 0; + list-style: none; +} + +.drawer-toolbox-chooser-row button { + min-height: 0; + gap: var(--space-4); + padding: var(--space-2); + cursor: pointer; +} + +.drawer-toolbox-chooser-row button:focus-visible { + outline: 2px solid var(--color-accent-gold); + outline-offset: -2px; +} + +.drawer-toolbox-chooser-cover { + display: grid; + flex: 0 0 min(240px, 42%); + aspect-ratio: 2 / 1; + overflow: hidden; + place-items: center; + border-radius: var(--radius-sm); + background: var(--gradient-nebula); +} + +.drawer-toolbox-chooser-cover img { + width: 100%; + height: 100%; + object-fit: cover; + transition: transform 0.2s ease; +} + +.drawer-toolbox-chooser-row:hover .drawer-toolbox-chooser-cover[data-shape="image"] img { + transform: scale(1.04); +} + +.drawer-toolbox-chooser-cover[data-shape="icon"] img { + width: 40%; + height: 70%; + object-fit: contain; +} + +.drawer-toolbox-chooser-text { + display: grid; + min-width: 0; + gap: var(--space-1); + text-align: left; +} + +.drawer-toolbox-chooser-text strong, +.drawer-toolbox-chooser-text small { + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} + +.drawer-toolbox-chooser-text strong { + font-size: var(--font-size-lg); +} + +.drawer-toolbox-chooser-text small { + color: var(--color-text-muted); + font-size: var(--font-size-sm); + font-weight: 700; +} + +@media (prefers-reduced-motion: reduce) { + .drawer-toolbox-chooser-cover img { + transition: none; + } +} + +.drawer-toolbox-chooser-create { + justify-self: start; +} + .drawer-link-existing h2 { font-size: var(--font-size-md); }