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
|
|
@ -1,5 +1,6 @@
|
|||
// Rôle : structure le layout global avec sidebar, topbar, navigation et contenu.
|
||||
import { useEffect, useRef } from "react";
|
||||
import { useFullCardsReserve } from "../features/cards/cardsReserve.js";
|
||||
import { Icon } from "./Icon.jsx";
|
||||
import { ImportButton } from "./ImportButton.jsx";
|
||||
import { Tooltip } from "./Tooltip.jsx";
|
||||
|
|
@ -41,6 +42,9 @@ export function Shell({ route, content, games, drawerGameId = "", drawerVisible
|
|||
}
|
||||
}, [compactGameLayout, compactToolboxVisible]);
|
||||
|
||||
const fullCardsReserve = useFullCardsReserve(cardsEnabled);
|
||||
const cardsLabel = fullCardsReserve ? `${content.navigation.cards} (${content.navigation.cardsReserveFull})` : content.navigation.cards;
|
||||
|
||||
return (
|
||||
<div className={`app-shell ${compactSidebar ? "sidebar-compact" : ""} ${!compactGameLayout && toolboxOpen ? "toolbox-drawer-open" : ""} ${compactToolboxVisible ? "compact-toolbox-visible" : ""}`}>
|
||||
<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.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>
|
||||
{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>
|
||||
<div className="sidebar-mascot" aria-hidden="true">
|
||||
<img src="/static/img/dragon-sidebar.webp" alt="" />
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import { CardsHomePanel } from "./CardsHomePanel.jsx";
|
|||
import { CollectionPanel } from "./CollectionPanel.jsx";
|
||||
import { HistoryPanel } from "./HistoryPanel.jsx";
|
||||
import { PackPanel } from "./PackPanel.jsx";
|
||||
import { publishCardsReserve } from "./cardsReserve.js";
|
||||
import { PrivacyNotice } from "./PrivacyNotice.jsx";
|
||||
import { ShopPanel } from "./ShopPanel.jsx";
|
||||
import { TransfersPanel } from "./TransfersPanel.jsx";
|
||||
|
|
@ -99,6 +100,12 @@ export function CardsPage({ siteContent, cardsConfig, playerSection = "", adminM
|
|||
if (status !== "loading") clearDiscordAuthFailure();
|
||||
}, [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.
|
||||
useEffect(() => {
|
||||
if (privacyOpen) privacyPanelRef.current?.scrollIntoView({ block: "nearest" });
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ export function PackPanel({ catalog, state, runMutation, busy, content, reserveC
|
|||
busy={busy}
|
||||
content={content}
|
||||
shopShare={state.shop.shopPackShare}
|
||||
remaining={{ reserve: state.recharge.openingsBalance, purchased: state.wallet.purchasedOpenings }}
|
||||
onComplete={async () => {
|
||||
setCompletedOpening(opening);
|
||||
return runMutation(() => completeOpening(opening.id));
|
||||
|
|
@ -124,7 +125,7 @@ function OpeningOdds({ catalog, opening, collection, content, shopShare }) {
|
|||
</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 [finishedReveals, setFinishedReveals] = useState(new Set());
|
||||
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">
|
||||
<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>}
|
||||
{allRevealed && <div className="nds-toolbar">
|
||||
<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;
|
||||
}
|
||||
|
||||
export function loadCardsReserve() {
|
||||
return request("/reserve");
|
||||
}
|
||||
|
||||
export function loadCardsState() {
|
||||
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 > .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-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); }
|
||||
.nebula-opening-odds :is(h3, p) { margin: 0; }
|
||||
.nebula-opening-odds h3 { font-size: var(--font-size-sm); }
|
||||
|
|
|
|||
|
|
@ -116,6 +116,30 @@
|
|||
-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 {
|
||||
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