diff --git a/client/src/components/GetImageAndQuestion.jsx b/client/src/components/GetImageAndQuestion.jsx index d27c4e3..1ca558d 100644 --- a/client/src/components/GetImageAndQuestion.jsx +++ b/client/src/components/GetImageAndQuestion.jsx @@ -136,7 +136,7 @@ export const QuizDataImageFromDb = [ }, } ]; - +let MAX_POINT = 9; @@ -379,10 +379,10 @@ useEffect(() => { const buttonsElementArray = Array.from(buttonsElement) setIsClick(!isClick); - if(score === 9) { + if(score === MAX_POINT) { navigate('/result'); } - if(isClick === true) { + if(isClick) { buttonsElementArray.forEach(button => { diff --git a/client/src/components/GetQuestion.jsx b/client/src/components/GetQuestion.jsx index 735e7da..6e259ec 100644 --- a/client/src/components/GetQuestion.jsx +++ b/client/src/components/GetQuestion.jsx @@ -1,47 +1,45 @@ import { TruckId } from "./Truck"; import { AppContext } from './AppContext'; -import React, {useContext, useEffect, useState} from 'react'; +import React, {useContext, useEffect, useState, useReducer} from 'react'; import { ButtonShowCorrectAnswer } from "./GetImageAndQuestion"; export let EndCacheId = ""; export let EndCorrectAnswer = ""; +let clickcounter = 0; - const FetchData = ({isClick,score,setIsClick,setScore,navigate}) => { + if(clickcounter < 3) + clickcounter++; useEffect(() => { fetch(`/random-question?fire-truck=${TruckId}`) .then(res => res.json()) .then(dataQuestion => { - if(isClick === true) { const propertValuesObjectFromDb = Object.values(dataQuestion); - EndCorrectAnswer = propertValuesObjectFromDb[1]; + if(clickcounter === 1) + EndCorrectAnswer = propertValuesObjectFromDb[1]; EndCacheId = propertValuesObjectFromDb[0]; + + if(!isClick){ + EndCorrectAnswer = propertValuesObjectFromDb[1]; + EndCacheId = propertValuesObjectFromDb[0]; } + }) - }) - - - - - - - + },[isClick]) return ( <>

{EndCorrectAnswer}

- +
) } - - export const QuizGetQuestion = ({score,isClick,setScore,setIsClick,navigate}) => { return ( diff --git a/client/src/components/Result.jsx b/client/src/components/Result.jsx index f5083da..42cdefa 100644 --- a/client/src/components/Result.jsx +++ b/client/src/components/Result.jsx @@ -11,12 +11,9 @@ import 'react-circular-progressbar/dist/styles.css'; const Result = () => { const navigate = useNavigate(); - console.log(endScore); - useEffect(() => { - if(!endScore) navigate('/'); - },[]) - - + useEffect(() => { + if(!SecondSeconds) navigate('/'); + },[]) if(endScore) { useEffect(() => { diff --git a/client/src/components/Timer.jsx b/client/src/components/Timer.jsx index 4a38fb1..0683ef5 100644 --- a/client/src/components/Timer.jsx +++ b/client/src/components/Timer.jsx @@ -1,11 +1,11 @@ -export let SecondSeconds = 1; +export let SecondSeconds = 0; export let SecondMinutes = 0; import React, { useState, useEffect } from 'react'; const Timer = () => { const [time, setTime] = useState(0); - let seconds = Math.floor(time % 60); + let seconds = Math.floor(time % 60) + 1; let minutes = Math.floor(time / 60); useEffect(() => {