Show a full reserve count on the Sokko TCG menu icon and remaining openings while opening a pack
A gold count now sits on the Sokko TCG menu icon while the opening reserve is full, so players notice it from any page. A light reserve route keeps it up to date outside the game, and the game page updates it with every state it gets. The opening stage also lists the remaining openings, apart for the automatic recharge and for openings bought one at a time, since the sidebar reserve is hidden there. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
2231bf05e1
commit
498e171bc3
14 changed files with 186 additions and 4 deletions
|
|
@ -583,6 +583,7 @@ Sidebar :
|
||||||
- icones SVG pour Accueil, Toolboxes et Jeux ;
|
- icones SVG pour Accueil, Toolboxes et Jeux ;
|
||||||
- navigation active en violet soft ;
|
- navigation active en violet soft ;
|
||||||
- le logo controller garde le gradient de l'ancien badge et une rotation au hover.
|
- le logo controller garde le gradient de l'ancien badge et une rotation au hover.
|
||||||
|
- quand la réserve d'ouvertures Sokko TCG est pleine, l'icône Sokko TCG porte en haut à droite une pastille or `nav-icon-count` avec le solde, détourée de la couleur de la sidebar ; le nom accessible et l'infobulle compacte le précisent. L'icône étant un masque, la pastille est posée à côté dans `nav-icon-slot`. Hors de la page de jeu, la route légère `GET /api/cards/reserve` la tient à jour (chargement, retour sur l'onglet, échéance de recharge) ; sur la page, chaque état serveur reçu la remplace aussitôt.
|
||||||
- `sidebar[data-variant="compact"]` réduit la navigation à 72 px jusqu'à `1024px`, ainsi que lorsqu'un panneau toolbox latéral est ouvert en fenêtre large : la manette conserve sa rotation au hover, les trois entrées principales et les trois raccourcis secondaires utilisent `Tooltip`, puis l’encart inférieur contient uniquement les actions globales exporter/importer empilées avec leurs propres infobulles.
|
- `sidebar[data-variant="compact"]` réduit la navigation à 72 px jusqu'à `1024px`, ainsi que lorsqu'un panneau toolbox latéral est ouvert en fenêtre large : la manette conserve sa rotation au hover, les trois entrées principales et les trois raccourcis secondaires utilisent `Tooltip`, puis l’encart inférieur contient uniquement les actions globales exporter/importer empilées avec leurs propres infobulles.
|
||||||
|
|
||||||
Le nom de marque affiche `Sokko` en blanc et `G` en dore. Au hover, `Sokko` anime vers le dore de droite a gauche puis revient au hover out.
|
Le nom de marque affiche `Sokko` en blanc et `G` en dore. Au hover, `Sokko` anime vers le dore de droite a gauche puis revient au hover out.
|
||||||
|
|
@ -1195,7 +1196,9 @@ seulement si la largeur manque), puis un `nds-panel` compact « Probabilités »
|
||||||
(les taux et la garantie du paquet offert s'il y en a). « Retour » ramène à la liste
|
(les taux et la garantie du paquet offert s'il y en a). « Retour » ramène à la liste
|
||||||
une fois toutes les cartes révélées ; à côté, un bouton primaire rouvre directement la
|
une fois toutes les cartes révélées ; à côté, un bouton primaire rouvre directement la
|
||||||
même collection tant qu'il reste une ouverture, sauf après un paquet offert ou de la
|
même collection tant qu'il reste une ouverture, sauf après un paquet offert ou de la
|
||||||
boutique, qui n'en consomment pas.
|
boutique, qui n'en consomment pas. Sous le titre, une ligne discrète « Ouvertures
|
||||||
|
restantes » sépare la recharge auto des ouvertures achetées à l'unité, puisque le menu
|
||||||
|
latéral et sa réserve sont masqués pendant l'ouverture.
|
||||||
|
|
||||||
Chaque collection fournit un dos illustré WebP au ratio 5:7 sous
|
Chaque collection fournit un dos illustré WebP au ratio 5:7 sous
|
||||||
`static/img/cards/<collectionId>/back.webp`; le composant conserve le nom en
|
`static/img/cards/<collectionId>/back.webp`; le composant conserve le nom en
|
||||||
|
|
|
||||||
|
|
@ -1613,6 +1613,11 @@ test("a player chains packs of the same collection while openings remain", async
|
||||||
await page.getByRole("button", { name: "Ouvrir ce paquet : Genèse Astrale", exact: true }).click();
|
await page.getByRole("button", { name: "Ouvrir ce paquet : Genèse Astrale", exact: true }).click();
|
||||||
await expect(revealAll).toBeVisible();
|
await expect(revealAll).toBeVisible();
|
||||||
await expect(openAnother).toHaveCount(0);
|
await expect(openAnother).toHaveCount(0);
|
||||||
|
// L'étape rappelle ce qu'il reste à ouvrir, en séparant la recharge automatique des ouvertures achetées.
|
||||||
|
const balances = await page.evaluate(async () => (await globalThis.fetch("/api/cards/state")).json().then((state) => [state.recharge.openingsBalance, state.wallet.purchasedOpenings]));
|
||||||
|
const remaining = page.getByRole("definition");
|
||||||
|
await expect(page.getByRole("term")).toHaveText(["Recharge auto", "À l’unité"]);
|
||||||
|
await expect(remaining).toHaveText(balances.map(String));
|
||||||
await revealAll.click();
|
await revealAll.click();
|
||||||
await expect(openAnother).toBeEnabled();
|
await expect(openAnother).toBeEnabled();
|
||||||
await expect.poll(pendingCollection).toBeNull();
|
await expect.poll(pendingCollection).toBeNull();
|
||||||
|
|
@ -1634,6 +1639,7 @@ test("a player chains packs of the same collection while openings remain", async
|
||||||
const openRequest = page.waitForRequest((request) => request.method() === "POST" && request.url().endsWith("/api/cards/openings"));
|
const openRequest = page.waitForRequest((request) => request.method() === "POST" && request.url().endsWith("/api/cards/openings"));
|
||||||
await revealAll.click();
|
await revealAll.click();
|
||||||
await expect(openAnother).toBeEnabled();
|
await expect(openAnother).toBeEnabled();
|
||||||
|
await expect(remaining).toHaveText(["0", "1"]);
|
||||||
await openAnother.click();
|
await openAnother.click();
|
||||||
expect((await openRequest).postDataJSON()).toEqual({ collectionId: "astral-genesis", purchased: true });
|
expect((await openRequest).postDataJSON()).toEqual({ collectionId: "astral-genesis", purchased: true });
|
||||||
await expect(page.getByRole("alert")).toContainText("aucune ouverture achetée");
|
await expect(page.getByRole("alert")).toContainText("aucune ouverture achetée");
|
||||||
|
|
@ -1650,3 +1656,35 @@ test("a player chains packs of the same collection while openings remain", async
|
||||||
await expect(back).toBeEnabled();
|
await expect(back).toBeEnabled();
|
||||||
await expect(openAnother).toHaveCount(0);
|
await expect(openAnother).toHaveCount(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("the Sokko TCG menu entry shows a count while the opening reserve is full", async ({ page }) => {
|
||||||
|
const cardsLink = page.getByRole("navigation", { name: "Navigation principale" }).getByRole("link", { name: /^Sokko TCG/ });
|
||||||
|
const count = cardsLink.locator(".nav-icon-count");
|
||||||
|
// Visiteur sans compte : aucune pastille.
|
||||||
|
await page.goto("/#/toolboxes");
|
||||||
|
await expect(cardsLink).toHaveAccessibleName("Sokko TCG");
|
||||||
|
await expect(count).toHaveCount(0);
|
||||||
|
|
||||||
|
await page.goto("/#/cards");
|
||||||
|
await page.getByRole("button", { name: "Version développement", exact: true }).click();
|
||||||
|
await expect(page.getByRole("heading", { name: "Sokko TCG", exact: true })).toBeVisible();
|
||||||
|
// Le compte de développement garde une réserve juste sous le maximum : la route est simulée pleine.
|
||||||
|
await page.route("**/api/cards/reserve", (route) => route.fulfill({ json: { recharge: { openingsBalance: 5, rechargeAnchor: null, nextOpeningAt: null } } }));
|
||||||
|
await page.goto("/#/toolboxes");
|
||||||
|
await page.reload();
|
||||||
|
await expect(count).toHaveText("5");
|
||||||
|
await expect(cardsLink).toHaveAccessibleName("Sokko TCG (réserve d’ouvertures pleine)");
|
||||||
|
const [icon, badge] = await Promise.all([cardsLink.locator(".nav-icon").boundingBox(), count.boundingBox()]);
|
||||||
|
expect(badge.x).toBeGreaterThan(icon.x + icon.width / 2);
|
||||||
|
expect(badge.y).toBeLessThan(icon.y + icon.height / 2);
|
||||||
|
// En sidebar compacte, la pastille reste sur l'icône seule.
|
||||||
|
await page.setViewportSize({ width: 900, height: 800 });
|
||||||
|
await expect(count).toBeVisible();
|
||||||
|
await page.setViewportSize({ width: 1280, height: 720 });
|
||||||
|
|
||||||
|
// Sur la page de jeu, l'état réel (réserve non pleine) remplace aussitôt la valeur relue par le menu.
|
||||||
|
await page.getByRole("navigation", { name: "Navigation principale" }).getByRole("link", { name: /^Sokko TCG/ }).click();
|
||||||
|
await expect(page.locator(".nebula-opening-reserve")).toBeVisible();
|
||||||
|
await expect(count).toHaveCount(0);
|
||||||
|
await expect(cardsLink).toHaveAccessibleName("Sokko TCG");
|
||||||
|
});
|
||||||
|
|
|
||||||
|
|
@ -278,6 +278,12 @@ export function createCardsApiHandler({
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Lue par le menu sur toutes les pages : un visiteur sans compte reçoit une réserve vide plutôt qu'une erreur.
|
||||||
|
if (req.method === "GET" && url.pathname === "/api/cards/reserve") {
|
||||||
|
json(res, 200, { recharge: session ? service.getReserve(session.player.id) : null });
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (!session) throw Object.assign(new Error("Connectez-vous pour accéder à votre collection."), { status: 401, code: "AUTH_REQUIRED" });
|
if (!session) throw Object.assign(new Error("Connectez-vous pour accéder à votre collection."), { status: 401, code: "AUTH_REQUIRED" });
|
||||||
if (req.method !== "GET") {
|
if (req.method !== "GET") {
|
||||||
const origin = req.headers.origin;
|
const origin = req.headers.origin;
|
||||||
|
|
|
||||||
|
|
@ -329,6 +329,11 @@ export class CardsService {
|
||||||
return recharge;
|
return recharge;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Réserve rechargeable seule, pour la pastille du menu : bien plus légère que l'état complet.
|
||||||
|
getReserve(playerId) {
|
||||||
|
return this.database.transaction(() => this.refreshRecharge(playerId));
|
||||||
|
}
|
||||||
|
|
||||||
// Carte affichable à partir d'une édition (catalogue publié).
|
// Carte affichable à partir d'une édition (catalogue publié).
|
||||||
cardEntry(editionId, extra = {}) {
|
cardEntry(editionId, extra = {}) {
|
||||||
const edition = this.index.editions.get(editionId);
|
const edition = this.index.editions.get(editionId);
|
||||||
|
|
|
||||||
|
|
@ -88,6 +88,7 @@ export function validateSiteContent(site) {
|
||||||
"navigation.toolboxes",
|
"navigation.toolboxes",
|
||||||
"navigation.games",
|
"navigation.games",
|
||||||
"navigation.cards",
|
"navigation.cards",
|
||||||
|
"navigation.cardsReserveFull",
|
||||||
"navigation.library",
|
"navigation.library",
|
||||||
"navigation.about",
|
"navigation.about",
|
||||||
"sidebar.badge",
|
"sidebar.badge",
|
||||||
|
|
@ -218,6 +219,9 @@ export function validateSiteContent(site) {
|
||||||
"cards.packs.probabilities",
|
"cards.packs.probabilities",
|
||||||
"cards.packs.back",
|
"cards.packs.back",
|
||||||
"cards.packs.openAnother",
|
"cards.packs.openAnother",
|
||||||
|
"cards.packs.remainingLabel",
|
||||||
|
"cards.packs.remainingReserve",
|
||||||
|
"cards.packs.remainingPurchased",
|
||||||
"cards.packs.newBadge",
|
"cards.packs.newBadge",
|
||||||
"cards.packs.shopShare",
|
"cards.packs.shopShare",
|
||||||
"cards.shop.packDescription",
|
"cards.shop.packDescription",
|
||||||
|
|
|
||||||
|
|
@ -359,3 +359,20 @@ test("cookies carry the __Host- prefix over HTTPS and only the prefixed session
|
||||||
assert.equal((await call(handler, { path: "/api/cards/session", headers: { cookie: `sokkog_cards_session=${token}` } })).json.authenticated, false);
|
assert.equal((await call(handler, { path: "/api/cards/session", headers: { cookie: `sokkog_cards_session=${token}` } })).json.authenticated, false);
|
||||||
assert.equal((await call(handler, { path: "/api/cards/session", headers: { cookie: `__Host-sokkog_cards_session=${token}` } })).json.authenticated, true);
|
assert.equal((await call(handler, { path: "/api/cards/session", headers: { cookie: `__Host-sokkog_cards_session=${token}` } })).json.authenticated, true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("the reserve route answers visitors without an account and returns the player's recharge", async (t) => {
|
||||||
|
const handler = createCardsApiHandler({ projectRoot: resolve("."), enabled: true, devAuth: true, databasePath: ":memory:", env: { NODE_ENV: "test" }, random: () => 0 });
|
||||||
|
t.after(() => handler.close());
|
||||||
|
|
||||||
|
const anonymous = await call(handler, { path: "/api/cards/reserve" });
|
||||||
|
assert.equal(anonymous.status, 200);
|
||||||
|
assert.deepEqual(anonymous.json, { recharge: null });
|
||||||
|
|
||||||
|
const login = await call(handler, { method: "POST", path: "/api/cards/auth/dev", body: {} });
|
||||||
|
const cookie = login.headers["set-cookie"].split(";")[0];
|
||||||
|
const reserve = await call(handler, { path: "/api/cards/reserve", headers: { cookie } });
|
||||||
|
const state = await call(handler, { path: "/api/cards/state", headers: { cookie } });
|
||||||
|
assert.equal(reserve.status, 200);
|
||||||
|
assert.equal(reserve.json.recharge.openingsBalance, state.json.recharge.openingsBalance);
|
||||||
|
assert.equal(reserve.json.recharge.nextOpeningAt, state.json.recharge.nextOpeningAt);
|
||||||
|
});
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
"toolboxes": "Toolboxes",
|
"toolboxes": "Toolboxes",
|
||||||
"games": "Jeux",
|
"games": "Jeux",
|
||||||
"cards": "Sokko TCG",
|
"cards": "Sokko TCG",
|
||||||
|
"cardsReserveFull": "réserve d’ouvertures pleine",
|
||||||
"library": "Librairie",
|
"library": "Librairie",
|
||||||
"about": "C'est quoi Sokko G ?"
|
"about": "C'est quoi Sokko G ?"
|
||||||
},
|
},
|
||||||
|
|
@ -201,6 +202,9 @@
|
||||||
"probabilities": "Probabilités",
|
"probabilities": "Probabilités",
|
||||||
"back": "Retour",
|
"back": "Retour",
|
||||||
"openAnother": "Ouvrir un autre paquet de la même collection",
|
"openAnother": "Ouvrir un autre paquet de la même collection",
|
||||||
|
"remainingLabel": "Ouvertures restantes",
|
||||||
|
"remainingReserve": "Recharge auto",
|
||||||
|
"remainingPurchased": "À l’unité",
|
||||||
"newBadge": "New",
|
"newBadge": "New",
|
||||||
"shopShare": "des légendaires et mythiques tirées viennent de",
|
"shopShare": "des légendaires et mythiques tirées viennent de",
|
||||||
"purchasedLabel": "Ouvertures achetées",
|
"purchasedLabel": "Ouvertures achetées",
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
// Rôle : structure le layout global avec sidebar, topbar, navigation et contenu.
|
// Rôle : structure le layout global avec sidebar, topbar, navigation et contenu.
|
||||||
import { useEffect, useRef } from "react";
|
import { useEffect, useRef } from "react";
|
||||||
|
import { useFullCardsReserve } from "../features/cards/cardsReserve.js";
|
||||||
import { Icon } from "./Icon.jsx";
|
import { Icon } from "./Icon.jsx";
|
||||||
import { ImportButton } from "./ImportButton.jsx";
|
import { ImportButton } from "./ImportButton.jsx";
|
||||||
import { Tooltip } from "./Tooltip.jsx";
|
import { Tooltip } from "./Tooltip.jsx";
|
||||||
|
|
@ -41,6 +42,9 @@ export function Shell({ route, content, games, drawerGameId = "", drawerVisible
|
||||||
}
|
}
|
||||||
}, [compactGameLayout, compactToolboxVisible]);
|
}, [compactGameLayout, compactToolboxVisible]);
|
||||||
|
|
||||||
|
const fullCardsReserve = useFullCardsReserve(cardsEnabled);
|
||||||
|
const cardsLabel = fullCardsReserve ? `${content.navigation.cards} (${content.navigation.cardsReserveFull})` : content.navigation.cards;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={`app-shell ${compactSidebar ? "sidebar-compact" : ""} ${!compactGameLayout && toolboxOpen ? "toolbox-drawer-open" : ""} ${compactToolboxVisible ? "compact-toolbox-visible" : ""}`}>
|
<div className={`app-shell ${compactSidebar ? "sidebar-compact" : ""} ${!compactGameLayout && toolboxOpen ? "toolbox-drawer-open" : ""} ${compactToolboxVisible ? "compact-toolbox-visible" : ""}`}>
|
||||||
<aside className="sidebar" data-variant={compactSidebar ? "compact" : undefined}>
|
<aside className="sidebar" data-variant={compactSidebar ? "compact" : undefined}>
|
||||||
|
|
@ -52,7 +56,7 @@ export function Shell({ route, content, games, drawerGameId = "", drawerVisible
|
||||||
<Tooltip as="a" className={`nav-item ${route === "/" ? "active" : ""}`} content={compactSidebar ? content.navigation.home : ""} position="right" href="#/" aria-label={content.navigation.home}><span className="nav-icon nav-icon-home" aria-hidden="true" /><strong>{content.navigation.home}</strong></Tooltip>
|
<Tooltip as="a" className={`nav-item ${route === "/" ? "active" : ""}`} content={compactSidebar ? content.navigation.home : ""} position="right" href="#/" aria-label={content.navigation.home}><span className="nav-icon nav-icon-home" aria-hidden="true" /><strong>{content.navigation.home}</strong></Tooltip>
|
||||||
<Tooltip as="a" className={`nav-item ${route.startsWith("/games") ? "active" : ""}`} content={compactSidebar ? content.navigation.games : ""} position="right" href="#/games" aria-label={content.navigation.games}><span className="nav-icon nav-icon-controller" aria-hidden="true" /><strong>{content.navigation.games}</strong></Tooltip>
|
<Tooltip as="a" className={`nav-item ${route.startsWith("/games") ? "active" : ""}`} content={compactSidebar ? content.navigation.games : ""} position="right" href="#/games" aria-label={content.navigation.games}><span className="nav-icon nav-icon-controller" aria-hidden="true" /><strong>{content.navigation.games}</strong></Tooltip>
|
||||||
<Tooltip as="a" className={`nav-item ${route.startsWith("/toolboxes") || route.startsWith("/toolbox") ? "active" : ""}`} content={compactSidebar ? content.navigation.toolboxes : ""} position="right" href="#/toolboxes" aria-label={content.navigation.toolboxes}><span className="nav-icon nav-icon-toolbox" aria-hidden="true" /><strong>{content.navigation.toolboxes}</strong></Tooltip>
|
<Tooltip as="a" className={`nav-item ${route.startsWith("/toolboxes") || route.startsWith("/toolbox") ? "active" : ""}`} content={compactSidebar ? content.navigation.toolboxes : ""} position="right" href="#/toolboxes" aria-label={content.navigation.toolboxes}><span className="nav-icon nav-icon-toolbox" aria-hidden="true" /><strong>{content.navigation.toolboxes}</strong></Tooltip>
|
||||||
{cardsEnabled && <Tooltip as="a" className={`nav-item ${route.startsWith("/cards") ? "active" : ""}`} content={compactSidebar ? content.navigation.cards : ""} position="right" href="#/cards" aria-label={content.navigation.cards}><span className="nav-icon nav-icon-cards" aria-hidden="true" /><strong>{content.navigation.cards}</strong></Tooltip>}
|
{cardsEnabled && <Tooltip as="a" className={`nav-item ${route.startsWith("/cards") ? "active" : ""}`} content={compactSidebar ? cardsLabel : ""} position="right" href="#/cards" aria-label={cardsLabel}><span className="nav-icon-slot" aria-hidden="true"><span className="nav-icon nav-icon-cards" />{fullCardsReserve && <span className="nav-icon-count">{fullCardsReserve}</span>}</span><strong>{content.navigation.cards}</strong></Tooltip>}
|
||||||
</nav>
|
</nav>
|
||||||
<div className="sidebar-mascot" aria-hidden="true">
|
<div className="sidebar-mascot" aria-hidden="true">
|
||||||
<img src="/static/img/dragon-sidebar.webp" alt="" />
|
<img src="/static/img/dragon-sidebar.webp" alt="" />
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ import { CardsHomePanel } from "./CardsHomePanel.jsx";
|
||||||
import { CollectionPanel } from "./CollectionPanel.jsx";
|
import { CollectionPanel } from "./CollectionPanel.jsx";
|
||||||
import { HistoryPanel } from "./HistoryPanel.jsx";
|
import { HistoryPanel } from "./HistoryPanel.jsx";
|
||||||
import { PackPanel } from "./PackPanel.jsx";
|
import { PackPanel } from "./PackPanel.jsx";
|
||||||
|
import { publishCardsReserve } from "./cardsReserve.js";
|
||||||
import { PrivacyNotice } from "./PrivacyNotice.jsx";
|
import { PrivacyNotice } from "./PrivacyNotice.jsx";
|
||||||
import { ShopPanel } from "./ShopPanel.jsx";
|
import { ShopPanel } from "./ShopPanel.jsx";
|
||||||
import { TransfersPanel } from "./TransfersPanel.jsx";
|
import { TransfersPanel } from "./TransfersPanel.jsx";
|
||||||
|
|
@ -99,6 +100,12 @@ export function CardsPage({ siteContent, cardsConfig, playerSection = "", adminM
|
||||||
if (status !== "loading") clearDiscordAuthFailure();
|
if (status !== "loading") clearDiscordAuthFailure();
|
||||||
}, [status]);
|
}, [status]);
|
||||||
|
|
||||||
|
// La pastille du menu suit chaque état reçu, sans attendre sa propre relecture.
|
||||||
|
useEffect(() => {
|
||||||
|
if (status === "anonymous") publishCardsReserve(null);
|
||||||
|
else if (status === "ready" && !offline && state?.recharge) publishCardsReserve(state.recharge);
|
||||||
|
}, [offline, state?.recharge, status]);
|
||||||
|
|
||||||
// Le panneau s'ouvre sous le login, parfois hors de l'écran.
|
// Le panneau s'ouvre sous le login, parfois hors de l'écran.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (privacyOpen) privacyPanelRef.current?.scrollIntoView({ block: "nearest" });
|
if (privacyOpen) privacyPanelRef.current?.scrollIntoView({ block: "nearest" });
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ export function PackPanel({ catalog, state, runMutation, busy, content, reserveC
|
||||||
busy={busy}
|
busy={busy}
|
||||||
content={content}
|
content={content}
|
||||||
shopShare={state.shop.shopPackShare}
|
shopShare={state.shop.shopPackShare}
|
||||||
|
remaining={{ reserve: state.recharge.openingsBalance, purchased: state.wallet.purchasedOpenings }}
|
||||||
onComplete={async () => {
|
onComplete={async () => {
|
||||||
setCompletedOpening(opening);
|
setCompletedOpening(opening);
|
||||||
return runMutation(() => completeOpening(opening.id));
|
return runMutation(() => completeOpening(opening.id));
|
||||||
|
|
@ -124,7 +125,7 @@ function OpeningOdds({ catalog, opening, collection, content, shopShare }) {
|
||||||
</section>;
|
</section>;
|
||||||
}
|
}
|
||||||
|
|
||||||
function OpeningStage({ catalog, opening, onComplete, onDismiss, onOpenAnother, focusOnMountRef, busy, content, shopShare }) {
|
function OpeningStage({ catalog, opening, onComplete, onDismiss, onOpenAnother, focusOnMountRef, remaining, busy, content, shopShare }) {
|
||||||
const [revealed, setRevealed] = useState(new Set());
|
const [revealed, setRevealed] = useState(new Set());
|
||||||
const [finishedReveals, setFinishedReveals] = useState(new Set());
|
const [finishedReveals, setFinishedReveals] = useState(new Set());
|
||||||
const [completed, setCompleted] = useState(false);
|
const [completed, setCompleted] = useState(false);
|
||||||
|
|
@ -160,7 +161,14 @@ function OpeningStage({ catalog, opening, onComplete, onDismiss, onOpenAnother,
|
||||||
}
|
}
|
||||||
|
|
||||||
return <section className="nebula-opening-stage" aria-labelledby="nebula-opening-title">
|
return <section className="nebula-opening-stage" aria-labelledby="nebula-opening-title">
|
||||||
<div className="nds-section-heading nebula-section-heading"><div><p className="eyebrow">Paquet attribué</p><h2 id="nebula-opening-title">Révélez vos trois cartes</h2></div>
|
<div className="nds-section-heading nebula-section-heading"><div><p className="eyebrow">Paquet attribué</p><h2 id="nebula-opening-title">Révélez vos trois cartes</h2>
|
||||||
|
<div className="nebula-opening-remaining"><span>{content.remainingLabel} :</span>
|
||||||
|
<dl aria-label={content.remainingLabel}>
|
||||||
|
<div><dt>{content.remainingReserve}</dt><dd>{remaining.reserve}</dd></div>
|
||||||
|
<div><dt>{content.remainingPurchased}</dt><dd>{remaining.purchased}</dd></div>
|
||||||
|
</dl>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
{!allStarted && <button ref={revealAllRef} className="nds-button" data-size="sm" data-variant="secondary" type="button" onClick={() => setRevealed(new Set(opening.cards.map((card) => card.id)))}>Tout révéler</button>}
|
{!allStarted && <button ref={revealAllRef} className="nds-button" data-size="sm" data-variant="secondary" type="button" onClick={() => setRevealed(new Set(opening.cards.map((card) => card.id)))}>Tout révéler</button>}
|
||||||
{allRevealed && <div className="nds-toolbar">
|
{allRevealed && <div className="nds-toolbar">
|
||||||
<button className="nds-button" data-size="sm" data-variant="secondary" type="button" disabled={busy} onClick={finish}>{content.back}</button>
|
<button className="nds-button" data-size="sm" data-variant="secondary" type="button" disabled={busy} onClick={finish}>{content.back}</button>
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,10 @@ export async function loadCardsSession() {
|
||||||
return session;
|
return session;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function loadCardsReserve() {
|
||||||
|
return request("/reserve");
|
||||||
|
}
|
||||||
|
|
||||||
export function loadCardsState() {
|
export function loadCardsState() {
|
||||||
return request("/state");
|
return request("/state");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
54
website/src/features/cards/cardsReserve.js
Normal file
54
website/src/features/cards/cardsReserve.js
Normal file
|
|
@ -0,0 +1,54 @@
|
||||||
|
// Rôle : partage la réserve d'ouvertures Sokko TCG entre la page de jeu et la pastille du menu.
|
||||||
|
// La page publie chaque état serveur reçu ; hors de la page, la route légère `/reserve` le relit.
|
||||||
|
import { useEffect, useSyncExternalStore } from "react";
|
||||||
|
import { loadCardsReserve } from "./cardsApi.js";
|
||||||
|
|
||||||
|
let reserve = null;
|
||||||
|
const listeners = new Set();
|
||||||
|
const subscribe = (listener) => {
|
||||||
|
listeners.add(listener);
|
||||||
|
return () => listeners.delete(listener);
|
||||||
|
};
|
||||||
|
const snapshot = () => reserve;
|
||||||
|
|
||||||
|
// `recharge` vient de l'état serveur ; `null` quand personne n'est connecté.
|
||||||
|
export function publishCardsReserve(recharge) {
|
||||||
|
const next = recharge ? { openingsBalance: recharge.openingsBalance, nextOpeningAt: recharge.nextOpeningAt } : null;
|
||||||
|
if (next?.openingsBalance === reserve?.openingsBalance && next?.nextOpeningAt === reserve?.nextOpeningAt) return;
|
||||||
|
reserve = next;
|
||||||
|
for (const listener of listeners) listener();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function refreshReserve() {
|
||||||
|
if (globalThis.document.visibilityState === "hidden") return;
|
||||||
|
try {
|
||||||
|
publishCardsReserve((await loadCardsReserve()).recharge);
|
||||||
|
} catch {
|
||||||
|
// Hors connexion, la pastille garde la dernière réserve connue.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Renvoie le solde quand la réserve est pleine, sinon `null` : une réserve pleine n'a plus d'échéance de recharge.
|
||||||
|
export function useFullCardsReserve(enabled) {
|
||||||
|
const current = useSyncExternalStore(subscribe, snapshot);
|
||||||
|
const nextOpeningAt = current?.nextOpeningAt;
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!enabled) return undefined;
|
||||||
|
void refreshReserve();
|
||||||
|
window.addEventListener("focus", refreshReserve);
|
||||||
|
globalThis.document.addEventListener("visibilitychange", refreshReserve);
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener("focus", refreshReserve);
|
||||||
|
globalThis.document.removeEventListener("visibilitychange", refreshReserve);
|
||||||
|
};
|
||||||
|
}, [enabled]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!enabled || !nextOpeningAt) return undefined;
|
||||||
|
const timeout = window.setTimeout(refreshReserve, Math.max(0, nextOpeningAt - Date.now()) + 250);
|
||||||
|
return () => window.clearTimeout(timeout);
|
||||||
|
}, [enabled, nextOpeningAt]);
|
||||||
|
|
||||||
|
return enabled && current && current.nextOpeningAt == null && current.openingsBalance > 0 ? current.openingsBalance : null;
|
||||||
|
}
|
||||||
|
|
@ -108,6 +108,10 @@
|
||||||
.nebula-opening-stage { display: grid; width: min(100%, 1000px); margin-inline: auto; gap: var(--space-4); }
|
.nebula-opening-stage { display: grid; width: min(100%, 1000px); margin-inline: auto; gap: var(--space-4); }
|
||||||
.nebula-opening-stage > .nds-section-heading.nebula-section-heading { margin-bottom: 0; }
|
.nebula-opening-stage > .nds-section-heading.nebula-section-heading { margin-bottom: 0; }
|
||||||
.nebula-opening-cards { display: grid; grid-template-columns: repeat(3, minmax(0, 300px)); justify-content: center; align-items: center; gap: clamp(12px, 2vw, 24px); min-height: 368px; padding: var(--space-4); border: 1px solid var(--color-border); border-radius: var(--radius-xl); background: radial-gradient(ellipse at center, rgba(139, 92, 246, 0.16), transparent 62%), rgba(5, 7, 17, 0.55); }
|
.nebula-opening-cards { display: grid; grid-template-columns: repeat(3, minmax(0, 300px)); justify-content: center; align-items: center; gap: clamp(12px, 2vw, 24px); min-height: 368px; padding: var(--space-4); border: 1px solid var(--color-border); border-radius: var(--radius-xl); background: radial-gradient(ellipse at center, rgba(139, 92, 246, 0.16), transparent 62%), rgba(5, 7, 17, 0.55); }
|
||||||
|
.nebula-opening-remaining { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--space-1) var(--space-3); margin-top: var(--space-2); color: var(--color-text-muted); font-size: var(--font-size-sm); }
|
||||||
|
.nebula-opening-remaining dl { display: flex; flex-wrap: wrap; gap: var(--space-1) var(--space-3); margin: 0; }
|
||||||
|
.nebula-opening-remaining dl > div { display: flex; gap: 6px; }
|
||||||
|
.nebula-opening-remaining dd { margin: 0; color: var(--color-text-primary); font-weight: 700; }
|
||||||
.nds-panel.nebula-opening-odds { display: grid; gap: var(--space-2); padding: var(--space-3) var(--space-4); }
|
.nds-panel.nebula-opening-odds { display: grid; gap: var(--space-2); padding: var(--space-3) var(--space-4); }
|
||||||
.nebula-opening-odds :is(h3, p) { margin: 0; }
|
.nebula-opening-odds :is(h3, p) { margin: 0; }
|
||||||
.nebula-opening-odds h3 { font-size: var(--font-size-sm); }
|
.nebula-opening-odds h3 { font-size: var(--font-size-sm); }
|
||||||
|
|
|
||||||
|
|
@ -116,6 +116,30 @@
|
||||||
-webkit-mask-size: 20px 20px;
|
-webkit-mask-size: 20px 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Le pictogramme est un masque : la pastille vit à côté de lui, dans un conteneur positionné. */
|
||||||
|
.nav-icon-slot {
|
||||||
|
position: relative;
|
||||||
|
display: block;
|
||||||
|
flex: 0 0 auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-icon-count {
|
||||||
|
position: absolute;
|
||||||
|
top: -6px;
|
||||||
|
right: -8px;
|
||||||
|
min-width: 17px;
|
||||||
|
height: 17px;
|
||||||
|
padding: 0 4px;
|
||||||
|
border-radius: 999px;
|
||||||
|
background: var(--color-accent-gold);
|
||||||
|
box-shadow: 0 0 0 2px var(--color-bg-sidebar);
|
||||||
|
color: var(--color-text-inverse);
|
||||||
|
font-size: 11px;
|
||||||
|
font-weight: 800;
|
||||||
|
line-height: 17px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
.nav-icon-home {
|
.nav-icon-home {
|
||||||
mask-image: url("/static/icons/home.svg");
|
mask-image: url("/static/icons/home.svg");
|
||||||
-webkit-mask-image: url("/static/icons/home.svg");
|
-webkit-mask-image: url("/static/icons/home.svg");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue