-
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 #47 from JollyGrin/refactor/rename-to-crack
Refactor/rename to crack
- Loading branch information
Showing
10 changed files
with
197 additions
and
72 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,54 @@ | ||
import { Box, Grid, HStack } from "styled-system/jsx"; | ||
import { Button } from "@/components/ui/button"; | ||
import { Tabs } from "@/components/atoms/Tabs"; | ||
|
||
import { useCardFullData } from "@/utils/api/cardData/useCardData"; | ||
import { DraftProps } from "@/components/organisms/Draft/types"; | ||
import { generateBoosterPack } from "@/components/organisms/Draft/helpers"; | ||
|
||
export const Ribbon = ( | ||
props: DraftProps & { | ||
activeViewIndex: number; | ||
setActiveView(index: number): void; | ||
}, | ||
) => { | ||
const { data: cardData = [] } = useCardFullData(); | ||
|
||
function crackBooster() { | ||
const newBooster = generateBoosterPack({ | ||
cardData, | ||
expansionSlug: "bet", | ||
}); | ||
const { finishedPacks } = props.player; | ||
const isEmpty = finishedPacks.length === 0; | ||
props.setPlayerData({ | ||
...props.player, | ||
finishedPacks: isEmpty ? [newBooster] : [...finishedPacks, newBooster], | ||
}); | ||
props.setActiveView(props.player.finishedPacks.length); | ||
} | ||
|
||
const packTabs = | ||
props.player?.finishedPacks?.length > 0 | ||
? props.player?.finishedPacks?.map((_, index) => `Pack ${index + 1}`) | ||
: []; | ||
|
||
return ( | ||
<Box p="1rem" bg="brown"> | ||
<Grid gridTemplateColumns="1fr 7fr"> | ||
<Button minW="9rem" onClick={crackBooster}> | ||
Crack a Pack | ||
</Button> | ||
<HStack maxW="70vw" overflowX="auto" overflowY="clip"> | ||
{props.player.finishedPacks.length > 0 && ( | ||
<Tabs | ||
tabs={packTabs} | ||
onSelect={props.setActiveView} | ||
selectedIndex={props.activeViewIndex} | ||
/> | ||
)} | ||
</HStack> | ||
</Grid> | ||
</Box> | ||
); | ||
}; |
4 changes: 2 additions & 2 deletions
4
...omponents/organisms/Draft/Stats/index.tsx → ...omponents/organisms/Crack/Stats/index.tsx
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { DraftCard } from "@/components/organisms/Draft/Card"; | ||
import { Grid } from "styled-system/jsx"; | ||
import { DraftPlayerData } from "@/components/organisms/Draft/types"; | ||
import { Ribbon } from "@/components/organisms/Crack/Ribbon"; | ||
import { useMemo, useState } from "react"; | ||
import { CrackStats } from "@/components/organisms/Crack/Stats"; | ||
|
||
const hTop = "7vh"; | ||
const hTabs = "5vh"; | ||
const hCards = "88vh"; | ||
export const gridHeight = { top: hTop, tabs: hTabs, cards: hCards }; | ||
|
||
export const CrackBoard = (props: { | ||
player: DraftPlayerData; | ||
setPlayerData(data: DraftPlayerData): void; | ||
}) => { | ||
const [activeView, setActiveView] = useState(0); | ||
const cardView = useMemo(() => { | ||
return props.player.finishedPacks?.[activeView]; | ||
}, [activeView, props.player.finishedPacks.length]); | ||
|
||
return ( | ||
<Grid | ||
h="100vh" | ||
bg="gray.300" | ||
alignItems="center" | ||
gridTemplateRows={`${hTop} ${hTabs} ${hCards}`} | ||
gap={0} | ||
> | ||
<CrackStats {...props} /> | ||
<Ribbon | ||
{...props} | ||
activeViewIndex={activeView} | ||
setActiveView={setActiveView} | ||
/> | ||
<Grid | ||
p="3rem 4rem" | ||
h={hCards} | ||
overflowY="auto" | ||
overflowX="clip" | ||
gridTemplateColumns="repeat(auto-fit, minmax(16.4rem, 1fr))" | ||
position="relative" | ||
bg="gray.500" | ||
> | ||
{(!cardView || cardView?.length === 0) && ( | ||
<p>No packs... yet! Click Crack a Pack!</p> | ||
)} | ||
{cardView?.map((card, index) => ( | ||
<DraftCard key={"draftcard" + card?.name + index} {...card} /> | ||
))} | ||
</Grid> | ||
</Grid> | ||
); | ||
}; |
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 |
---|---|---|
@@ -1,54 +1,9 @@ | ||
import { Box, Grid, HStack } from "styled-system/jsx"; | ||
import { Button } from "@/components/ui/button"; | ||
import { Tabs } from "@/components/atoms/Tabs"; | ||
|
||
import { useCardFullData } from "@/utils/api/cardData/useCardData"; | ||
import { DraftProps } from "../types"; | ||
import { generateBoosterPack } from "../helpers"; | ||
|
||
export const Ribbon = ( | ||
props: DraftProps & { | ||
activeViewIndex: number; | ||
setActiveView(index: number): void; | ||
}, | ||
) => { | ||
const { data: cardData = [] } = useCardFullData(); | ||
|
||
function crackBooster() { | ||
const newBooster = generateBoosterPack({ | ||
cardData, | ||
expansionSlug: "bet", | ||
}); | ||
const { finishedPacks } = props.player; | ||
const isEmpty = finishedPacks.length === 0; | ||
props.setPlayerData({ | ||
...props.player, | ||
finishedPacks: isEmpty ? [newBooster] : [...finishedPacks, newBooster], | ||
}); | ||
props.setActiveView(props.player.finishedPacks.length); | ||
} | ||
|
||
const packTabs = | ||
props.player?.finishedPacks?.length > 0 | ||
? props.player?.finishedPacks?.map((_, index) => `Pack ${index + 1}`) | ||
: []; | ||
import { Box } from "styled-system/jsx"; | ||
|
||
export const DraftRibbon = () => { | ||
return ( | ||
<Box p="1rem" bg="brown"> | ||
<Grid gridTemplateColumns="1fr 7fr"> | ||
<Button minW="9rem" onClick={crackBooster}> | ||
Crack a Pack | ||
</Button> | ||
<HStack maxW="70vw" overflowX="auto" overflowY="clip"> | ||
{props.player.finishedPacks.length > 0 && ( | ||
<Tabs | ||
tabs={packTabs} | ||
onSelect={props.setActiveView} | ||
selectedIndex={props.activeViewIndex} | ||
/> | ||
)} | ||
</HStack> | ||
</Grid> | ||
<Box bg="brown" h="100%"> | ||
<p>ribbon</p> | ||
</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,18 @@ | ||
import { DraftPlayerData } from "../types"; | ||
|
||
export const DraftTray = (props: { | ||
players: Record<string, DraftPlayerData>; | ||
}) => { | ||
const players = Object.entries(props.players); | ||
return ( | ||
<div data-testid="stats"> | ||
{players?.map(([key, value]) => { | ||
return ( | ||
<p key={key}> | ||
{key}:{value.joinedSessionTimestamp} | ||
</p> | ||
); | ||
})} | ||
</div> | ||
); | ||
}; |
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
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,26 @@ | ||
import { CrackBoard } from "@/components/organisms/Crack"; | ||
import { DraftPlayerData } from "@/components/organisms/Draft/types"; | ||
import { useState } from "react"; | ||
|
||
export default function CrackPacksPage() { | ||
const [players, setPlayers] = useState<Record<string, DraftPlayerData>>({ | ||
p1: { | ||
joinedSessionTimestamp: 1, | ||
selectedCards: [], | ||
activePack: [], | ||
pendingPacks: [[]], | ||
finishedPacks: [], | ||
}, | ||
}); | ||
|
||
function setPlayer(data: DraftPlayerData) { | ||
return setPlayers((prev) => ({ | ||
...prev, | ||
p1: { | ||
...data, | ||
}, | ||
})); | ||
} | ||
|
||
return <CrackBoard player={players?.p1} setPlayerData={setPlayer} />; | ||
} |
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