Compare commits

...

5 Commits

Author SHA1 Message Date
3717240ce9 using useCallback for initAnswers function
Some checks failed
continuous-integration/drone/push Build is failing
2024-09-12 13:06:16 +02:00
b114f52b29 removing unused vars 2024-09-12 12:59:13 +02:00
2a717bfd1d commenting unused lines 2024-09-12 12:58:55 +02:00
72b7cec9af COMPATIBILITY CI | Adding setGameTime function in the list of dependencies 2024-09-12 12:58:38 +02:00
5f92b1bec2 COMPATIBILITY CI | Adding country in the list of dependencies 2024-09-12 12:57:43 +02:00
5 changed files with 29 additions and 29 deletions

View File

@ -5,24 +5,24 @@ import { motion } from "framer-motion";
export default function AnimatedPage({ children, className }) { export default function AnimatedPage({ children, className }) {
const location = useLocation(); const location = useLocation();
const isNext = location.state && location.state.isNext; // const isNext = location.state && location.state.isNext;
const isPrev = location.state && location.state.isPrev; // const isPrev = location.state && location.state.isPrev;
const isGoingNext = location.state && location.state.isGoingNext; // const isGoingNext = location.state && location.state.isGoingNext;
function getAnimationParameters() { // function getAnimationParameters() {
const animationParameters = { animate: { x: "0%", opacity: 1 } }; // const animationParameters = { animate: { x: "0%", opacity: 1 } };
if (isNext === true) { // if (isNext === true) {
animationParameters.initial = { x: "50%", opacity: 0 }; // animationParameters.initial = { x: "50%", opacity: 0 };
} else { // } else {
animationParameters.initial = { x: "-50%", opacity: 0 }; // animationParameters.initial = { x: "-50%", opacity: 0 };
} // }
if (isGoingNext === true) { // if (isGoingNext === true) {
animationParameters.exit = { x: "-50%", opacity: 0 }; // animationParameters.exit = { x: "-50%", opacity: 0 };
} else { // } else {
animationParameters.exit = { x: "50%", opacity: 0 }; // animationParameters.exit = { x: "50%", opacity: 0 };
} // }
return animationParameters; // return animationParameters;
} // }
// const animationParameters = getAnimationParameters(); // const animationParameters = getAnimationParameters();
const animationParameters = { const animationParameters = {
initial: { x: "50%", opacity: 0 }, initial: { x: "50%", opacity: 0 },

View File

@ -13,7 +13,7 @@ export default function GameContainer({ gameId }) {
const [isDragging, setIsDragging] = useState(false); const [isDragging, setIsDragging] = useState(false);
const [startX, setStartX] = useState(0); const [startX, setStartX] = useState(0);
const { contextGameDatas, setContextGameDatas, isGameComplete, score } = useGame(); const { contextGameDatas, setContextGameDatas, isGameComplete } = useGame();
useEffect(() => { useEffect(() => {
if (!gameDatas || gameDatas.error) return; if (!gameDatas || gameDatas.error) return;

View File

@ -15,7 +15,7 @@ export default function Timer() {
// setCurrentTime(currentTime); // setCurrentTime(currentTime);
return () => clearInterval(intervalId); return () => clearInterval(intervalId);
}, [hasCheckedTutorial, gameTime, isTimeRuning]); }, [hasCheckedTutorial, gameTime, isTimeRuning, setGameTime]);
const gameFormatedTime = formatCurrentTime(gameTime); const gameFormatedTime = formatCurrentTime(gameTime);

View File

@ -1,4 +1,4 @@
import { createContext, useEffect, useState } from "react"; import { createContext, useEffect, useState, useCallback } from "react";
// import chantierAtmopshere from "../assets/sounds/chantier_1.mp3"; // import chantierAtmopshere from "../assets/sounds/chantier_1.mp3";
import GameAnswerExplanation from "../components/game/GameAnswerExplanation.jsx"; import GameAnswerExplanation from "../components/game/GameAnswerExplanation.jsx";
import { useUser } from "../hooks/useUser.jsx"; import { useUser } from "../hooks/useUser.jsx";
@ -32,13 +32,7 @@ export function GameContextProvider({ children }) {
const [isGameComplete, setIsGameComplete] = useState(false); const [isGameComplete, setIsGameComplete] = useState(false);
// ##### INIT DATAS ##### // ##### INIT DATAS #####
useEffect(() => { const initAnswers = useCallback(() => {
if (!contextGameDatas) return;
initAnswers();
setRemainingQuestionsAmount(contextGameDatas.gameObjects.length);
}, [contextGameDatas]);
function initAnswers() {
const answersArray = contextGameDatas.gameObjects.map((object, key) => { const answersArray = contextGameDatas.gameObjects.map((object, key) => {
return { return {
correctAnswer: object.attrs.behaviourType ? object.attrs.behaviourType : "unsafe", correctAnswer: object.attrs.behaviourType ? object.attrs.behaviourType : "unsafe",
@ -47,7 +41,13 @@ export function GameContextProvider({ children }) {
}; };
}); });
setAnswers(answersArray); setAnswers(answersArray);
} }, [contextGameDatas]);
useEffect(() => {
if (!contextGameDatas) return;
initAnswers();
setRemainingQuestionsAmount(contextGameDatas.gameObjects.length);
}, [contextGameDatas, initAnswers]);
function answerQuestion(answerKey, answer) { function answerQuestion(answerKey, answer) {
if (!answer || answerKey === null) return; if (!answer || answerKey === null) return;

View File

@ -40,7 +40,7 @@ export function UserContextProvider({ children }) {
(countryJson) => countryJson.alpha2 === country.iso.toLowerCase() (countryJson) => countryJson.alpha2 === country.iso.toLowerCase()
); );
setCountry({ ...country, label: currentCountry[language.toLowerCase()] }); setCountry({ ...country, label: currentCountry[language.toLowerCase()] });
}, [language]); }, [language, country]);
function changeUserLanguage(newLanguage) { function changeUserLanguage(newLanguage) {
setLanguage(newLanguage); setLanguage(newLanguage);