sokko-g/website/src/features/toolboxes/GlobalMemosTicker.jsx
Shinuwa 22b397ebfa Document Sokko G's architecture and folders, and move JavaScript file headers to JSDoc @file blocks
Add ARCHITECTURE.md (layers, flows, folder map, glossary), CONTRIBUTING.md
(setup and step-by-step recipes) and a README in each main folder, with an
index of docs/. Convert the 511 JavaScript headers from "// Rôle :" lines to
JSDoc @file blocks, define a three-level header template in website/AGENTS.md
and check the header in tests/file-headers.test.mjs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-01 09:42:13 +01:00

56 lines
2.5 KiB
JavaScript

/**
* @file 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, cardsToolboxId, toolboxes) {
const toolboxMatch = route.match(/^\/toolbox\/([^/]+)/);
if (toolboxMatch) return decodeURIComponent(toolboxMatch[1]);
return getDrawerToolboxId(getRouteToolboxTargetId(route), links, cardsToolboxId, toolboxes);
}
export function GlobalMemosTicker({ route, toolboxes, links, cardsToolboxId = "", moduleData, textContent }) {
const [nowMs, setNowMs] = useState(() => Date.now());
useEffect(() => {
const intervalId = window.setInterval(() => setNowMs(Date.now()), 60000);
return () => window.clearInterval(intervalId);
}, []);
const items = useMemo(() => {
const toolboxId = getRouteToolboxId(route, links, cardsToolboxId, toolboxes);
const toolbox = toolboxes.find((item) => item.id === toolboxId);
if (!toolbox) return [];
return toolbox.modules
.filter((module) => module.type === "memos")
.flatMap((module) => {
const data = normalizeMemosData(moduleData[moduleStorageKey(toolbox.id, module.id)]);
if (!data.tickerEnabled) return [];
const plannerLink = resolveMemosPlannerLink(data.plannerLink, toolbox.modules);
const taskItems = getPlannerTaskTickerItems({
plannerLink,
modules: toolbox.modules,
getPlannerData: (plannerId) => moduleData[moduleStorageKey(toolbox.id, plannerId)],
nowMs,
alertTemplate: textContent?.taskAlertTemplate
});
return [
...data.items.map((memo) => ({ ...memo, id: `${module.id}:${memo.id}` })),
...taskItems.map((item) => ({ ...item, id: `${module.id}:${item.id}` }))
];
});
}, [route, toolboxes, links, cardsToolboxId, moduleData, nowMs, textContent?.taskAlertTemplate]);
if (!items.length) return null;
return (
<aside className="global-memos-ticker" aria-label={textContent?.tickerLabel || "Mémos"}>
<MemosTicker items={items} label={textContent?.tickerLabel || "Mémos"} />
</aside>
);
}