-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimer.js
More file actions
62 lines (53 loc) · 1.81 KB
/
Timer.js
File metadata and controls
62 lines (53 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import React, {useState} from "react";
import "./CssComponents/Timer.css";
import {FaPauseCircle, FaPlayCircle} from "react-icons/fa";
import Countdown, {zeroPad} from "react-countdown";
import StartExerciseList from "./StartExerciseList"
import {useLocation} from 'react-router-dom'
function Timer(props) {
let location = useLocation();
console.log(location);
let countdownApi = null;
const [isPlaying, setIsPlaying] = useState(true);
const [time, setTime] = useState(Date.now()+props.time);
const setRef = countdown => {
if (countdown) {
countdownApi = countdown.getApi();
}
};
const handlePauseClick = () => {
countdownApi && countdownApi.pause();
};
const handleStartClick = () => {
countdownApi && countdownApi.start();
};
//total time countdown settings
const renderer = ({ hours, minutes, seconds, completed }) => {
if (completed) {
return <span>You rock! Training session ended!</span>;
} else {
return <span>{zeroPad(minutes)}:{zeroPad(seconds)}</span>
}
}
const displayPauseOrResumeButton = () => {
if (isPlaying) {
return (
<FaPauseCircle size={40} color='teal' onClick = {() => {setIsPlaying(false); handlePauseClick();}} />
)
} else {
return (
<FaPlayCircle size={40} color='teal' onClick = {() => {setIsPlaying(true); handleStartClick();}} />
)
}
}
return (
<div className="timers">
<h1 className="mainTimer pt-4"><Countdown date={time} renderer={renderer} ref={setRef} /></h1>
<div className="button-wrapper">
{displayPauseOrResumeButton()}
</div>
<StartExerciseList exercisesArray={location.props.exercisesArray} isPlaying={isPlaying} />
</div>
)
}
export default Timer;