refactoring
This commit is contained in:
parent
e62a07c25e
commit
62a29d4b9d
|
|
@ -3,25 +3,27 @@ import clock from "../../assets/img/clock.svg";
|
|||
import { useGame } from "../../hooks/useGame";
|
||||
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>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user