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>
This commit is contained in:
parent
243465720f
commit
5ce35cd7ba
193 changed files with 12159 additions and 28 deletions
94
website/src/features/cards/admin/AdminPanel.jsx
Normal file
94
website/src/features/cards/admin/AdminPanel.jsx
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
// Rôle : assemble la navigation et les sections du tableau de bord d'administration Sokko TCG.
|
||||
import { useEffect, useState } from "react";
|
||||
import { CardsAccount, CardsDashboardLayout } from "../CardsDashboard.jsx";
|
||||
import { formatRelative } from "./adminFormat.js";
|
||||
import { AdminCollections } from "./AdminCollections.jsx";
|
||||
import { AdminDistributions } from "./AdminDistributions.jsx";
|
||||
import { AdminHistory } from "./AdminHistory.jsx";
|
||||
import { AdminOverview } from "./AdminOverview.jsx";
|
||||
import { AdminShop } from "./AdminShop.jsx";
|
||||
import { AdminVisualLab } from "./AdminVisualLab.jsx";
|
||||
import { useCatalogLookup } from "./catalogLookup.js";
|
||||
import { useAdminDashboard } from "./useAdminDashboard.js";
|
||||
|
||||
// Les sections qui agissent sur le jeu, l'Atelier visuel à part (un bac à sable où rien n'est enregistré), puis le journal de ces actions.
|
||||
const ADMIN_NAVIGATION = [
|
||||
[["overview", "Vue d’ensemble"], ["collections", "Collections"], ["codes", "Codes cadeaux"], ["shop", "Boutique"]],
|
||||
[["visual-lab", "Atelier visuel"]],
|
||||
[["history", "Historique"]]
|
||||
];
|
||||
const SECTION_IDS = new Set(ADMIN_NAVIGATION.flat().map(([id]) => id));
|
||||
// Anciennes adresses conservées pour les favoris existants.
|
||||
const SECTION_ALIASES = { players: "overview", cards: "collections", catalog: "collections", packs: "collections", distributions: "codes", "mythic-styles": "visual-lab", "opening-effects": "visual-lab" };
|
||||
|
||||
function resolveAdminSection(section) {
|
||||
const resolved = SECTION_ALIASES[section] || section;
|
||||
return SECTION_IDS.has(resolved) ? resolved : "overview";
|
||||
}
|
||||
|
||||
function useNow(intervalMs) {
|
||||
const [now, setNow] = useState(() => Date.now());
|
||||
useEffect(() => {
|
||||
const timer = window.setInterval(() => setNow(Date.now()), intervalMs);
|
||||
return () => window.clearInterval(timer);
|
||||
}, [intervalMs]);
|
||||
return now;
|
||||
}
|
||||
|
||||
export function AdminPanel({ catalog, state, runMutation, busy, section, subsection = "", onCatalogChange, backLabel = "Retour au jeu", onLogout = null }) {
|
||||
const activeSection = resolveAdminSection(section);
|
||||
const lookup = useCatalogLookup(catalog);
|
||||
const { dashboard, loading, error, refresh } = useAdminDashboard();
|
||||
const now = useNow(30_000);
|
||||
|
||||
async function mutateCatalog(action) {
|
||||
const result = await runMutation(action);
|
||||
if (result?.catalog) {
|
||||
onCatalogChange?.(result.catalog);
|
||||
void refresh();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// Les campagnes vivent dans les données du tableau de bord : on les recharge après chaque modification.
|
||||
async function mutateCampaigns(action) {
|
||||
const result = await runMutation(action);
|
||||
if (result) void refresh();
|
||||
return result;
|
||||
}
|
||||
|
||||
const shared = { catalog, lookup, state, dashboard, dashboardLoading: loading, refreshDashboard: refresh, runMutation, busy, now };
|
||||
|
||||
return <section className="nebula-dashboard" aria-labelledby="nebula-admin-title">
|
||||
<header className="nds-panel nebula-admin-heading">
|
||||
<div className="nebula-admin-title">
|
||||
<span className="nebula-admin-title-icon" aria-hidden="true"><span className="ui-icon nav-icon-cards" /></span>
|
||||
<div>
|
||||
<p className="eyebrow">Sokko TCG · Administration</p>
|
||||
<h1 id="nebula-admin-title">Tableau de bord Sokko TCG</h1>
|
||||
<p className="nebula-admin-refresh">
|
||||
<span role="status">{loading ? "Actualisation…" : dashboard?.generatedAt ? `Données mises à jour ${formatRelative(dashboard.generatedAt, Math.max(now, dashboard.generatedAt))}` : "Chargement des données…"}</span>
|
||||
<button className="nds-button" data-size="xs" data-variant="secondary" type="button" disabled={loading} onClick={refresh}>Actualiser</button>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<CardsAccount player={state.player} onLogout={onLogout} />
|
||||
</header>
|
||||
{error && <p className="nds-inline-notice" data-variant="danger" role="alert">{error}</p>}
|
||||
<CardsDashboardLayout
|
||||
label="Sections de l’administration"
|
||||
groups={ADMIN_NAVIGATION}
|
||||
active={activeSection}
|
||||
hrefFor={(id) => `#/cards/admin/${id}`}
|
||||
switchLink={{ href: "#/cards", label: backLabel }}
|
||||
busy={loading}
|
||||
>
|
||||
{activeSection === "overview" && <AdminOverview {...shared} />}
|
||||
{activeSection === "collections" && <AdminCollections {...shared} mutateCatalog={mutateCatalog} collectionId={subsection} />}
|
||||
{activeSection === "visual-lab" && <AdminVisualLab catalog={catalog} lookup={lookup} />}
|
||||
{activeSection === "history" && <AdminHistory catalog={catalog} refreshedAt={dashboard?.generatedAt} />}
|
||||
{activeSection === "codes" && <AdminDistributions {...shared} mutateCampaigns={mutateCampaigns} />}
|
||||
{activeSection === "shop" && <AdminShop {...shared} refreshDashboard={refresh} />}
|
||||
</CardsDashboardLayout>
|
||||
</section>;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue