return to the previous state with btnCorrectAnswer

This commit is contained in:
Stachu 2023-03-15 00:41:35 +01:00
parent c3d013d6b8
commit 7bf9684946
2 changed files with 12 additions and 17 deletions

View File

@ -1,4 +1,3 @@
import React, {useRef, useEffect, useState} from 'react';
import { useNavigate } from 'react-router-dom';
import { TruckId } from './Truck';
@ -296,7 +295,6 @@ useEffect(() => {
break;
case 3:
console.log('Wykonało sie 3')
name0ArrayFromDB.push(caches[0].cacheName);
name1ArrayFromDB.push(caches[1].cacheName);
name2ArrayFromDB.push(caches[2].cacheName);

View File

@ -1,49 +1,46 @@
import { TruckId } from "./Truck";
import { AppContext } from './AppContext';
import React, {useContext, useEffect, useState, useReducer} from 'react';
import React, {useContext, useEffect, useState} 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) {
const propertValuesObjectFromDb = Object.values(dataQuestion);
if(clickcounter === 1)
EndCorrectAnswer = propertValuesObjectFromDb[1];
EndCacheId = propertValuesObjectFromDb[0];
if(!isClick){
EndCorrectAnswer = propertValuesObjectFromDb[1];
EndCacheId = propertValuesObjectFromDb[0];
EndCacheId = propertValuesObjectFromDb[0];
}
})
},[isClick])
})
return (
<>
<div className="questionDiv">
<h1 className='questionText1'>{EndCorrectAnswer}</h1>
<button onClick={() => ButtonShowCorrectAnswer(isClick, setIsClick , score , setScore, navigate)} className='NextQuestionButton'>{isClick ? "Pokaż odpowiedź" : "Następne pytanie"}</button>
<button onClick={() => ButtonShowCorrectAnswer(isClick, setIsClick , score , setScore, navigate)} className='NextQuestionButton'>{isClick ? "Pokaż odpowiedź" : "Następne pytanie"}</button>
</div>
</>
)
}
export const QuizGetQuestion = ({score,isClick,setScore,setIsClick,navigate}) => {
return (
<FetchData score = {score} isClick = {isClick} setScore = {setScore} setIsClick = {setIsClick} navigate = {navigate}/>
)
}