sokko-g/website/src/features/cards/useCardsConfig.js
Shinuwa 34b412d968 Give Sokko TCG's interface files headers that explain their role, callers and pitfalls
Document the page, API client, offline cache, card renderer, quest pages and
admin dashboard: how stale responses are ignored, where the CSRF token lives,
which requests are idempotent and what the admin checks really protect. Fix
the Broken Mirror headers that still described two levels instead of three,
and the cards README that still described the stale-response bug as open.

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

27 lines
1.3 KiB
JavaScript

/**
* @file Lit une fois `GET /api/cards/config` : TCG activé ou non, connexion Discord ou de développement disponible,
* catalogue public et contact de confidentialité.
*
* Utilisé par : main.jsx, qui transmet la configuration aux pages (menu, CardsPage, À propos).
* Attention : chaque visite du site lit cette route, même hors du TCG ; `replaceCatalog` remplace le catalogue
* après une modification d'administration, sans relire la configuration.
*/
import { useCallback, useEffect, useState } from "react";
import { loadCardsConfig } from "./cardsApi.js";
export function useCardsConfig() {
const [config, setConfig] = useState({ loading: true, enabled: false, devAuth: false, catalog: null, error: "" });
useEffect(() => {
let active = true;
loadCardsConfig()
.then((value) => { if (active) setConfig({ loading: false, error: "", ...value }); })
.catch((error) => { if (active) setConfig({ loading: false, enabled: false, devAuth: false, catalog: null, error: error.message }); });
return () => { active = false; };
}, []);
// Remplace le catalogue publié après une modification admin, sans recharger la configuration.
const replaceCatalog = useCallback((catalog) => {
if (catalog) setConfig((current) => ({ ...current, catalog }));
}, []);
return { ...config, replaceCatalog };
}