diff --git a/components/Bag/StarterDecks/index.tsx b/components/Bag/StarterDecks/index.tsx
new file mode 100644
index 0000000..abdd867
--- /dev/null
+++ b/components/Bag/StarterDecks/index.tsx
@@ -0,0 +1,39 @@
+import { DeckImportType } from "@/components/DeckPool/deck-import.type";
+import { Box, Button, Flex, Text, useDisclosure } from "@chakra-ui/react";
+import { useStarterDecks } from "./useStarterDecks";
+
+export const StarterDeckContainer = (props: {
+ pushDeck: (data: DeckImportType) => void;
+ deckIds?: string[];
+}) => {
+ const { isOpen, onOpen } = useDisclosure();
+ const results = useStarterDecks({ enabled: isOpen });
+ const hasResult = !!results.find((record) => record.status === "success");
+ return (
+
+ Don't have any decks in mind?
+ {!hasResult && (
+
+ )}
+
+ {results?.map(
+ (record) =>
+ record.data !== undefined && (
+
+ ),
+ )}
+
+
+ );
+};
diff --git a/components/Bag/StarterDecks/useStarterDecks.ts b/components/Bag/StarterDecks/useStarterDecks.ts
new file mode 100644
index 0000000..608293b
--- /dev/null
+++ b/components/Bag/StarterDecks/useStarterDecks.ts
@@ -0,0 +1,37 @@
+import { DeckImportType } from "@/components/DeckPool/deck-import.type";
+import { useQuery, useQueries } from "@tanstack/react-query";
+import axios from "axios";
+import toast from "react-hot-toast";
+
+export const useStarterDecks = (props: { enabled: boolean }) => {
+ const deckKeys = Object.keys(BACKUP_DECKS);
+ console.log({ deckKeys });
+
+ const queries = useQueries({
+ queries: deckKeys.map((id) => ({
+ queryKey: ["starter-deck", id],
+ queryFn: () => fetchDeck(BACKUP_DECKS[id as BACKUP_KEY]),
+ enabled: props.enabled,
+ })),
+ });
+
+ return queries;
+};
+
+async function fetchDeck(url: string) {
+ try {
+ const result = await axios.get(url);
+ return result.data;
+ } catch (err) {
+ console.error(err);
+ }
+}
+
+type BACKUP_KEY = keyof typeof BACKUP_DECKS;
+enum BACKUP_DECKS {
+ THRALL = "https://arweave.net/OCa_LQ9vLH7ucJqVsxPYScaVoZL7btnzaRioH7rZjdw",
+ MANDOLORIAN = "https://arweave.net/iQKZY8HNihjGO0wt6pHGxo6uD-9416-24X65WCzL68g",
+ GINGER = "https://arweave.net/5vbOUVYkn1GUIPbpZdORslk10kT--Pt4KKziQYDIqcU",
+ JOHNWICK = "https://arweave.net/z46jYDgrKBQT8bA_NqC5BJkWD6GFkWUFLKXRO8sAj_4",
+ FRANKEN = "https://arweave.net/Nh3KzSYPTVhxXzV4N0YQ9YLHhkXQxxs-2wSwj7Xr12w",
+}
diff --git a/lib/hooks/useUnmatchedDeck.ts b/lib/hooks/useUnmatchedDeck.ts
index c8cb1a9..c1ee82c 100644
--- a/lib/hooks/useUnmatchedDeck.ts
+++ b/lib/hooks/useUnmatchedDeck.ts
@@ -1,3 +1,4 @@
+import { DeckImportType } from "@/components/DeckPool/deck-import.type";
import { useQuery } from "@tanstack/react-query";
import axios from "axios";
import { useState } from "react";
@@ -8,14 +9,16 @@ export const useUnmatchedDeck = () => {
const [deckId, setDeckId] = useState();
const [deckIdDebounced] = useDebounce(deckId, 300);
const [apiUrl, setApiUrl] = useState(
- "https://unbrewed-api.vercel.app/api/unmatched-deck/"
+ "https://unbrewed-api.vercel.app/api/unmatched-deck/",
);
const { data, isLoading, error } = useQuery(
["deck", deckIdDebounced, apiUrl],
async () => {
try {
- const result = await axios.get(apiUrl + deckIdDebounced);
+ const result = await axios.get(
+ apiUrl + deckIdDebounced,
+ );
return result.data;
} catch (err) {
console.error(err);
@@ -25,7 +28,7 @@ export const useUnmatchedDeck = () => {
enabled: !!deckIdDebounced,
onSuccess: (e) => toast.success("Deck fetched!"),
onError: (e) => toast.error("Error fetching deck"),
- }
+ },
);
return {
diff --git a/pages/bag.tsx b/pages/bag.tsx
index be2a250..cb2b282 100644
--- a/pages/bag.tsx
+++ b/pages/bag.tsx
@@ -1,26 +1,22 @@
-//@ts-nocheck
-import { useState } from "react";
+import { Dispatch, SetStateAction, useState } from "react";
import {
Box,
Button,
Flex,
HStack,
Input,
- Spinner,
Tag,
Text,
+ VStack,
} from "@chakra-ui/react";
import { CardFactory } from "@/components/CardFactory/card.factory";
import { DECK_ID } from "@/lib/constants/unmatched-deckids";
import { useUnmatchedDeck } from "@/lib/hooks/useUnmatchedDeck";
-import { useRouter } from "next/router";
import { Carousel } from "@/components/Game/game.carousel";
-import {
- DeckImportDataType,
- DeckImportType,
-} from "@/components/DeckPool/deck-import.type";
+import { DeckImportType } from "@/components/DeckPool/deck-import.type";
import { useLocalDeckStorage } from "@/lib/hooks/useLocalStorage";
import Link from "next/link";
+import { StarterDeckContainer } from "@/components/Bag/StarterDecks";
const BagPage = () => {
const { data, isLoading, error, deckId, setDeckId, apiUrl, setApiUrl } =
@@ -28,12 +24,13 @@ const BagPage = () => {
const { decks, pushDeck, removeDeckbyId, totalKbLeft, setStar, star } =
useLocalDeckStorage();
+
const [selectedDeckId, setSelectedDeckId] = useState();
return (
-
+
{decks && (
{
.toUpperCase()}
id={deck?.id}
setSelectedDeck={setSelectedDeckId}
+ isSelected={selectedDeckId === deck.id}
star={star}
/>
@@ -52,13 +50,17 @@ const BagPage = () => {
/>
)}
-
- {/*
- */}
-
- {!selectedDeckId && !data && }
+ {!selectedDeckId && !data && (
+ <>
+
+ deck.id)}
+ />
+ >
+ )}
{!selectedDeckId && data && }
{selectedDeckId && (
deck.id === selectedDeckId)} />
@@ -128,7 +130,7 @@ const BagNav = () => {
);
};
-const DeckStats = ({ length, deckKb }) => {
+const DeckStats = ({ length, deckKb }: { length: number; deckKb: number }) => {
return (
{
);
};
-const DeckSlot = ({ abbrev, id, setSelectedDeck, star }) => {
+const DeckSlot = ({
+ abbrev,
+ id,
+ setSelectedDeck,
+ isSelected,
+ star,
+}: {
+ abbrev: string;
+ id: string;
+ setSelectedDeck: any;
+ star: string;
+ isSelected: boolean;
+}) => {
const isStarred = star === id;
return (
{
h="85%"
w="85%"
borderRadius={"inherit"}
- border={isStarred && "2px solid gold"}
+ border={isStarred ? "2px solid gold" : ""}
p={2}
color="antiquewhite"
justifyContent={"center"}
@@ -185,7 +199,11 @@ const DeckSlot = ({ abbrev, id, setSelectedDeck, star }) => {
);
};
-const UnmatchedInput = ({ setDeckId }) => {
+const UnmatchedInput = ({
+ setDeckId,
+}: {
+ setDeckId: Dispatch>;
+}) => {
return (
<>
@@ -212,7 +230,13 @@ const UnmatchedInput = ({ setDeckId }) => {
);
};
-const DeckCarousel = ({ data, selectedDeck }) => {
+const DeckCarousel = ({
+ data,
+ selectedDeck,
+}: {
+ data?: DeckImportType;
+ selectedDeck?: DeckImportType;
+}) => {
const deck = selectedDeck ? selectedDeck : data;
if (!deck) return ;
return (
@@ -226,7 +250,7 @@ const DeckCarousel = ({ data, selectedDeck }) => {
);
};
-const DeckInfo: DeckImportDataType = ({ data }) => {
+const DeckInfo = ({ data }: { data?: DeckImportType }) => {
if (!data) return ;
const { hero, sidekick } = data.deck_data;
return (
@@ -241,7 +265,7 @@ const DeckInfo: DeckImportDataType = ({ data }) => {
- {sidekick.quantity > 1
+ {sidekick.quantity !== null && sidekick.quantity > 1
? sidekick.quantity + "x"
: "❤️️" + sidekick.hp}
@@ -250,6 +274,9 @@ const DeckInfo: DeckImportDataType = ({ data }) => {
{sidekick.name}
+
+ {data.deck_data.hero.specialAbility}
+
);
};