From 9251a5c115d80e0c23c0607cd871e5fab1cac6d3 Mon Sep 17 00:00:00 2001 From: jollygrin Date: Fri, 29 Mar 2024 22:35:21 +0100 Subject: [PATCH 1/3] refactored to be better display of decks --- components/Bag/Deck/index.tsx | 252 +++++++++++++++++++++------------- 1 file changed, 154 insertions(+), 98 deletions(-) diff --git a/components/Bag/Deck/index.tsx b/components/Bag/Deck/index.tsx index 7548bee..65a013c 100644 --- a/components/Bag/Deck/index.tsx +++ b/components/Bag/Deck/index.tsx @@ -1,18 +1,18 @@ 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"; export const BagDecks = () => { - const { data, isLoading, setDeckId } = useUnmatchedDeck(); + const { data, setDeckId } = useUnmatchedDeck(); const { decks, pushDeck, removeDeckbyId, totalKbLeft, setStar, star } = useLocalDeckStorage(); @@ -23,89 +23,165 @@ export const BagDecks = () => { <> - - {decks && ( - ( - - - - ))} - /> - )} - - - - {!selectedDeckId && !data && ( - <> - - deck.id)} + + + {decks?.map((deck) => ( + - - )} - {!selectedDeckId && data && } + ))} + {selectedDeckId && ( - deck.id === selectedDeckId)} /> + + + + )} - - - {!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 = ({ + selectedDeckId, + setSelectedDeckId, + removeDeckbyId, + setStar, +}: { + selectedDeckId?: string; + setSelectedDeckId: (id?: string) => void; + removeDeckbyId: (id: string) => void; + setStar: (id: string) => void; +}) => { + 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 +215,3 @@ const UnmatchedInput = ({ ); }; - -const DeckCarousel = ({ - data, - selectedDeck, -}: { - data?: DeckImportType; - selectedDeck?: DeckImportType; -}) => { - const deck = selectedDeck ? selectedDeck : data; - if (!deck) return
; - return ( - ( - - - - ))} - /> - ); -}; From db61e54e5296dd5d9555420a60f83a110ef68207 Mon Sep 17 00:00:00 2001 From: jollygrin Date: Sat, 30 Mar 2024 00:01:35 +0100 Subject: [PATCH 2/3] add json --- components/Bag/Deck/AddJson.tsx | 162 ++++++++++++++++++++++++++++++++ components/Bag/Deck/index.tsx | 17 ++++ 2 files changed, 179 insertions(+) create mode 100644 components/Bag/Deck/AddJson.tsx diff --git a/components/Bag/Deck/AddJson.tsx b/components/Bag/Deck/AddJson.tsx new file mode 100644 index 0000000..e46239f --- /dev/null +++ b/components/Bag/Deck/AddJson.tsx @@ -0,0 +1,162 @@ +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 && ( + + )} + +