refactoring

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

View File

@ -1,27 +1,29 @@
import React, { useEffect, useState } from "react";
import clock from "../../assets/img/clock.svg";
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();
console.log("currentTime", currentTime);
const { setGameTime, gameTime } = useGame();
useEffect(() => {
if (!hasCheckedTutorial || !isTimeRuning) return;
let intervalId;
intervalId = setInterval(() => setCurrentTime(currentTime + 100), 1000);
setCurrentTime(currentTime);
intervalId = setInterval(() => setGameTime(gameTime + 100), 1000);
// setCurrentTime(currentTime);
return () => clearInterval(intervalId);
}, [hasCheckedTutorial, currentTime, isTimeRuning]);
}, [hasCheckedTutorial, gameTime, isTimeRuning]);
const gameTime = formatCurrentTime(currentTime);
const gameFormatedTime = formatCurrentTime(gameTime);
return (
<div className='timer'>
<div className='bg'></div>
<img className='clock' src={clock} alt='' />
<h2>{gameTime}</h2>
<h2>{gameFormatedTime}</h2>
</div>
);
}