sokko-g/website/src/features/games/aniimo/AniimoPage.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

80 lines
6.4 KiB
JavaScript

/**
* @file Assemble l'accueil Aniimo, ses guides et la grille filtrable de ses variantes.
*/
import { useMemo } from "react";
import { CopyChecklistItemsButton } from "../CopyChecklistItemsButton.jsx";
import { GuideChecklistPageControls } from "../GuideChecklistControls.jsx";
import { useGuideChecklist } from "../useGuideChecklist.js";
import { Icon } from "../../../components/Icon.jsx";
import { GameBreadcrumb } from "../GameBreadcrumb.jsx";
import { AniimoCard } from "./AniimoCard.jsx";
import { AniimoFilters } from "./AniimoFilters.jsx";
import { AniimoLists } from "./AniimoLists.jsx";
import { AniimoElements } from "./AniimoElements.jsx";
import { getAniimoStatsMax, aniimoLabel, filterAniimoVariants, groupAniimoVariants } from "./utils.js";
function AniimoListing({ game, aniimo, filters, setFilters, content }) {
const active = filters.aniimo;
const statsMax = useMemo(() => getAniimoStatsMax(aniimo.variants), [aniimo.variants]);
const checklist = useGuideChecklist("aniimo/aniimos");
const filtered = useMemo(() => filterAniimoVariants(aniimo.variants, active), [aniimo.variants, active]);
const visible = filtered.filter((variant) => checklist.isVisible(variant.key));
const groups = useMemo(() => groupAniimoVariants(visible), [visible]);
const totalAniimos = useMemo(() => new Set(aniimo.variants.map((variant) => variant.aniimoUid)).size, [aniimo.variants]);
const t = (key) => aniimoLabel(aniimo.translations, key);
const cards = active.grouped ? groups : visible.map((variant) => [variant]);
const update = (next) => setFilters((current) => ({ ...current, aniimo: next }));
return <>
<section className="page-heading game-heading">
<div>
<GameBreadcrumb game={game} />
<div className="game-title-row">
<h1>{content.title}</h1>
<span className="results-count aniimo-results-count" role="status"><span data-copy-target={active.grouped || undefined}>{groups.length} / {totalAniimos} {content.title}</span>{" · "}<span data-copy-target={!active.grouped || undefined}>{visible.length} / {aniimo.variants.length} {content.variants.toLowerCase()}</span></span>
<CopyChecklistItemsButton
labels={active.grouped ? groups.map(([variant]) => t(variant.name)) : visible.map((variant) => `${t(variant.name)} — ${t(variant.form)}`)}
title={active.grouped ? content.copyChecklist : content.copyVariantsChecklist}
filteredResults
checklistTitle={active.grouped ? content.title : content.variantsChecklistTitle}
linkedToolbox={checklist.toolbox}
content={checklist.content}
onCreateChecklist={checklist.createChecklistFromResults}
/>
</div>
<p>{content.description}</p>
</div>
<div className="actions game-heading-actions">
<GuideChecklistPageControls checklist={checklist} />
<button className="nds-switch" type="button" aria-pressed={active.grouped} onClick={() => update({ ...active, grouped: !active.grouped })}><Icon name="multiple" /><span>{content.groupVariants}</span><i aria-hidden="true" /></button>
</div>
</section>
<section className="game-layout aniimo-layout">
<aside className="game-filters"><AniimoFilters filters={active} onChange={update} options={aniimo.filterOptions} t={t} content={content} /></aside>
<section className="game-results" aria-label={content.results}>
{cards.length ? <div className="game-grid aniimo-grid">{cards.map((variants) => <AniimoCard key={active.grouped ? variants[0].aniimoUid : variants[0].key} variants={variants} t={t} content={content} checklist={checklist} statsMax={statsMax} />)}</div> : <div className="empty nds-empty-state"><h2>{content.emptyTitle}</h2><p>{content.emptyText}</p></div>}
</section>
</section>
</>;
}
export function AniimoPage({ category, game, aniimo, filters, setFilters, siteContent, links, actions }) {
const content = siteContent.aniimo;
if (category === "lists") {
if (aniimo.loading || !aniimo.loaded) return <section className="empty nds-empty-state" aria-busy="true"><h1>{content.loading}</h1></section>;
if (aniimo.error) return <section className="empty nds-empty-state" role="alert"><h1>{content.error}</h1><p>{aniimo.error}</p><button className="nds-button" data-size="sm" data-variant="primary" type="button" onClick={aniimo.retry}>{siteContent.gamesPage.retryLabel}</button></section>;
return <AniimoLists game={game} aniimo={aniimo} linkedToolboxId={links?.[game.id] || ""} actions={actions} />;
}
if (!["aniimos", "elements"].includes(category)) return <>
<section className="game-hero" style={{ "--game-hero-image": `url("${game.images.heroBg}")` }}><div><p className="eyebrow">{game.eyebrow}</p><h1>{game.title}</h1><p>{game.summary}</p></div></section>
<section className="game-home-grid">
<a className="feature game-home-card aniimo-home-card" href="#/games/aniimo/aniimos"><img src={game.images.aniimosCover} alt="" /><strong>{content.title}</strong><span>{content.homeDescription}</span></a>
<a className="feature game-home-card" href="#/games/aniimo/elements"><span className="game-home-card-icon" aria-hidden="true"><span className="aniimo-elements-home-icon"><img src="/static/img/aniimo/fire.webp" alt="" /><img src="/static/img/aniimo/water.webp" alt="" /><img src="/static/img/aniimo/grass.webp" alt="" /></span></span><strong>{content.elementCalculator.title}</strong><span>{content.elementCalculator.homeDescription}</span></a>
<a className="feature game-home-card" href="#/games/aniimo/lists"><span className="game-home-card-icon" aria-hidden="true"><span className="module-icon-svg module-icon-checklist" /></span><strong>Listes</strong><span>Données copiables au format checklist pour préparer vos suivis.</span></a>
</section>
</>;
if (aniimo.loading || !aniimo.loaded) return <section className="empty nds-empty-state" aria-busy="true"><h1>{content.loading}</h1></section>;
if (aniimo.error) return <section className="empty nds-empty-state" role="alert"><h1>{content.error}</h1><p>{aniimo.error}</p><button className="nds-button" data-size="sm" data-variant="primary" type="button" onClick={aniimo.retry}>{siteContent.gamesPage.retryLabel}</button></section>;
if (category === "elements") return <AniimoElements game={game} aniimo={aniimo} content={content.elementCalculator} />;
return <AniimoListing game={game} aniimo={aniimo} filters={filters} setFilters={setFilters} content={content} />;
}