refactoring

This commit is contained in:
Antoine M 2024-02-21 11:05:11 +01:00
parent e62a07c25e
commit 62a29d4b9d

View File

@ -3,25 +3,27 @@ import clock from "../../assets/img/clock.svg";
import { useGame } from "../../hooks/useGame"; import { useGame } from "../../hooks/useGame";
import { formatCurrentTime } from "../../utils/gameFunctions"; import { formatCurrentTime } from "../../utils/gameFunctions";
export default function Timer({ currentTime, setCurrentTime }) { export default function Timer() {
const { hasCheckedTutorial, isTimeRuning } = useGame(); const { hasCheckedTutorial, isTimeRuning } = useGame();
console.log("currentTime", currentTime);
const { setGameTime, gameTime } = useGame();
useEffect(() => { useEffect(() => {
if (!hasCheckedTutorial || !isTimeRuning) return; if (!hasCheckedTutorial || !isTimeRuning) return;
let intervalId; let intervalId;
intervalId = setInterval(() => setCurrentTime(currentTime + 100), 1000); intervalId = setInterval(() => setGameTime(gameTime + 100), 1000);
setCurrentTime(currentTime); // setCurrentTime(currentTime);
return () => clearInterval(intervalId); return () => clearInterval(intervalId);
}, [hasCheckedTutorial, currentTime, isTimeRuning]); }, [hasCheckedTutorial, gameTime, isTimeRuning]);
const gameTime = formatCurrentTime(currentTime); const gameFormatedTime = formatCurrentTime(gameTime);
return ( return (
<div className='timer'> <div className='timer'>
<div className='bg'></div> <div className='bg'></div>
<img className='clock' src={clock} alt='' /> <img className='clock' src={clock} alt='' />
<h2>{gameTime}</h2> <h2>{gameFormatedTime}</h2>
</div> </div>
); );
} }