Skip to content

Commit

Permalink
feat: init results page
Browse files Browse the repository at this point in the history
  • Loading branch information
filahf committed Mar 10, 2022
1 parent c5d7d7a commit a318b5b
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 14 deletions.
11 changes: 7 additions & 4 deletions src/components/dom/score/Score.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const Score = () => {

const score = useStore((s) => s.score)
const streakMultiplier = useStore((s) => s.streakMultiplier)
const start = useStore((s) => s.startGame)

useEffect(() => {
if (!ref.current) return
Expand All @@ -20,14 +21,16 @@ const Score = () => {

return (
<>
<VStack mt={10}>
<VStack>
<Text>SCORE</Text>
<Text textStyle='score' mb={0} pb={0} ref={ref}>
{score}
</Text>
<Text mt={0} fontWeight='bold'>
{streakMultiplier}x
</Text>
{start && (
<Text mt={0} fontWeight='bold'>
{streakMultiplier}x
</Text>
)}
</VStack>
</>
)
Expand Down
13 changes: 10 additions & 3 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import useStore from '@/shared/store'
import { InGame, Onboarding } from '@/views/dom'
import { EndGame, InGame, Onboarding } from '@/views/dom'
import dynamic from 'next/dynamic'

const GameCanvas = dynamic<Record<string, unknown>>(
Expand All @@ -8,9 +8,16 @@ const GameCanvas = dynamic<Record<string, unknown>>(
)

const DomElements = () => {
const inGame = useStore((s) => s.startGame)
const start = useStore((s) => s.startGame)
const endGame = useStore((s) => s.endGame)

return inGame ? <InGame /> : <Onboarding />
return (
<>
{!start && !endGame && <Onboarding />}
{start && !endGame && <InGame />}
{!start && endGame && <EndGame />}
</>
)
}

const Page = () => {
Expand Down
30 changes: 29 additions & 1 deletion src/views/dom/EndGame.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,35 @@
import { Score } from '@/components/dom/score'
import useStore from '@/shared/store'
import {
Button,
Center,
Modal,
ModalBody,
ModalContent,
ModalOverlay,
} from '@chakra-ui/react'
const EndGame = () => {
const resetGame = useStore((s) => s.resetGame)
return (
<>
<p>EndGame</p>
<Modal
closeOnOverlayClick={false}
isOpen={true}
isCentered
onClose={() => resetGame()}
>
<ModalOverlay />
<ModalContent>
<ModalBody bg='black' p={10}>
<Center flexDir='column'>
<Score />
<Button mt={3} onClick={() => resetGame()}>
New Game
</Button>
</Center>
</ModalBody>
</ModalContent>
</Modal>
</>
)
}
Expand Down
10 changes: 4 additions & 6 deletions src/views/dom/InGame.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import { ResetButton } from '@/components/dom/reset-button'
import { Score } from '@/components/dom/score'
import { Box, Stack } from '@chakra-ui/react'
import { Box } from '@chakra-ui/react'

const InGame = () => {
return (
<>
<ResetButton />
<Stack textAlign={'center'} py={4}>
<Box>
<Score />
</Box>
</Stack>
<Box mt={6}>
<Score />
</Box>
</>
)
}
Expand Down

0 comments on commit a318b5b

Please sign in to comment.