diff --git a/components/Bag/Deck/AddJson.tsx b/components/Bag/Deck/AddJson.tsx
new file mode 100644
index 0000000..47441be
--- /dev/null
+++ b/components/Bag/Deck/AddJson.tsx
@@ -0,0 +1,163 @@
+import {
+ Box,
+ Flex,
+ Text,
+ Accordion,
+ AccordionItem,
+ AccordionButton,
+ AccordionPanel,
+ AccordionIcon,
+ Textarea,
+ HStack,
+ Button,
+ FormLabel,
+ Input,
+} from "@chakra-ui/react";
+import { useState } from "react";
+import { useQuery } from "@tanstack/react-query";
+import { useLocalDeckStorage } from "@/lib/hooks";
+import { useRouter } from "next/router";
+import axios from "axios";
+
+export const AddJson = () => {
+ return (
+
+ Load a Deck from a JSON
+
+ Don't have a deck uploaded to Unmatched? You can import the raw
+ JSON
+
+
+
+ );
+};
+
+const Options = () => {
+ const { reload } = useRouter();
+ const { pushDeck } = useLocalDeckStorage();
+
+ const [json, setJson] = useState("");
+ const [url, setUrl] = useState();
+
+ const { data: isJsonValid } = useQuery(
+ ["json-check", json.length, json.substring(0, 5)],
+ async () => await jsonCheck(json),
+ );
+
+ const { data: urlData } = useQuery(
+ ["urlData"],
+ async () => await axios.get(url ?? ""),
+ {
+ enabled: !!url,
+ },
+ );
+
+ return (
+
+
+
+
+
+ Input via Text
+
+
+
+
+
+
+
+
+
+ Heads up! This won't check the JSON contents, just if
+ it's a valid json
+
+
+ {isJsonValid && (
+
+ )}
+
+
+
+
+
+
+
+
+
+ Input via URL
+
+
+
+
+
+ {urlData?.data && (
+
+ )}
+
+ setUrl(e.target.value)}
+ value={url}
+ />
+
+ {JSON.stringify(urlData?.data)}
+
+
+
+
+
+ );
+};
+
+const StatusText = (props: { text: string; isValid: boolean }) => {
+ return (
+
+
+ {props.text}
+
+ );
+};
+
+async function jsonCheck(value: string) {
+ console.log(value);
+ try {
+ JSON.parse(value);
+ return true;
+ } catch (err) {
+ return false;
+ }
+}
diff --git a/components/Bag/Deck/index.tsx b/components/Bag/Deck/index.tsx
index 7548bee..a8b16a0 100644
--- a/components/Bag/Deck/index.tsx
+++ b/components/Bag/Deck/index.tsx
@@ -1,18 +1,21 @@
import { Dispatch, SetStateAction, useState } from "react";
-import { Box, Button, Flex, Input, Text } from "@chakra-ui/react";
+import { Box, Button, Flex, Grid, HStack, Input, Text } 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 { Carousel } from "@/components/Game/game.carousel";
import { DeckImportType } from "@/components/DeckPool/deck-import.type";
import { useLocalDeckStorage } from "@/lib/hooks/useLocalStorage";
+
+import { FaStar } from "react-icons/fa";
+
import { StarterDeckContainer } from "@/components/Bag/StarterDecks";
-import { DeckSlot } from "./Slot";
import { DeckStats } from "./Stats";
-import { DeckInfo } from "./Info";
+import { AddJson } from "./AddJson";
+import { useCopyToClipboard } from "@/lib/hooks/useCopyToClipboard";
+import { toast } from "react-hot-toast";
export const BagDecks = () => {
- const { data, isLoading, setDeckId } = useUnmatchedDeck();
+ const { data, setDeckId } = useUnmatchedDeck();
const { decks, pushDeck, removeDeckbyId, totalKbLeft, setStar, star } =
useLocalDeckStorage();
@@ -23,89 +26,179 @@ export const BagDecks = () => {
<>
-
- {decks && (
- (
-
-
-
- ))}
- />
- )}
-
-
-
- {!selectedDeckId && !data && (
- <>
-
- deck.id)}
+
+
+ {decks?.map((deck) => (
+
- >
- )}
- {!selectedDeckId && data && }
+ ))}
+
{selectedDeckId && (
- deck.id === selectedDeckId)} />
+
+ deck.id === selectedDeckId)}
+ {...{
+ setSelectedDeckId,
+ selectedDeckId,
+ star,
+ setStar,
+ removeDeckbyId,
+ }}
+ />
+
+
)}
-
-
- {!selectedDeckId && data && !isLoading && }
- {decks && selectedDeckId && (
- deck.id === selectedDeckId)}
- />
+
+ {!selectedDeckId && (
+
+ {!data && (
+
+
+
+
+
+ deck.id)}
+ {...{ pushDeck }}
+ />
+
+ )}
+ {data && (
+
+
+
+
+ )}
+
+ {/* If data exists, show the cards */}
+ {data && }
+
)}
-
-
- {!selectedDeckId && data && (
+
+ >
+ );
+};
+
+const DeckListItem = ({
+ deck,
+ star,
+ setSelectedDeckId,
+ selectedDeckId,
+}: {
+ deck: DeckImportType;
+ star?: string;
+ selectedDeckId?: string;
+ setSelectedDeckId: (id: string) => void;
+}) => {
+ return (
+ setSelectedDeckId(deck.id)}
+ >
+
+ {star === deck.id && (
+
+ )}
+ {deck.name}
+
+ );
+};
+
+const Buttons = ({
+ deck,
+ selectedDeckId,
+ setSelectedDeckId,
+ removeDeckbyId,
+ setStar,
+}: {
+ deck?: DeckImportType;
+ selectedDeckId?: string;
+ setSelectedDeckId: (id?: string) => void;
+ removeDeckbyId: (id: string) => void;
+ setStar: (id: string) => void;
+}) => {
+ const [_, copy] = useCopyToClipboard();
+ return (
+
+ {selectedDeckId && (
+
+
- )}
- {selectedDeckId && (
-
-
-
-
-
- )}
-
- >
+
+
+
+
+ )}
+
+ );
+};
+
+const DeckCards = ({
+ decks,
+ selectedDeckId,
+}: {
+ decks?: DeckImportType[];
+ selectedDeckId?: string;
+}) => {
+ return (
+
+ {decks
+ ?.find((deck) => deck.id === selectedDeckId)
+ ?.deck_data?.cards?.map((card) => (
+
+
+
+ ))}
+
);
};
@@ -139,23 +232,3 @@ const UnmatchedInput = ({
>
);
};
-
-const DeckCarousel = ({
- data,
- selectedDeck,
-}: {
- data?: DeckImportType;
- selectedDeck?: DeckImportType;
-}) => {
- const deck = selectedDeck ? selectedDeck : data;
- if (!deck) return ;
- return (
- (
-
-
-
- ))}
- />
- );
-};