Skip to content

Commit

Permalink
Improve timer
Browse files Browse the repository at this point in the history
  • Loading branch information
mdelura committed Mar 5, 2020
1 parent 6f200ab commit 5f8b95e
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/components/Brewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const Brewer: React.SFC<BrewerProps> = ({ recipe }) => {
const finishTime = stepTime * initialPortions;

if (time + 1 < finishTime) {
if (time !== 0 && time % stepTime === 0) sound.play();
if ((time + 1) % stepTime === 0) sound.play();
return time + 1;
} else {
sound.play();
Expand All @@ -49,6 +49,13 @@ const Brewer: React.SFC<BrewerProps> = ({ recipe }) => {
});
};

const toggleTimer = () => (!timer ? startTimer() : killTimer());

const resetTimer = () => {
if (timer) killTimer();
setTime(0);
};

const stepIndex = Math.floor(time / stepTime);

const currentStep = sortedSteps[stepIndex];
Expand All @@ -75,11 +82,16 @@ const Brewer: React.SFC<BrewerProps> = ({ recipe }) => {
<Grid item xs={6}>
<Typography variant="h4">{moment.unix(time).format('mm:ss')}</Typography>
</Grid>
<Grid item xs={6}>
<Button variant="contained" color="primary" onClick={() => (!timer ? startTimer() : killTimer())}>
<Grid item xs={3}>
<Button variant="contained" color="primary" onClick={toggleTimer}>
{!timer ? 'Start' : 'Pause'}
</Button>
</Grid>
<Grid item xs={3}>
<Button variant="contained" color="primary" onClick={resetTimer}>
Reset
</Button>
</Grid>
</Grid>
<Typography variant="h5">Step {stepIndex + 1}</Typography>
<Typography variant="h5">Pour {currentPortion} ml of water</Typography>
Expand Down

0 comments on commit 5f8b95e

Please sign in to comment.