-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExerciseList.js
More file actions
77 lines (69 loc) · 2.94 KB
/
ExerciseList.js
File metadata and controls
77 lines (69 loc) · 2.94 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import React from "react";
import Exercise from "./ExerciseItem";
import { Container, Row, Button, Tooltip } from "shards-react";
import {NavLink} from 'react-router-dom';
import { Label } from 'semantic-ui-react';
const ExerciseList = ( {choosenExercisesArray, updateExercisesArray, totalTrainingTime}) => {
const exercisesDurationInSec = () => {
let count = 0;
choosenExercisesArray.forEach((exercise) => {
count+= (exercise.time + exercise.restTime) * exercise.repeats;
})
return count;
}
const convertAndDisplaySec = (timeInSec) => {
let secDisplay = timeInSec % 60 === 0 ? "00" : timeInSec % 60;
let minDisplay = Math.trunc(timeInSec/60) === 0 ? "00" : Math.trunc(timeInSec/60);
let displayCount = `${minDisplay}:${secDisplay} minutes`;
return displayCount;
}
//consider removing one restTime from total count
//option to add a message of what diff in min:sec exists
const isExercisesDurationFitTotalTime = () => {
const actualDiff = totalTrainingTimeInSec - totalExerciseDuration;
const timeLeftInMin = convertAndDisplaySec(actualDiff);
let msgToShow = "";
if (actualDiff < 0){
msgToShow = "you've reached the training time";
}
else if (actualDiff > 0){
msgToShow = `${timeLeftInMin} left, don't be lazy ;)`;
}
return {
isDurationFitTime: actualDiff <= 0,
diff: actualDiff,
msgToShow
};
}
const totalTrainingTimeInSec = totalTrainingTime / 1000;
const totalExerciseDuration = exercisesDurationInSec();
const {isDurationFitTime, diff, msgToShow} = isExercisesDurationFitTotalTime();
return(
<Container>
<Row className="py-4">
<h1 className="text-white">Training List</h1>
</Row>
{choosenExercisesArray.map((exercise) => (
<Exercise
exercise={exercise}
choosenExercisesArray={choosenExercisesArray}
updateExercisesArray={updateExercisesArray}
key={exercise.id} />
))}
<Row>
<h6 className="text-white">Current duration with rest breaks: <br />
<strong>{convertAndDisplaySec(totalExerciseDuration)}</strong></h6>
{/* Option to display - Remaining time to total: */}
</Row>
<Row className="mt-3">
<NavLink to = {{ pathname: `/Timer/`,
props: { exercisesArray: choosenExercisesArray }
}}>
<Button pill theme="info" size="lg" disabled={!isDurationFitTime}>START TRAINING</Button>
</NavLink>
{!isDurationFitTime && <Label basic color='red' pointing='left'>{msgToShow}</Label>}
</Row>
</Container>
);
};
export default ExerciseList;