sokko-g/website/src/features/cards/HistoryPanel.jsx
Shinuwa 5ce35cd7ba Add the Sokko TCG collectible card mini-game
Add the server-backed card game: Discord login, recharging pack openings,
album, trades, gifts, stardust shop, campaign codes and its administration,
stored in SQLite and disabled in production until configured.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 17:47:35 +01:00

64 lines
4.4 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.

// Rôle : présente le journal personnel des ouvertures et de leurs cartes, des transferts, récompenses et achats en boutique.
import { formatStardust } from "./stardustFormat.js";
const EVENT_LABELS = {
pack_opened: "Paquet ouvert",
trade_created: "Échange proposé",
trade_received: "Proposition d’échange reçue",
trade_declined: "Échange refusé",
trade_joined: "Échange rejoint",
trade_completed: "Échange terminé",
trade_cancelled: "Échange annulé",
gift_created: "Don créé",
gift_joined: "Don rejoint",
gift_completed: "Don terminé",
gift_cancelled: "Don annulé",
campaign_claimed: "Code utilisé",
gift_pack_opened: "Paquet offert ouvert",
cards_recycled: "Doublons recyclés",
opening_purchased: "Ouverture achetée"
};
// Le journal garde la quantité réellement offerte : les comptes plus anciens n'ont reçu qu'une ouverture.
function eventLabel(entry) {
if (entry.type !== "welcome_opening") return EVENT_LABELS[entry.type];
const amount = entry.details.amount ?? 1;
return amount > 1 ? `${amount} ouvertures de paquets de bienvenue offertes` : "1 ouverture de paquet de bienvenue offerte";
}
// Simple référence textuelle : le journal garde l'identifiant si la carte a depuis quitté le catalogue.
function cardReference(editionId, catalog) {
const edition = catalog.editions.find((item) => item.id === editionId);
const card = edition && catalog.cards.find((item) => item.id === edition.cardId);
if (!card) return editionId;
const finishes = edition.finishIds.filter((id) => id !== "standard").map((id) => catalog.finishes.find((item) => item.id === id)?.label);
return [card.name, ...finishes].filter(Boolean).join(" · ");
}
function OpenedCards({ entry, catalog, pendingOpeningId, content }) {
const editionIds = entry.details.cards;
if (!editionIds?.length) return null;
// L'entrée existe dès l'attribution du paquet : les cartes restent cachées tant qu'elles n'ont pas été révélées.
if (entry.entityId === pendingOpeningId) return <span>{content.pendingCards}</span>;
return <ul className="nebula-history-cards" aria-label="Cartes obtenues">{editionIds.map((editionId, index) => {
const rarityId = catalog.editions.find((item) => item.id === editionId)?.rarity;
const rarity = catalog.rarities.find((item) => item.id === rarityId)?.label;
return <li key={`${editionId}-${index}`} data-rarity={rarityId}><span className="nds-badge" data-variant="neutral"><i className="nebula-history-rarity" {...(rarity ? { role: "img", "aria-label": rarity, title: rarity } : { "aria-hidden": true })} />{cardReference(editionId, catalog)}</span></li>;
})}</ul>;
}
function HistoryDetail({ entry, catalog }) {
const { details } = entry;
if (details.sent || details.received) return <span>{[details.sent && `Donnée : ${cardReference(details.sent, catalog)}`, details.received && `Reçue : ${cardReference(details.received, catalog)}`].filter(Boolean).join(" · ")}</span>;
if (entry.type === "cards_recycled") return <span>{details.count} exemplaire{details.count > 1 ? "s" : ""} · +{formatStardust(details.stardust)} d’étoiles</span>;
if (entry.type === "opening_purchased") return <span>−{formatStardust(details.price)} d’étoiles</span>;
if (!details.collectionId) return null;
const name = catalog.collections.find((item) => item.id === details.collectionId)?.name;
if (details.price) return <span>{name} · −{formatStardust(details.price)}</span>;
return <span>{details.purchased ? `${name} · ouverture achetée` : name}</span>;
}
export function HistoryPanel({ state, catalog, content }) {
return <section aria-labelledby="nebula-history-title"><div className="nds-section-heading nebula-section-heading"><div><p className="eyebrow">Journal du compte</p><h2 id="nebula-history-title">Historique</h2></div></div>
{state.history.length ? <ol className="nebula-history-list">{state.history.map((entry, index) => <li key={`${entry.entityId}-${entry.createdAt}-${index}`} className="nds-list-row"><span className="nebula-history-mark" aria-hidden="true" /><div><strong>{eventLabel(entry) || entry.type}</strong><HistoryDetail entry={entry} catalog={catalog} /><OpenedCards entry={entry} catalog={catalog} pendingOpeningId={state.pendingOpening?.id} content={content} /></div><time dateTime={new Date(entry.createdAt).toISOString()}>{new Date(entry.createdAt).toLocaleString("fr-FR")}</time></li>)}</ol> : <div className="nds-empty-state"><p>Vos premières actions apparaîtront ici.</p></div>}
</section>;
}