sokko-g/website/src/features/cards/CardsHomePanel.jsx
Shinuwa aa8bb1ebaa Split dailyShare.js and document the shared exported functions with JSDoc
dailyShare.js held fillTemplate and formatCountdown, used across the whole TCG,
under a Daily Card name. They now live in textFormat.js at the root, and the
Daily Card helpers in daily/dailyFormat.js.

173 exported functions that other files call now explain what they return and
how they treat missing values: the server game rules, the toolbox storage chain,
the shared hooks and utilities, and the TCG display helpers. website/AGENTS.md
asks the same of new shared functions.

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

79 lines
5.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* @file Compose le tableau de bord d'accueil compact de Sokko TCG.
*/
import { useState } from "react";
import { CardDetailModal } from "./CardDetailModal.jsx";
import { DashboardAside, DashboardStat } from "./CardsDashboard.jsx";
import { DailyTip } from "./DailyTip.jsx";
import { readCollection } from "./collectionState.js";
import { NebulaCard } from "./rendering/NebulaCard.jsx";
import { OpeningReserve } from "./OpeningReserve.jsx";
import { fillTemplate } from "./textFormat.js";
import { pendingQuestCount } from "./guildQuests.js";
import { StardustBalance } from "./Currency.jsx";
// Le dragon des Veilleurs, parchemin de quête en main : l'emblème de la Guilde, propre à elle et non à l'une de ses quêtes.
const GUILD_ILLUSTRATION = "/static/img/cards/guild-veilleurs.webp";
/** Encart de la Guilde des Veilleurs, à côté du meilleur tirage : une entrée vers la Guilde, qui annonce combien de quêtes attendent sans les détailler. */
function GuildBanner({ state, content, guildContent }) {
const pending = pendingQuestCount(state);
const status = pending ? fillTemplate(content.guildPending, { count: pending, s: pending > 1 ? "s" : "", ent: pending > 1 ? "ent" : "" }) : content.guildIdle;
return <section className="nds-panel nebula-guild-banner" data-pending={pending > 0 || undefined} aria-labelledby="nebula-guild-banner-title">
<span className="nebula-guild-banner-art" aria-hidden="true"><img src={GUILD_ILLUSTRATION} alt="" /></span>
<div className="nebula-guild-banner-copy">
<h3 id="nebula-guild-banner-title">{guildContent.title}</h3>
<p>{content.guildTagline}</p>
<p className="nebula-guild-banner-status">{status}</p>
<a className="nds-button" data-size="sm" data-variant={pending ? "primary" : "secondary"} href="#/cards/guild">{content.guildAction}</a>
</div>
</section>;
}
export function CardsHomePanel({ catalog, state, runMutation, busy, content, guildContent, tipsContent, cardSheetContent, onOpenPacks }) {
const [detailOpen, setDetailOpen] = useState(false);
const collectibleCards = catalog.cards.filter((card) => catalog.editions.some((edition) => edition.cardId === card.id && !edition.promotional));
const collectibleEditions = catalog.editions.filter((edition) => !edition.promotional);
const owned = readCollection(state);
const discoveredCards = collectibleCards.filter((card) => owned.ownedCardIds.has(card.id)).length;
const discoveredEditions = collectibleEditions.filter((edition) => owned.quantities.has(edition.id)).length;
const rarest = state.rarestPull;
const rarity = rarest && catalog.rarities.find((item) => item.id === rarest.edition.rarity);
return <section className="nebula-home" aria-labelledby="nebula-home-title">
<div className="nds-section-heading nebula-home-heading">
<div><p className="eyebrow">{content.eyebrow}</p><h2 id="nebula-home-title">{content.title}</h2></div>
</div>
{state.pendingOpening && <div className="nds-inline-notice nebula-home-resume" data-variant="warning"><span>{content.resume}</span><button className="nds-button" data-size="sm" data-variant="primary" type="button" onClick={onOpenPacks}>{content.resumeAction}</button></div>}
{/* Comme sur Paquets, la réserve d'ouvertures se range sous le menu, avec un accès direct aux paquets. */}
<DashboardAside>
<OpeningReserve recharge={state.recharge} content={content} compact>
<button className="nds-button" data-size="sm" data-variant="primary" type="button" onClick={onOpenPacks}>{content.browsePacks}</button>
</OpeningReserve>
</DashboardAside>
{/* La Guilde et le meilleur tirage se partagent une rangée à parts égales, les chiffres clés suivent. */}
<div className="nebula-home-highlights">
<GuildBanner state={state} content={content} guildContent={guildContent} />
<section className="nds-panel nebula-home-rarest" aria-labelledby="nebula-home-rarest-title">
<div className="nebula-home-rarest-copy">
<p className="eyebrow">{content.rarestEyebrow}</p>
<h2 id="nebula-home-rarest-title">{content.rarestTitle}</h2>
{rarest ? <><strong>{rarest.card.name}</strong><span className="nebula-home-rarity" data-rarity={rarest.edition.rarity}>{rarity?.label}</span><time dateTime={new Date(rarest.openedAt).toISOString()}>{new Date(rarest.openedAt).toLocaleDateString("fr-FR")}</time></> : <p>{content.noPull}</p>}
</div>
{rarest && <div className="nebula-home-rarest-card"><NebulaCard catalog={catalog} entry={rarest} size="md" onSelect={() => setDetailOpen(true)} /></div>}
</section>
</div>
<section className="nebula-dashboard-stats nebula-home-stats" aria-label="Statistiques de collection">
<DashboardStat label={content.cardsDiscovered} value={<>{discoveredCards}<small> / {collectibleCards.length}</small></>} />
<DashboardStat label={content.editionsDiscovered} value={<>{discoveredEditions}<small> / {collectibleEditions.length}</small></>} />
<DashboardStat label={content.ownedCopies} value={owned.totalCopies} />
<DashboardStat label={content.packsOpened} value={state.stats?.openingsCount || 0} />
<DashboardStat label={content.stardust} value={<StardustBalance value={state.wallet.stardust} />} />
<DashboardStat label={content.recyclable} value={state.recycling.count} />
</section>
{/* Sous les chiffres clés : en 1280 × 720, l'Accueil tient encore sans défiler jusqu'à eux. */}
<DailyTip content={tipsContent} values={state.tipValues} day={state.daily?.day ?? new Date().toISOString().slice(0, 10)} />
{detailOpen && rarest && <CardDetailModal catalog={catalog} state={state} entry={rarest} content={cardSheetContent} runMutation={runMutation} busy={busy} onClose={() => setDetailOpen(false)} />}
</section>;
}