Recycle duplicates in bulk up to a chosen rarity, never mythics
The collection page asks how far the bulk recycling goes (Common by default) and its preview follows that choice, so duplicates kept for later uses are not lost with the rest. Mythic duplicates are only recycled one by one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
79fdf2a9a8
commit
c7f951920e
10 changed files with 63 additions and 29 deletions
|
|
@ -1,6 +1,7 @@
|
|||
// Rôle : affiche l'album, ses progressions, ses filtres, le recyclage des doublons et le détail des éditions.
|
||||
import { useMemo, useState } from "react";
|
||||
import { Icon } from "../../components/Icon.jsx";
|
||||
import { SelectDropdown } from "../../components/SelectDropdown.jsx";
|
||||
import { Tooltip } from "../../components/Tooltip.jsx";
|
||||
import { ActiveFilterBadges } from "../games/ActiveFilterBadges.jsx";
|
||||
import { ConfirmModal } from "../../components/ToolboxModals.jsx";
|
||||
|
|
@ -24,6 +25,8 @@ export function CollectionPanel({ catalog, state, runMutation, busy, headingCont
|
|||
const [selected, setSelected] = useState(null);
|
||||
const [confirmingRecycle, setConfirmingRecycle] = useState(false);
|
||||
const [recycleNotice, setRecycleNotice] = useState("");
|
||||
// Rareté maximale du recyclage en masse : les communes seules par défaut, pour ne pas jeter les doublons utiles à un Éveil.
|
||||
const [maxRarity, setMaxRarity] = useState("common");
|
||||
const owned = useMemo(() => readCollection(state), [state]);
|
||||
const { quantities } = owned;
|
||||
const cards = useMemo(() => new Map(catalog.cards.map((card) => [card.id, card])), [catalog.cards]);
|
||||
|
|
@ -54,7 +57,7 @@ export function CollectionPanel({ catalog, state, runMutation, busy, headingCont
|
|||
|
||||
async function recycleAll() {
|
||||
setRecycleNotice("");
|
||||
const result = await runMutation(() => recycleDuplicates());
|
||||
const result = await runMutation(() => recycleDuplicates(null, maxRarity));
|
||||
if (!result?.recycled) return;
|
||||
setRecycleNotice(`${result.recycled.count > 1 ? `${result.recycled.count} doublons recyclés` : "1 doublon recyclé"} : +${formatStardust(result.recycled.stardust)} d’étoiles.`);
|
||||
// Il ne reste plus de doublon à montrer : on revient à toute la collection.
|
||||
|
|
@ -62,6 +65,11 @@ export function CollectionPanel({ catalog, state, runMutation, busy, headingCont
|
|||
}
|
||||
|
||||
const { recycling, wallet, shop } = state;
|
||||
// Raretés recyclables en masse (sans les mythiques), dans l'ordre du catalogue, avec l'aperçu de chacune envoyé par le serveur.
|
||||
const massRarities = catalog.rarities.filter((rarity) => Object.hasOwn(recycling.byRarity ?? {}, rarity.id));
|
||||
const chosen = massRarities.slice(0, massRarities.findIndex((rarity) => rarity.id === maxRarity) + 1).map((rarity) => recycling.byRarity[rarity.id]);
|
||||
const preview = { count: chosen.reduce((total, item) => total + item.count, 0), stardust: chosen.reduce((total, item) => total + item.stardust, 0) };
|
||||
const maxRarityLabel = massRarities.find((rarity) => rarity.id === maxRarity)?.label ?? maxRarity;
|
||||
const showingDuplicates = ownership.includes("duplicates");
|
||||
const collectionOptions = collections.map((item) => ({ value: item.id, label: item.name }));
|
||||
const rarityOptions = catalog.rarities.map((item) => ({ value: item.id, label: item.label }));
|
||||
|
|
@ -77,9 +85,10 @@ export function CollectionPanel({ catalog, state, runMutation, busy, headingCont
|
|||
{recycling.count > 0 && <DashboardAside>
|
||||
<section className="nds-panel nebula-recycle-box" aria-label={content.barLabel}>
|
||||
<StardustBalance value={wallet.stardust} />
|
||||
<p><strong>{countDuplicates(recycling.count)}</strong> à recycler pour <strong>+{formatStardust(recycling.stardust)}</strong></p>
|
||||
<SelectDropdown className="nebula-recycle-box-rarity" label={content.maxRarityLabel} size="sm" value={maxRarity} options={massRarities.map((rarity) => ({ value: rarity.id, label: rarity.label }))} onChange={setMaxRarity} />
|
||||
<p><strong>{countDuplicates(preview.count)}</strong> à recycler pour <strong>+{formatStardust(preview.stardust)}</strong></p>
|
||||
<div className="nebula-recycle-box-actions">
|
||||
<button className="nds-button" data-size="sm" data-variant="primary" type="button" disabled={busy || Boolean(state.pendingOpening)} onClick={() => setConfirmingRecycle(true)}>{content.allButton}</button>
|
||||
<button className="nds-button" data-size="sm" data-variant="primary" type="button" disabled={busy || Boolean(state.pendingOpening) || !preview.count} onClick={() => setConfirmingRecycle(true)}>{content.allButton}</button>
|
||||
<button className="nds-button" data-size="sm" data-variant="secondary" type="button" onClick={() => setOwnership(showingDuplicates ? [] : ["duplicates"])}>{showingDuplicates ? content.viewAll : content.viewDuplicates}</button>
|
||||
</div>
|
||||
{state.pendingOpening && <p className="nebula-form-help">{content.pending} <a href="#/cards/packs">{content.pendingAction}</a></p>}
|
||||
|
|
@ -119,8 +128,8 @@ export function CollectionPanel({ catalog, state, runMutation, busy, headingCont
|
|||
})}</div> : <div className="nds-empty-state"><p>Aucune édition ne correspond à ces filtres.</p></div>}
|
||||
</section>
|
||||
{confirmingRecycle && <ConfirmModal
|
||||
title={`Recycler ${countDuplicates(recycling.count)} ?`}
|
||||
message={`Vous recevrez ${formatStardust(recycling.stardust)} d’étoiles. Les exemplaires recyclés disparaissent de votre collection ; un exemplaire de chaque carte est conservé et les doublons réservés par un échange ne sont pas recyclés.`}
|
||||
title={`Recycler ${countDuplicates(preview.count)} ?`}
|
||||
message={`Vous recevrez ${formatStardust(preview.stardust)} d’étoiles pour les doublons de rareté ${maxRarityLabel} ou plus commune. Les exemplaires recyclés disparaissent de votre collection ; un exemplaire de chaque carte est conservé, les doublons réservés par un échange ne sont pas recyclés et les mythiques se recyclent une par une.`}
|
||||
confirmLabel="Recycler"
|
||||
onClose={(confirmed) => { setConfirmingRecycle(false); if (confirmed) void recycleAll(); }}
|
||||
>
|
||||
|
|
|
|||
|
|
@ -65,9 +65,9 @@ export function openPack(collectionId, { purchased = false } = {}) {
|
|||
return request("/openings", { method: "POST", headers: { "Idempotency-Key": requestKey }, body: JSON.stringify({ collectionId, purchased }) });
|
||||
}
|
||||
|
||||
// Sans `editionId`, recycle tous les doublons ; avec, un seul exemplaire de cette variation.
|
||||
export function recycleDuplicates(editionId = null) {
|
||||
return request("/recycle", { method: "POST", body: JSON.stringify({ editionId }) });
|
||||
// Sans `editionId`, recycle en masse les doublons des communes jusqu'à `maxRarity` ; avec, un seul exemplaire de cette variation.
|
||||
export function recycleDuplicates(editionId = null, maxRarity = "legendary") {
|
||||
return request("/recycle", { method: "POST", body: JSON.stringify(editionId ? { editionId } : { maxRarity }) });
|
||||
}
|
||||
|
||||
export function buyShopPack() {
|
||||
|
|
|
|||
|
|
@ -1069,6 +1069,7 @@ main:has(.nebula-dashboard) { overflow-x: clip; }
|
|||
.nebula-shop-buy .nebula-stardust { color: inherit; font-size: inherit; }
|
||||
.nds-panel.nebula-recycle-box { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-4); padding: var(--space-3) var(--space-4); }
|
||||
.nebula-recycle-box p { margin: 0; color: var(--color-text-secondary); font-size: var(--font-size-sm); }
|
||||
.nebula-recycle-box .nebula-recycle-box-rarity { display: flex; align-items: center; gap: var(--space-2); color: var(--color-text-secondary); font-size: var(--font-size-sm); white-space: nowrap; }
|
||||
.nebula-recycle-box .nebula-stardust { font-size: var(--font-size-xl); }
|
||||
.nebula-recycle-box-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-left: auto; }
|
||||
/* En colonne, sous le menu : les encarts s'empilent ; en demi-écran, ils restent des bandeaux sous le menu horizontal. */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue