Add Cards: re-adding a card moves its Just added row to the top
Previously it got a second row, and the older one kept a stale count. Closes #30 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -110,7 +110,10 @@ export function CardEntry() {
|
|||||||
const loc = intoDeck ? "" : location.trim();
|
const loc = intoDeck ? "" : location.trim();
|
||||||
if (loc) await api.setLocation(card.oracle_id, loc);
|
if (loc) await api.setLocation(card.oracle_id, loc);
|
||||||
if (deck) await sendToDeck(deck, card.oracle_id, entry);
|
if (deck) await sendToDeck(deck, card.oracle_id, entry);
|
||||||
setRecent((r) => [{ card, qty, location: loc, deck }, ...r].slice(0, 12));
|
// Re-adding a card moves it to the top rather than listing it twice.
|
||||||
|
setRecent((r) =>
|
||||||
|
[{ card, qty, location: loc, deck }, ...r.filter((e) => e.card.oracle_id !== card.oracle_id)].slice(0, 12),
|
||||||
|
);
|
||||||
setQuery("");
|
setQuery("");
|
||||||
setResults([]);
|
setResults([]);
|
||||||
}
|
}
|
||||||
@@ -197,8 +200,8 @@ export function CardEntry() {
|
|||||||
<>
|
<>
|
||||||
<h2 style={{ marginTop: "var(--space-6)" }}>Just added</h2>
|
<h2 style={{ marginTop: "var(--space-6)" }}>Just added</h2>
|
||||||
<ul className="result-list">
|
<ul className="result-list">
|
||||||
{recent.map((r, i) => (
|
{recent.map((r) => (
|
||||||
<li key={i} style={{ cursor: "default" }}>
|
<li key={r.card.oracle_id} style={{ cursor: "default" }}>
|
||||||
<span className="card-name">{r.card.name}</span>
|
<span className="card-name">{r.card.name}</span>
|
||||||
{r.deck && <span className="deck-chip">→ {r.deck.name}</span>}
|
{r.deck && <span className="deck-chip">→ {r.deck.name}</span>}
|
||||||
{r.location && <span className="deck-chip">{r.location}</span>}
|
{r.location && <span className="deck-chip">{r.location}</span>}
|
||||||
|
|||||||
Reference in New Issue
Block a user