-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from JollyGrin/feat/update-bag
Feat/update bag
- Loading branch information
Showing
4 changed files
with
131 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ( | ||
<Box p="1rem" mt="2rem" bg="antiquewhite" borderRadius="0.25rem"> | ||
<Text>Don't have any decks in mind?</Text> | ||
{!hasResult && ( | ||
<Button mt="1rem" onClick={onOpen}> | ||
Load starter decks | ||
</Button> | ||
)} | ||
<Flex flexWrap="wrap" gap="0.5rem" mt="1rem"> | ||
{results?.map( | ||
(record) => | ||
record.data !== undefined && ( | ||
<Button | ||
borderRadius="0.25rem" | ||
cursor="pointer" | ||
p="0.5rem" | ||
bg="rgba(0,0,0,0.15)" | ||
isDisabled={props.deckIds?.includes(record.data.id)} | ||
onClick={() => props.pushDeck(record.data as DeckImportType)} | ||
> | ||
{record.data.name} | ||
</Button> | ||
), | ||
)} | ||
</Flex> | ||
</Box> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<DeckImportType>(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", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters