Skip to content

Commit 11640d8

Browse files
authored
now showing all cards with images (#52)
1 parent 45cda81 commit 11640d8

File tree

11 files changed

+25721
-27541
lines changed

11 files changed

+25721
-27541
lines changed

cards/A1.json

Lines changed: 0 additions & 12874 deletions
This file was deleted.

cards/A1a.json

Lines changed: 0 additions & 3803 deletions
This file was deleted.

cards/A2.json

Lines changed: 0 additions & 9279 deletions
This file was deleted.

cards/P-A.json

Lines changed: 0 additions & 1524 deletions
This file was deleted.

frontend/assets/cards/A1.json

Lines changed: 12006 additions & 0 deletions
Large diffs are not rendered by default.

frontend/assets/cards/A1a.json

Lines changed: 3564 additions & 0 deletions
Large diffs are not rendered by default.

frontend/assets/cards/A2.json

Lines changed: 8670 additions & 0 deletions
Large diffs are not rendered by default.

frontend/assets/cards/P-A.json

Lines changed: 1428 additions & 0 deletions
Large diffs are not rendered by default.

frontend/src/components/Cards.tsx

Lines changed: 40 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,107 +1,91 @@
1-
import { ID, type Models } from "appwrite";
2-
import { type FC, useEffect, useState } from "react";
3-
import { COLLECTION_ID, DATABASE_ID, getDatabase } from "../lib/Auth.ts";
4-
import type { CollectionRow } from "../types";
5-
import A1 from "../../../cards/A1.json";
6-
import type { Card as CardType } from "../types";
1+
import type { CollectionRow } from '@/types'
2+
import { ID, type Models } from 'appwrite'
3+
import { type FC, useEffect, useState } from 'react'
4+
import A1 from '../../assets/cards/A1.json'
5+
import { COLLECTION_ID, DATABASE_ID, getDatabase } from '../lib/Auth.ts'
6+
import type { Card as CardType } from '../types'
77

88
interface Props {
9-
user: Models.User<Models.Preferences>;
9+
user: Models.User<Models.Preferences>
1010
}
1111

1212
export const Cards: FC<Props> = ({ user }) => {
13-
const [ownedCards, setOwnedCards] = useState<CollectionRow[]>([]);
13+
const [ownedCards, setOwnedCards] = useState<CollectionRow[]>([])
1414

1515
useEffect(() => {
16-
fetchCollection();
17-
}, []);
16+
fetchCollection()
17+
}, [])
1818

1919
const fetchCollection = async () => {
20-
const db = await getDatabase();
21-
const { documents } = await db.listDocuments(DATABASE_ID, COLLECTION_ID);
22-
console.log("documents", documents);
23-
setOwnedCards(documents as unknown as CollectionRow[]);
24-
};
20+
const db = await getDatabase()
21+
const { documents } = await db.listDocuments(DATABASE_ID, COLLECTION_ID)
22+
console.log('documents', documents)
23+
setOwnedCards(documents as unknown as CollectionRow[])
24+
}
2525

2626
const updateCardCount = async (cardId: string, increment: number) => {
27-
console.log(`${cardId} button clicked`);
28-
const db = await getDatabase();
29-
const ownedCard = ownedCards.find((c) => c.card_id === cardId);
27+
console.log(`${cardId} button clicked`)
28+
const db = await getDatabase()
29+
const ownedCard = ownedCards.find((c) => c.card_id === cardId)
3030

3131
if (ownedCard) {
32-
console.log("updating", ownedCard);
33-
ownedCard.amount_owned = Math.max(0, ownedCard.amount_owned + increment);
34-
setOwnedCards([...ownedCards]);
32+
console.log('updating', ownedCard)
33+
ownedCard.amount_owned = Math.max(0, ownedCard.amount_owned + increment)
34+
setOwnedCards([...ownedCards])
3535
await db.updateDocument(DATABASE_ID, COLLECTION_ID, ownedCard.$id, {
3636
amount_owned: ownedCard.amount_owned,
37-
});
38-
await fetchCollection();
37+
})
38+
await fetchCollection()
3939
} else if (!ownedCard && increment > 0) {
40-
console.log("adding new card", cardId);
40+
console.log('adding new card', cardId)
4141
await db.createDocument(DATABASE_ID, COLLECTION_ID, ID.unique(), {
4242
email: user.email,
4343
card_id: cardId,
4444
amount_owned: increment,
45-
});
46-
await fetchCollection();
45+
})
46+
await fetchCollection()
4747
}
48-
};
48+
}
4949

50-
const A1_Cards: CardType[] = A1 as unknown as CardType[];
50+
const A1_Cards: CardType[] = A1 as unknown as CardType[]
5151

5252
const Card = ({ cardId }: { cardId: string }) => {
53-
const Card_info = A1_Cards.find((c) => c.id === cardId);
53+
const Card_info = A1_Cards.find((c) => c.id === cardId)
5454
return (
5555
<div className="flex flex-col items-center gap-y-4 w-fit border p-4 rounded-lg shadow-md hover:shadow-lg transition duration-200 group">
56-
<img
57-
className="w-40 rounded-lg object-cover transform group-hover:scale-105 transition duration-200"
58-
src={Card_info?.image}
59-
alt={Card_info?.name}
60-
/>
56+
<img className="w-40 rounded-lg object-cover transform group-hover:scale-105 transition duration-200" src={Card_info?.image} alt={Card_info?.name} />
6157
<div className="flex items-center gap-x-4 mt-2">
6258
<button
6359
type="button"
6460
onClick={() => updateCardCount(cardId, -1)}
6561
className="flex items-center justify-center w-8 h-8 rounded-full bg-red-500 text-white hover:bg-red-400 transition duration-200 focus:outline-none"
6662
>
67-
<svg
68-
className="w-4 h-4"
69-
viewBox="0 0 20 20"
70-
fill="currentColor"
71-
aria-hidden="true"
72-
>
63+
<svg className="w-4 h-4" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
7364
<path d="M5 10a.75.75 0 0 1 .75-.75h8.5a.75.75 0 0 1 0 1.5h-8.5A.75.75 0 0 1 5 10z" />
7465
</svg>
7566
</button>
76-
<span className="text-lg font-semibold">
77-
{ownedCards.find((c) => c.card_id === cardId)?.amount_owned || 0}
78-
</span>
67+
<span className="text-lg font-semibold">{ownedCards.find((c) => c.card_id === cardId)?.amount_owned || 0}</span>
7968
<button
8069
type="button"
8170
onClick={() => updateCardCount(cardId, 1)}
8271
className="flex items-center justify-center w-8 h-8 rounded-full bg-green-500 text-white hover:bg-green-400 transition duration-200 focus:outline-none"
8372
>
84-
<svg
85-
className="w-4 h-4"
86-
viewBox="0 0 20 20"
87-
fill="currentColor"
88-
aria-hidden="true"
89-
>
73+
<svg className="w-4 h-4" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
9074
<path d="M10.75 4.75a.75.75 0 0 0-1.5 0v4.5h-4.5a.75.75 0 0 0 0 1.5h4.5v4.5a.75.75 0 0 0 1.5 0v-4.5h4.5a.75.75 0 0 0 0-1.5h-4.5v-4.5Z" />
9175
</svg>
9276
</button>
9377
</div>
9478
</div>
95-
);
96-
};
79+
)
80+
}
9781

9882
return (
9983
<ul className="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-4 justify-center">
100-
{A1_Cards.map((cardId) => (
101-
<li className="mx-auto">
102-
<Card cardId={cardId.id} />
84+
{A1_Cards.map((card) => (
85+
<li key={card.id} className="mx-auto">
86+
<Card cardId={card.id} />
10387
</li>
10488
))}
10589
</ul>
106-
);
107-
};
90+
)
91+
}

frontend/src/types/index.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ export interface Card {
1818
damage: string
1919
effect: string
2020
}[]
21-
ability: {
22-
name: string
23-
effect: string
24-
} | string
21+
ability:
22+
| {
23+
name: string
24+
effect: string
25+
}
26+
| string
2527
weakness: string
2628
retreat: string
2729
rarity: string
@@ -41,4 +43,3 @@ export interface Card {
4143
}
4244
crafting_cost: number
4345
}
44-

0 commit comments

Comments
 (0)