From a179118bfa2f7af306893895161adf9fb9bd1897 Mon Sep 17 00:00:00 2001 From: asketonim Date: Sun, 5 Jan 2020 00:40:40 +0300 Subject: Fix timer behavior and initial time value --- src/components/Timer/Timer.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/components') diff --git a/src/components/Timer/Timer.js b/src/components/Timer/Timer.js index f840429..4712265 100644 --- a/src/components/Timer/Timer.js +++ b/src/components/Timer/Timer.js @@ -7,7 +7,7 @@ import { Typography } from '@material-ui/core'; const Timer = () => { const SPACE = 32; const maxCountdown = 15000; - const [time, setTime] = useState('00:15:00'); + const [time, setTime] = useState('00:00:00'); const [isRunning, setIsRunning] = useState(false); const [timer, setTimer] = useState(0); const [isCountdown, setIsCountdown] = useState(false); @@ -32,14 +32,14 @@ const Timer = () => { }; const handleKeyUp = event => { - clearInterval(timer); - if (event.keyCode === SPACE){ + if (event.keyCode === SPACE) { + clearInterval(timer); if (!isRunning) { startingTime = Date.now(); setIsRunning(true); setTimer(setInterval(() => setTime(convertTimeToString((Date.now() - startingTime))), 10)); } else { - + clearInterval(timer); setIsRunning(false); setIsCountdown(false); -- cgit v1.2.3