diff --git a/src/components/atoms/Modal/index.tsx b/src/components/atoms/Modal/index.tsx index 2d458a8..b082b95 100644 --- a/src/components/atoms/Modal/index.tsx +++ b/src/components/atoms/Modal/index.tsx @@ -5,8 +5,9 @@ import { DialogTitle, DialogTrigger, } from "@/components/ui/dialog"; -import { DialogProps } from "@radix-ui/react-dialog"; +import { DialogDescription, DialogProps } from "@radix-ui/react-dialog"; import { ReactNode } from "react"; +import { VisuallyHidden } from "styled-system/jsx"; export const Modal = (props: { wrapperProps: DialogProps; @@ -18,11 +19,12 @@ export const Modal = (props: { {props.trigger && {props.trigger}} - {props.title && ( + {props.title} + modal - )} + {props.content} diff --git a/src/components/molecules/LoadDeck/index.tsx b/src/components/molecules/LoadDeck/index.tsx index 807a8be..29d3346 100644 --- a/src/components/molecules/LoadDeck/index.tsx +++ b/src/components/molecules/LoadDeck/index.tsx @@ -7,7 +7,7 @@ import { Box, Flex } from "styled-system/jsx"; import { button, input } from "styled-system/recipes"; export const LoadDeck = (props: GameStateActions) => { - const [deckId, setDeckId] = useState(); + const [deckId, setDeckId] = useState(""); const { data: deck } = useCuriosaDeck(deckId); const cards = [ ...(deck?.avatar ?? []), @@ -70,7 +70,7 @@ export const LoadDeck = (props: GameStateActions) => { value={deckId} onChange={(e) => setDeckId(e.target.value)} /> - {deckId === undefined && ( + {deckId === "" && ( <> copy the deckid from curiosa { > )} - {deckId !== undefined && ( + {deckId !== "" && ( { const gridIndex = GRIDS.HAND; const cardsInHand = props.gridItems[gridIndex] ?? []; @@ -45,23 +60,13 @@ export const GameFooter = (props: GameStateActions) => { overflowX="auto" > {props.gridItems?.[gridIndex]?.map((card, index) => ( - - - {card?.type === "site" && } - {card?.type !== "site" && } - - + ))} @@ -70,3 +75,82 @@ export const GameFooter = (props: GameStateActions) => { ); }; + +const HandCard = ({ + card, + gridIndex, + cardIndex: index, + gameStateActions, +}: { + card: GameCard; + gridIndex: number; + cardIndex: number; + gameStateActions: GameStateActions; +}) => { + const [preview, setPreview] = useState(false); + const deckType = card.type === "site" ? "atlas" : "deck"; + + function topDeck() { + gameStateActions.setGridItems( + actHandToTopDeck(gameStateActions.gridItems, deckType, index), + ); + } + + function bottomDeck() { + gameStateActions.setGridItems( + actHandToBottomDeck(gameStateActions.gridItems, deckType, index), + ); + } + + return ( + { + e.preventDefault(); + setPreview(true); + }} + style={{ + position: "relative", + width: "100%", + maxWidth: "220px", + minWidth: "180px", + }} + > + + {card?.type === "site" && } + {card?.type !== "site" && } + + + + {card.type === "site" && } + {card.type !== "site" && } + + + + + Top of deck + + + + + + + Bottom of deck + + + + + } + /> + + ); +}; diff --git a/src/utils/actions/hand.ts b/src/utils/actions/hand.ts new file mode 100644 index 0000000..190a849 --- /dev/null +++ b/src/utils/actions/hand.ts @@ -0,0 +1,62 @@ +import { GRIDS } from "@/components/organisms/GameBoard/constants"; +import { GameState } from "@/types/card"; + +/** + * Return a card from hand to the top of the deck + * */ +export function actHandToTopDeck( + state: GameState, + deckType: "deck" | "atlas", + handCardIndex: number, +) { + // Create a shallow copy of the previous grid items array + const newState = [...state]; + + // choose between deck or atlas deck + const GRIDS_DECK_TYPE = deckType === "deck" ? GRIDS.DECK : GRIDS.ATLAS_DECK; + + // Make a copy of the deck and hand arrays, preserving their positions + const newDeck = [...newState[GRIDS_DECK_TYPE]]; + const newHand = [...newState[GRIDS.HAND]]; + + // Pop a card from the hand and push it to the deck + const [card] = newHand.splice(handCardIndex, 1); + if (card) newDeck.push(card); + + // Update the newState array + newState[GRIDS_DECK_TYPE] = newDeck; + newState[GRIDS.HAND] = newHand; + + // Return the updated newState array to trigger a re-render + return newState; +} + +/** + * Return a card from hand to the top of the deck + * */ +export function actHandToBottomDeck( + state: GameState, + deckType: "deck" | "atlas", + handCardIndex: number, +) { + // Create a shallow copy of the previous grid items array + const newState = [...state]; + + // choose between deck or atlas deck + const GRIDS_DECK_TYPE = deckType === "deck" ? GRIDS.DECK : GRIDS.ATLAS_DECK; + + // Make a copy of the deck and hand arrays, preserving their positions + const newDeck = [...newState[GRIDS_DECK_TYPE]]; + const newHand = [...newState[GRIDS.HAND]]; + + // Pop a card from the hand and push it to the deck + const [card] = newHand.splice(handCardIndex, 1); + if (card) newDeck.unshift(card); + + // Update the newState array + newState[GRIDS_DECK_TYPE] = newDeck; + newState[GRIDS.HAND] = newHand; + + // Return the updated newState array to trigger a re-render + return newState; +}
copy the deckid from curiosa
Top of deck
Bottom of deck