sokko-g/website/src/features/cards/ExpeditionsPanel.jsx
Shinuwa 4d05d812c5 Split the Guild administration into tabs and sell Éclats and openings by quantity in the shop
The Guild administration now has a tab per quest. The expedition settings sit behind a status band (open or close, today's activity) and four themed tabs, with units inside the fields, the default value shown, and one sticky apply bar that lists every change before confirming.

The Pont des Veilleurs leaves the expedition page and becomes the « Éclats d’étoile » shop item, priced from Administration › Boutique. Openings and Éclats are bought by quantity: a number field capped by the stardust the player actually has, and a full-width button that shows the total cost. Stardust and Éclats get their own SVG icons, aligned with the text around them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 15:39:45 +01:00

158 lines
12 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 les Expéditions, quête de la Guilde : expéditions du joueur (retour, butin) et préparation d'une expédition solo.
import { useEffect, useState } from "react";
import { addBonusDestination, claimExpedition, craftPowerCommon, recallExpedition, departExpedition, joinExpedition, leaveExpedition, loadExpeditions, startExpedition } from "./cardsApi.js";
import { CurrencyAmount } from "./Currency.jsx";
import { fillTemplate, formatCountdown } from "./dailyShare.js";
import { ExpeditionGroupCard } from "./ExpeditionGroupCard.jsx";
import { ExpeditionPlanner } from "./ExpeditionPlanner.jsx";
import { ExpeditionReport } from "./ExpeditionReport.jsx";
import { formatEclats, grimoireLabel } from "./expeditionFormat.js";
const COUNTDOWN_TICK_MS = 30_000;
// Les refus propres aux Expéditions restent dans ce panneau ; runMutation garde le reste (réseau, session).
const expeditionCall = (call) => async () => {
try {
return await call();
} catch (error) {
if (String(error.code || "").startsWith("EXPEDITION")) return { expeditionError: error };
throw error;
}
};
// Sac du Veilleur : objets rapportés ; les destinations bonus s'ouvrent ici, l'ancre et le burin depuis l'expédition et la fiche de carte.
// Atelier : 3 doublons de communes (une même commune peut compter autant de fois qu'elle a de doublons libres).
function Atelier({ catalog, state, content, busy, onCraft }) {
const [chosen, setChosen] = useState([]);
const commons = state.collection.filter((entry) => entry.spare > 0 && entry.edition?.rarity === "common");
const count = (editionId) => chosen.filter((id) => id === editionId).length;
return <div className="nebula-expedition-atelier">
<p className="nebula-form-help">{fillTemplate(content.atelierHelp, { count: chosen.length })}</p>
{commons.length ? <ul>{commons.map((entry) => <li key={entry.editionId}>
<button className="nds-button" data-size="sm" data-variant={count(entry.editionId) ? "primary" : "secondary"} type="button" disabled={busy || (chosen.length >= 3 && !count(entry.editionId))}
onClick={() => setChosen(count(entry.editionId) < entry.spare && chosen.length < 3 ? [...chosen, entry.editionId] : chosen.filter((id) => id !== entry.editionId))}>
{entry.card?.name || catalog.cards.find((card) => card.id === entry.edition?.cardId)?.name}{count(entry.editionId) ? ` ×${count(entry.editionId)}` : ""}
</button>
</li>)}</ul> : <p className="nebula-form-help">{content.atelierNoCommons}</p>}
<button className="nds-button" data-size="sm" data-variant="primary" type="button" disabled={busy || chosen.length !== 3} onClick={async () => { if (await onCraft(chosen)) setChosen([]); }}>{content.atelierAction}</button>
</div>;
}
function ItemBag({ catalog, state, view, content, busy, onBonus, onCraft }) {
const [crafting, setCrafting] = useState(false);
const { items } = view;
const used = new Set(view.destinations.map((destination) => destination.bonusSlot).filter(Boolean));
const actions = { guideStar: ["5", content.useGuideStar, 1], skyChart: ["6", content.useSkyChart, 1], fragment: ["hidden", content.useFragments, view.fragmentsForMap] };
const owned = Object.entries(items).filter(([, count]) => count > 0);
return <section className="nds-panel nebula-expedition-bag" aria-labelledby="nebula-expedition-bag-title">
<h3 id="nebula-expedition-bag-title">{content.bagTitle}</h3>
{owned.length ? <ul>{owned.map(([id, count]) => {
const action = actions[id];
return <li key={id} className="nds-list-row">
<span><strong>{content.items[id]}</strong> ×{count}<span className="nebula-form-help">{content.itemHelp[id]}</span></span>
{action && view.enabled && <button className="nds-button" data-size="sm" data-variant="secondary" type="button" disabled={busy || count < action[2] || used.has(action[0])} onClick={() => onBonus(id)}>{action[1]}</button>}
{id === "plan" && view.atelierAvailable && <button className="nds-button" data-size="sm" data-variant="secondary" type="button" aria-pressed={crafting} disabled={busy} onClick={() => setCrafting(!crafting)}>{content.atelierOpen}</button>}
{id === "plan" && crafting && <Atelier catalog={catalog} state={state} content={content} busy={busy} onCraft={async (ids) => { const done = await onCraft(ids); if (done) setCrafting(false); return done; }} />}
</li>;
})}</ul> : <p className="nebula-form-help">{content.bagEmpty}</p>}
</section>;
}
export function ExpeditionsPanel({ catalog, state, runMutation, busy, content }) {
const [view, setView] = useState(null);
const [loadError, setLoadError] = useState("");
const [reloadKey, setReloadKey] = useState(0);
const [notice, setNotice] = useState(null);
const [mode, setMode] = useState("solo");
const [now, setNow] = useState(() => Date.now());
useEffect(() => {
let active = true;
loadExpeditions()
.then((result) => { if (active) { setView(result); setLoadError(""); setNow(Date.now()); } })
.catch((error) => { if (active) setLoadError(error.message); });
return () => { active = false; };
}, [reloadKey]);
useEffect(() => {
const timer = setInterval(() => setNow(Date.now()), COUNTDOWN_TICK_MS);
return () => clearInterval(timer);
}, []);
if (loadError) return <section className="nds-empty-state" role="alert"><h2>{content.title}</h2><p>{loadError}</p></section>;
if (!view) return <section className="nds-empty-state" aria-busy="true"><h2>{content.title}</h2></section>;
const reload = () => { setNotice(null); setReloadKey((key) => key + 1); };
const handle = (result, success) => {
if (result?.expeditions) {
setView(result.expeditions);
setNow(Date.now());
setNotice(success ? { variant: "success", text: success } : null);
return true;
}
if (result?.expeditionError?.code === "EXPEDITION_DAY_EXPIRED") setNow(view.nextDayAt);
else if (result?.expeditionError) setNotice({ variant: "warning", text: result.expeditionError.message });
return false;
};
const start = async (body) => handle(await runMutation(expeditionCall(() => startExpedition(body))), body.mode === "group" ? content.groupOpened : content.started);
const claim = async (id) => handle(await runMutation(expeditionCall(() => claimExpedition(id))), content.claimed);
const join = async (id, choice) => handle(await runMutation(expeditionCall(() => joinExpedition(id, choice))), content.joined);
const leave = async (id) => handle(await runMutation(expeditionCall(() => leaveExpedition(id))), content.left);
const bonus = async (item) => handle(await runMutation(expeditionCall(() => addBonusDestination(item))), content.bonusAdded);
const craft = async (editionIds) => {
const result = await runMutation(expeditionCall(() => craftPowerCommon(editionIds)));
if (result?.crafted) setNotice({ variant: "success", text: fillTemplate(content.crafted, { card: catalog.cards.find((card) => card.id === catalog.editions.find((edition) => edition.id === result.crafted)?.cardId)?.name || "" }) });
else if (result?.expeditionError) setNotice({ variant: "warning", text: result.expeditionError.message });
return Boolean(result?.crafted);
};
const recall = async (id) => handle(await runMutation(expeditionCall(() => recallExpedition(id))), content.recalled);
const depart = async (id) => handle(await runMutation(expeditionCall(() => departExpedition(id))), content.departed);
const expired = view.enabled && now >= view.nextDayAt;
const soloActive = view.expeditions.filter((expedition) => expedition.mode === "solo" && expedition.status === "running" && !expedition.claimedAt);
const soloLimitReached = soloActive.length >= view.soloLimit;
const groupLimitReached = view.group.active >= view.group.limit;
return <section className="nebula-expeditions" aria-labelledby="nebula-expeditions-title">
<div className="nds-section-heading nebula-section-heading">
<div><p className="eyebrow">{content.eyebrow}</p><h2 id="nebula-expeditions-title">{content.title}</h2><p className="nebula-guild-intro">{content.intro}</p></div>
<div className="nebula-daily-heading-actions">
<span className="nds-badge" data-variant="gold" title={content.eclatsHelp}><CurrencyAmount kind="eclats">{fillTemplate(content.eclatsBalance, { value: formatEclats(state.wallet.eclats ?? 0) })}</CurrencyAmount></span>
<a className="nds-button" data-size="sm" data-variant="secondary" href="#/cards/guild">{content.back}</a>
</div>
</div>
<p className="nebula-form-help">{content.eclatsHelp}</p>
<ItemBag catalog={catalog} state={state} view={view} content={content} busy={busy} onBonus={bonus} onCraft={craft} />
{notice && <p className="nds-inline-notice" data-variant={notice.variant} role="status">{notice.text}</p>}
{expired && <div className="nds-inline-notice nebula-daily-expired" data-variant="warning" role="status"><span>{content.expired}</span><button className="nds-button" data-size="sm" data-variant="primary" type="button" onClick={reload}>{content.reload}</button></div>}
{view.expeditions.length > 0 && <section className="nebula-expedition-active" aria-labelledby="nebula-expedition-active-title">
<h3 id="nebula-expedition-active-title">{content.activeTitle}</h3>
<div className="nebula-expedition-reports">{view.expeditions.map((expedition) => <ExpeditionReport key={expedition.id} catalog={catalog} expedition={expedition} content={content} now={now} busy={busy} onClaim={claim} anchors={view.items.anchor} onRecall={recall} />)}</div>
</section>}
{(view.enabled || view.groups.length > 0) && <section className="nebula-expedition-active" aria-labelledby="nebula-expedition-groups-title">
<h3 id="nebula-expedition-groups-title">{content.groupsTitle}</h3>
{view.groups.length ? <div className="nebula-expedition-reports">{view.groups.map((group) => <ExpeditionGroupCard key={group.id} catalog={catalog} group={group} cards={view.cards} content={content} now={now} busy={busy} limitReached={groupLimitReached} minPlayers={view.group.minPlayers} onJoin={join} onLeave={leave} onDepart={depart} />)}</div>
: <p className="nebula-form-help">{content.groupsEmpty}</p>}
</section>}
<section className="nds-panel nebula-expedition-grimoire" aria-labelledby="nebula-expedition-grimoire-title">
<h3 id="nebula-expedition-grimoire-title">{content.grimoireTitle} <span className="nds-badge" data-variant="neutral">{fillTemplate(content.grimoireCount, { count: view.grimoire.length, s: view.grimoire.length > 1 ? "s" : "" })}</span></h3>
<p className="nebula-form-help">{content.grimoireHelp}</p>
{view.grimoire.length ? <ul className="nebula-expedition-rewards">{view.grimoire.map((entry) => <li key={entry.id} className="nds-badge" data-variant="gold">{grimoireLabel(entry.id, catalog, content)}</li>)}</ul> : <p className="nebula-form-help">{content.grimoireEmpty}</p>}
</section>
{!view.enabled ? <div className="nds-empty-state"><h3>{content.closedTitle}</h3><p>{content.closedText}</p></div>
: !expired && <>
<div className="nebula-expedition-plan-heading">
<h3>{content.planTitle}</h3>
<span className="nebula-form-help">{fillTemplate(content.nextDay, { time: formatCountdown(view.nextDayAt - now) })}</span>
</div>
<div role="group" aria-label={content.modeLabel} className="nds-toolbar">{[["solo", content.modeSolo], ["group", content.modeGroup]].map(([value, label]) => <button key={value} type="button" className="nds-button" data-size="sm" data-variant={value === mode ? "primary" : "secondary"} aria-pressed={value === mode} onClick={() => setMode(value)}>{label}</button>)}</div>
{mode === "solo" && soloLimitReached ? <p className="nds-inline-notice" data-variant="info">{content.limitReached}</p>
: mode === "group" && groupLimitReached ? <p className="nds-inline-notice" data-variant="info">{content.groupLimit}</p>
: <ExpeditionPlanner key={`${view.day}-${mode}`} catalog={catalog} view={view} mode={mode} content={content} busy={busy} onStart={start} />}
</>}
</section>;
}