Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
JollyGrin committed Mar 30, 2024
1 parent 75a1ec8 commit 7bfd70b
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
28 changes: 26 additions & 2 deletions components/Bag/Bulk/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { DeckImportType } from "@/components/DeckPool/deck-import.type";
import { MapData, useLocalDeckStorage, useLocalMapStorage } from "@/lib/hooks";
import { useGenericImport } from "@/lib/hooks/useGenericImport";
import { useJsonCheck } from "@/lib/hooks/useJsonCheck";
import {
Box,
Expand All @@ -15,14 +16,18 @@ import {
} from "@chakra-ui/react";
import dynamic from "next/dynamic";
import { useState } from "react";
import { useDebounce } from "use-debounce";
const DynamicReactJson = dynamic(import("react-json-view"), { ssr: false });

export const BagBulkContainer = () => {
const { decks, pushDeck } = useLocalDeckStorage();
const { data: maps, clear } = useLocalMapStorage();

const [rawText, setRawText] = useState<string>();
const [url, setUrl] = useState<string>();
const [_url, setUrl] = useState<string>();
const [url] = useDebounce(_url, 300);

const { data: dataGeneric } = useGenericImport(url);

const urlDisclosure = useDisclosure();

Expand All @@ -44,15 +49,31 @@ export const BagBulkContainer = () => {
<Text my="0.5rem">Viewing Local Storage</Text>
)}
</HStack>
{urlDisclosure.isOpen && <Input maxW="200px" bg="white" />}
{urlDisclosure.isOpen && (
<Input
maxW="200px"
bg="white"
value={url}
onChange={(e) => {
if (rawText) setRawText(undefined);
if (e.target.value === "") {
setUrl(undefined);
return;
}
setUrl(e.target.value);
}}
/>
)}
</Box>
{urlDisclosure.isOpen && (
<Box>
<Text>Or copy/paste the json</Text>
<Textarea
h="50px"
fontSize="0.35rem"
value={rawText}
onChange={(e) => {
if (url) setUrl(undefined);
if (e.target.value === "") {
setRawText(undefined);
return;
Expand All @@ -66,6 +87,9 @@ export const BagBulkContainer = () => {
</Box>
{!urlDisclosure.isOpen && <BulkGrid bulk={localBulk} />}
{urlDisclosure.isOpen && rawText && <GridTextWrapper text={rawText} />}
{urlDisclosure.isOpen && dataGeneric?.data && (
<GridTextWrapper text={JSON.stringify(dataGeneric?.data)} />
)}
</Box>
);
};
Expand Down
1 change: 0 additions & 1 deletion components/Bag/Deck/DeckCards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export const DeckCards = ({
};

const HeroCard = ({ deck }: { deck: DeckImportType }) => {
console.log({ deck });
const hero = deck?.deck_data?.hero;
const sidekick = deck?.deck_data?.sidekick;
const isSidekick =
Expand Down
4 changes: 1 addition & 3 deletions components/Bag/StarterDecks/useStarterDecks.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { DeckImportType } from "@/components/DeckPool/deck-import.type";
import { useQuery, useQueries } from "@tanstack/react-query";
import { 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) => ({
Expand Down
8 changes: 8 additions & 0 deletions lib/hooks/useGenericImport.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { useQuery } from "@tanstack/react-query";
import axios from "axios";

export const useGenericImport = (url?: string) => {
return useQuery(["urlData", url], async () => await axios.get(url ?? ""), {
enabled: !!url,
});
};

0 comments on commit 7bfd70b

Please sign in to comment.