-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature] - Add Timer #33
base: master
Are you sure you want to change the base?
Changes from 3 commits
5ca6ecf
1aecdf7
f515aac
b9da0ef
1669413
f26af3c
dc74532
8b178b9
7e1121b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
PORT=3001 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,66 @@ | ||
import React from 'react'; | ||
import { makeStyles } from '@material-ui/core'; | ||
|
||
const Timer: React.FC = () => <h1>Timer</h1>; | ||
const useStyles = makeStyles(() => ({ | ||
timer: { | ||
position: 'fixed', | ||
left: 0, | ||
width: '100vw', | ||
height: '100vh', | ||
margin: 0, | ||
textAlign: 'center', | ||
display: 'flex', | ||
flexDirection: 'column', | ||
justifyContent: 'center', | ||
}, | ||
})); | ||
|
||
const Timer = () => { | ||
const classes = useStyles(); | ||
const [minutes, setMintues] = React.useState(0); | ||
const [seconds, setSeconds] = React.useState(-5); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like prefixing state variables with |
||
const ref = React.useRef<any>(); | ||
|
||
const stopTimer = () => { | ||
clearInterval(ref.current); | ||
ref.current = null; | ||
}; | ||
|
||
const startTimer = () => { | ||
ref.current = setInterval(() => { | ||
setSeconds((s) => { | ||
if (s + 1 === 60) { | ||
setMintues((m) => m + 1); | ||
return 0; | ||
} | ||
return s + 1; | ||
}); | ||
}, 1000); | ||
}; | ||
|
||
const toggleTimer = () => { | ||
if (ref.current != null) { | ||
stopTimer(); | ||
} else { | ||
startTimer(); | ||
} | ||
}; | ||
|
||
return ( | ||
<div | ||
className={classes.timer} | ||
tabIndex={0} | ||
role="button" | ||
onClick={toggleTimer} | ||
onKeyDown={toggleTimer} | ||
> | ||
<h1> | ||
{minutes < 10 ? 0 : ''} | ||
{minutes}:{seconds < 10 ? 0 : ''} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can use something like |
||
{seconds < 0 ? Math.abs(seconds) : seconds} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since lookup time will always be at a maximum 15 seconds, could we only show seconds there. eg. when seconds state is negative we only show |
||
</h1> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Timer; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we might be able to get rid of this line. I'm not seeing any consoles that would require turning it off.