From d0817c7476e23df66095d3ec7eccd050cd8aea93 Mon Sep 17 00:00:00 2001 From: Syco21 Date: Sat, 16 May 2026 02:08:46 +0200 Subject: [PATCH] Group set cards by name with expandable rarity rows --- src/pages/SetsPage.jsx | 63 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 55 insertions(+), 8 deletions(-) diff --git a/src/pages/SetsPage.jsx b/src/pages/SetsPage.jsx index 14ca28f..1520ef8 100644 --- a/src/pages/SetsPage.jsx +++ b/src/pages/SetsPage.jsx @@ -54,11 +54,10 @@ function SetCardRow({ card, zebra }) { return (
- {card.name} {card.rarity_name}
@@ -69,6 +68,38 @@ function SetCardRow({ card, zebra }) { ); } +function CardGroup({ group, isExpanded, onToggle }) { + const { ownedAmounts } = useContext(CardContext); + const total = group.printings.reduce((sum, p) => { + const key = `${p.set_id ?? ''}-${p.rarity_id}`; + return sum + (ownedAmounts[group.id]?.[key] ?? p.amount_owned ?? 0); + }, 0); + + return ( + <> +
+ {group.name} +
+ {total > 0 && ×{total}} + {isExpanded ? '▲' : '▼'} +
+
+ {isExpanded && group.printings.map((p, i) => ( + + ))} + + ); +} + function SetsPage() { const [sets, setSets] = useState([]); const [loading, setLoading] = useState(true); @@ -76,6 +107,7 @@ function SetsPage() { const [setCards, setSetCards] = useState([]); const [cardsLoading, setCardsLoading] = useState(false); const [searchTerm, setSearchTerm] = useState(''); + const [expandedCardId, setExpandedCardId] = useState(null); const isMobile = useMediaQuery('(max-width: 768px)'); useEffect(() => { @@ -86,6 +118,7 @@ function SetsPage() { if (selectedSet?.id === set.id) { setSelectedSet(null); setSetCards([]); return; } setSelectedSet(set); setSetCards([]); + setExpandedCardId(null); setCardsLoading(true); fetchSetCards(set.id).then(setSetCards).catch(console.error).finally(() => setCardsLoading(false)); }; @@ -95,6 +128,15 @@ function SetsPage() { return sets.filter(s => fuzzyMatch(s.set_name, searchTerm) || fuzzyMatch(s.set_code, searchTerm)); }, [sets, searchTerm]); + const groupedCards = useMemo(() => { + const map = new Map(); + for (const card of setCards) { + if (!map.has(card.id)) map.set(card.id, { id: card.id, name: card.name, printings: [] }); + map.get(card.id).printings.push(card); + } + return [...map.values()]; + }, [setCards]); + const setDetail = selectedSet && (
@@ -109,15 +151,20 @@ function SetsPage() { : (
- CardRarityOwned + CardOwned
- {setCards.map((card, i) => ( - + {groupedCards.map(group => ( + setExpandedCardId(expandedCardId === group.id ? null : group.id)} + /> ))}
)