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