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

View File

@ -1,34 +1,30 @@
import { TruckId } from "./Truck"; import { TruckId } from "./Truck";
import { AppContext } from './AppContext'; import { AppContext } from './AppContext';
import React, {useContext, useEffect, useState, useReducer} from 'react'; import React, {useContext, useEffect, useState} from 'react';
import { ButtonShowCorrectAnswer } from "./GetImageAndQuestion"; import { ButtonShowCorrectAnswer } from "./GetImageAndQuestion";
export let EndCacheId = ""; export let EndCacheId = "";
export let EndCorrectAnswer = ""; export let EndCorrectAnswer = "";
let clickcounter = 0;
const FetchData = ({isClick,score,setIsClick,setScore,navigate}) => { const FetchData = ({isClick,score,setIsClick,setScore,navigate}) => {
if(clickcounter < 3)
clickcounter++;
useEffect(() => { useEffect(() => {
fetch(`/random-question?fire-truck=${TruckId}`) fetch(`/random-question?fire-truck=${TruckId}`)
.then(res => res.json()) .then(res => res.json())
.then(dataQuestion => { .then(dataQuestion => {
if(isClick) {
const propertValuesObjectFromDb = Object.values(dataQuestion); const propertValuesObjectFromDb = Object.values(dataQuestion);
if(clickcounter === 1)
EndCorrectAnswer = propertValuesObjectFromDb[1]; EndCorrectAnswer = propertValuesObjectFromDb[1];
EndCacheId = propertValuesObjectFromDb[0];
if(!isClick){
EndCorrectAnswer = propertValuesObjectFromDb[1];
EndCacheId = propertValuesObjectFromDb[0]; EndCacheId = propertValuesObjectFromDb[0];
} }
}) })
},[isClick]) })
return ( return (
<> <>
@ -40,10 +36,11 @@ const FetchData = ({isClick,score,setIsClick,setScore,navigate}) => {
) )
} }
export const QuizGetQuestion = ({score,isClick,setScore,setIsClick,navigate}) => { export const QuizGetQuestion = ({score,isClick,setScore,setIsClick,navigate}) => {
return ( return (
<FetchData score = {score} isClick = {isClick} setScore = {setScore} setIsClick = {setIsClick} navigate = {navigate}/> <FetchData score = {score} isClick = {isClick} setScore = {setScore} setIsClick = {setIsClick} navigate = {navigate}/>
) )
} }