Skip to content

Commit

Permalink
fix: Play gets stuck bug
Browse files Browse the repository at this point in the history
  • Loading branch information
CaliCastle committed Oct 23, 2023
1 parent 59fc331 commit ee3bb0f
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions app/_game/scenes/Play.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { clsxm } from '@zolplay/utils'
import { AnimatePresence } from 'framer-motion'
import Image from 'next/image'
import { useEffect, useMemo, useRef, useState } from 'react'
import { useCountdown, useWindowSize } from 'usehooks-ts'
import { useCountdown, useInterval, useWindowSize } from 'usehooks-ts'

import { getGameImageUrlById } from '~/helpers/getGameImageUrlById'
import { useMount } from '~/hooks/useMount'
Expand All @@ -27,18 +27,23 @@ export function Play() {
const startTime = useRef(new Date())
const answers = useRef<Answers>([])
const handleAnswer = (AI: boolean) => {
if (answers.current.length === props.total) {
return
}
answers.current.push({ image: props.images[imageIndex] || '', AI })
setImageIndex(imageIndex + 1)
setSwipingSide('none')
}

useInterval(() => {
if (answers.current.length === props.total) {
const time = Math.floor(
(new Date().getTime() - startTime.current.getTime()) / 1000
)
setSceneProps('RESULT_WAITING', { answers: answers.current, time })
switchScene('RESULT_WAITING')
return
}
setImageIndex(imageIndex + 1)
setSwipingSide('none')
}
}, 1000)

const nextTestRemainingSeconds = dayjs(
sceneProps['MENU'].nextTestStartTime
Expand Down

0 comments on commit ee3bb0f

Please sign in to comment.