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 }) {
const location = useLocation();
const isNext = location.state && location.state.isNext;
const isPrev = location.state && location.state.isPrev;
const isGoingNext = location.state && location.state.isGoingNext;
// const isNext = location.state && location.state.isNext;
// const isPrev = location.state && location.state.isPrev;
// const isGoingNext = location.state && location.state.isGoingNext;
function getAnimationParameters() {
const animationParameters = { animate: { x: "0%", opacity: 1 } };
if (isNext === true) {
animationParameters.initial = { x: "50%", opacity: 0 };
} else {
animationParameters.initial = { x: "-50%", opacity: 0 };
}
if (isGoingNext === true) {
animationParameters.exit = { x: "-50%", opacity: 0 };
} else {
animationParameters.exit = { x: "50%", opacity: 0 };
}
return animationParameters;
}
// function getAnimationParameters() {
// const animationParameters = { animate: { x: "0%", opacity: 1 } };
// if (isNext === true) {
// animationParameters.initial = { x: "50%", opacity: 0 };
// } else {
// animationParameters.initial = { x: "-50%", opacity: 0 };
// }
// if (isGoingNext === true) {
// animationParameters.exit = { x: "-50%", opacity: 0 };
// } else {
// animationParameters.exit = { x: "50%", opacity: 0 };
// }
// return animationParameters;
// }
// const animationParameters = getAnimationParameters();
const animationParameters = {
initial: { x: "50%", opacity: 0 },

View File

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

View File

@ -15,7 +15,7 @@ export default function Timer() {
// setCurrentTime(currentTime);
return () => clearInterval(intervalId);
}, [hasCheckedTutorial, gameTime, isTimeRuning]);
}, [hasCheckedTutorial, gameTime, isTimeRuning, setGameTime]);
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 GameAnswerExplanation from "../components/game/GameAnswerExplanation.jsx";
import { useUser } from "../hooks/useUser.jsx";
@ -32,13 +32,7 @@ export function GameContextProvider({ children }) {
const [isGameComplete, setIsGameComplete] = useState(false);
// ##### INIT DATAS #####
useEffect(() => {
if (!contextGameDatas) return;
initAnswers();
setRemainingQuestionsAmount(contextGameDatas.gameObjects.length);
}, [contextGameDatas]);
function initAnswers() {
const initAnswers = useCallback(() => {
const answersArray = contextGameDatas.gameObjects.map((object, key) => {
return {
correctAnswer: object.attrs.behaviourType ? object.attrs.behaviourType : "unsafe",
@ -47,7 +41,13 @@ export function GameContextProvider({ children }) {
};
});
setAnswers(answersArray);
}
}, [contextGameDatas]);
useEffect(() => {
if (!contextGameDatas) return;
initAnswers();
setRemainingQuestionsAmount(contextGameDatas.gameObjects.length);
}, [contextGameDatas, initAnswers]);
function answerQuestion(answerKey, answer) {
if (!answer || answerKey === null) return;

View File

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