diff --git a/src/components/PrintingRow/PrintingRow.jsx b/src/components/PrintingRow/PrintingRow.jsx index 06a0fbb..1787ddf 100644 --- a/src/components/PrintingRow/PrintingRow.jsx +++ b/src/components/PrintingRow/PrintingRow.jsx @@ -1,24 +1,21 @@ -import React, { useContext, useState } from 'react'; +import React, { useContext } from 'react'; import { CardContext } from '../../context/CardContext'; import { updateCardAmount } from '../../services/api'; function PrintingRow({ card_id, printing, cols, zebra }) { const { ownedAmounts, updateAmount } = useContext(CardContext); - const [loading, setLoading] = useState(false); const key = `${printing.set_id}-${printing.rarity_id}`; const current = ownedAmounts[card_id]?.[key] ?? printing.amount_owned ?? 0; const save = async (next) => { if (card_id == null || printing.set_id == null || printing.rarity_id == null) return; - setLoading(true); + updateAmount(card_id, key, next); try { await updateCardAmount(card_id, printing.set_id, printing.rarity_id, next); - updateAmount(card_id, key, next); } catch (err) { console.error('Failed to update amount', err); - } finally { - setLoading(false); + updateAmount(card_id, key, current); } }; @@ -26,7 +23,7 @@ function PrintingRow({ card_id, printing, cols, zebra }) {
@@ -35,19 +32,11 @@ function PrintingRow({ card_id, printing, cols, zebra }) { {printing.set_name} {printing.rarity_name}
- + {current} - +
); diff --git a/src/pages/SetsPage.jsx b/src/pages/SetsPage.jsx index 1520ef8..46d52f4 100644 --- a/src/pages/SetsPage.jsx +++ b/src/pages/SetsPage.jsx @@ -44,11 +44,12 @@ function SetCardRow({ card, zebra }) { const current = ownedAmounts[card.id]?.[key] ?? card.amount_owned ?? 0; const save = async (next) => { + updateAmount(card.id, key, next); try { await updateCardAmount(card.id, card.set_id, card.rarity_id, next); - updateAmount(card.id, key, next); } catch (err) { console.error('Failed to update amount', err); + updateAmount(card.id, key, current); } };