Skip to content

Commit

Permalink
Send int ids
Browse files Browse the repository at this point in the history
  • Loading branch information
junhoyeo committed Aug 20, 2023
1 parent f25e64e commit 73a6315
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# travel.finance

Backend: https://github.com/inevitable-dao/travel-finance-backend
22 changes: 15 additions & 7 deletions src/cards/CardUpgradePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,23 @@ const CardUpgradePage: NextPage = () => {
const [newCard, setNewCard] = useState<CardItem>();

const router = useRouter();
const targetCardId = router.query.baseCardId;
const targetCardId = parseInt((router.query.baseCardId as string) || '');

const targetCard = useMemo(() => {
if (!targetCardId) {
return null;
}
return cards.filter((card) => card.id == targetCardId)[0];
return cards.filter(
(card) => card.id.toString() == targetCardId.toString(),
)[0];
}, [cards, targetCardId]);

const renderedInventory = useMemo(() => {
// if targetCard is available, remove it from inventory
if (targetCard) {
return cards.filter((card) => card.id !== targetCard.id);
return cards.filter(
(card) => card.id.toString() !== targetCard.id.toString(),
);
}
return cards;
}, [cards, targetCard]);
Expand All @@ -67,7 +71,7 @@ const CardUpgradePage: NextPage = () => {
'https://stevejkang.jp.ngrok.io/cards/upgrade',
{
targetCardId,
sourceCardsId: selectedSacrificeIds,
sourceCardsId: selectedSacrificeIds.map((v) => parseInt(v)),
},
{
headers: {
Expand Down Expand Up @@ -140,18 +144,22 @@ const CardUpgradePage: NextPage = () => {
<div className="flex gap-3">
<Checkbox
id={`card-${card.id}`}
checked={selectedSacrificeIds.includes(card.id)}
checked={selectedSacrificeIds.includes(
card.id.toString(),
)}
onCheckedChange={() =>
setSelectedSacrificeIds((prev) => {
if (prev.includes(card.id)) {
return prev.filter((id) => id !== card.id);
return prev.filter(
(id) => id.toString() !== card.id.toString(),
);
}

// MAX source length is 2!
if (prev.length >= 2) {
return prev;
}
return [...prev, card.id];
return [...prev, card.id.toString()];
})
}
/>
Expand Down

0 comments on commit 73a6315

Please sign in to comment.