Skip to content

Commit

Permalink
feat: close game result auto
Browse files Browse the repository at this point in the history
  • Loading branch information
JangAyeon committed Feb 25, 2024
1 parent 21da8c6 commit c099028
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
1 change: 0 additions & 1 deletion components/modal/GameResultModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ const GameResultModal = ({
height={48.0}
pointColor={"--color-pink-01"}
>
<Modal.CloseButton />
<Modal.Body>
<Container>
<Text
Expand Down
4 changes: 1 addition & 3 deletions components/pages/cardgame/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import styled from "@emotion/styled"
import { useCallback, useEffect, useState } from "react"
import { useEffect, useState } from "react"

import GameState from "@/components/molecules/GameState"
import PlayBoard from "@/components/molecules/PlayBoard"

import useGame from "@/hooks/useGame"
import useUserProfile from "@/hooks/useUser"

import recordApi from "@/apis/recordApi"

Expand All @@ -14,7 +13,6 @@ import { GameLoadingProps, IGameResult } from "@/types/common/gameProps"
import Loading from "./loading"

const CardGameBoard = () => {
const { userEmail, userSbId } = useUserProfile()
const [stageType, setStageType] = useState<GameLoadingProps>("start")
const { computedBoardState, onCardClick, score, time, moves, cards } =
useGame()
Expand Down
11 changes: 7 additions & 4 deletions components/pages/cardgame/loading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const Loading = ({ type, gameResult }: IGameLoading) => {
// console.log(type)
const router = useRouter()
const [isModalOpen, setIsModalOpen] = useState(false)
const { userEmail, userSbId } = useUserProfile()
const { userEmail } = useUserProfile()

const handleModalOpen = () => {
// console.log("open")
Expand All @@ -48,14 +48,17 @@ const Loading = ({ type, gameResult }: IGameLoading) => {
await recordApi.postGameResult(userEmail, data)
}

const handleModalClose = () => {
const handleModalClose = async () => {
await new Promise((resolve) => setTimeout(resolve, 3000))
setIsModalOpen(false)
postGameResult()

router.replace("/")
}
useEffect(() => {
if (type === "result") {
handleModalOpen()
postGameResult()
handleModalClose()
}
}, [type])
return (
Expand All @@ -66,7 +69,7 @@ const Loading = ({ type, gameResult }: IGameLoading) => {
src="/assets/card/clear.png"
width={254}
height={254}
alt="claer"
alt="clear"
/>
)}
{type === "result" && (
Expand Down

0 comments on commit c099028

Please sign in to comment.