-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExerciseForm.js
More file actions
204 lines (184 loc) · 6.8 KB
/
ExerciseForm.js
File metadata and controls
204 lines (184 loc) · 6.8 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
import React, { useState } from 'react';
import {Exercises} from "../Common/Enums";
import "./CssComponents/ExerciseForm.css";
import 'semantic-ui-css/semantic.min.css';
import { Dropdown, Label, Form ,Input } from 'semantic-ui-react';
import { getRandomExercise } from './RandomExercise';
import { timeOptions } from "../Common/Enums";
import ExerciseList from './ExerciseList';
import { Container, Row, Col } from "shards-react";
class ExerciseForm extends React.Component {
constructor(props) {
super(props);
var ex = Object.keys(Exercises).map((key)=>{
var obj = {};
obj[key] = Exercises[key];
return obj;
});
var res = [];
for (var i in ex){
for (var key in ex[i])
{
Object.values(ex[i][key]).forEach(item =>{
res.push({
key: item,
text: item,
value: item
});
})
}
}
var Types_of_exercises = [{
key: 'Back exercises',
text: 'Back exercises',
value: 'Back exercises',
},
{
key: 'Legs exercises',
text: 'Legs exercises',
value: 'Legs exercises',
},
{
key: 'Abs exercisesbs',
text: 'Abs exercisesbs',
value: 'Abs exercisesbs',
},{
key: 'Shoulders exercises',
text: 'Shoulders exercises',
value: 'Shoulders exercises',
},
{
key: 'FullBody exercises',
text: 'FullBody exercises',
value: 'FullBody exercises',
},]
var myArray = {"Total":10,"Back exercises": 0, "Legs exercises": 1, "Abs exercisesbs": 3,"Shoulders exercises": 4,"FullBody exercises": 5, "Chest exercises":6};
this.state = {
current_exercise: res ,
current_exercises_key: ex ,
myArray: myArray,
Types_of_exercises:Types_of_exercises,
exercise_item : [],
choosenExercisesArray:[],
type: "Back exercises",
name: "Supermans",
time: "",
repeats: 1,
restTime: 10,
id: 1,
};
this.randomFunctionHandler = this.randomFunctionHandler.bind(this);
this.updateExercisesArrayHandler = this.updateExercisesArrayHandler.bind(this);
}
handleRand = () =>{
return(
<div>
{getRandomExercise(getRandomExercise(Exercises))}
</div>
)
}
randomFunctionHandler = (e) => {
e.preventDefault();
console.log(getRandomExercise(getRandomExercise(Exercises)));
let x= getRandomExercise(getRandomExercise(Exercises))
this.setState({name: x})
}
filterExercise = (e,data) =>{
console.log(e.value);
var current_dropdown=[];
for (var key in this.state.current_exercises_key[this.state.myArray[e.value]])
{
Object.keys(this.state.current_exercises_key[this.state.myArray[e.value]][key]).forEach(item =>{
current_dropdown.push({
key: item,
text: item,
value: item
});
})
}
this.setState({current_exercise:current_dropdown})
}
sumbitExerciseHandler = (e) => {
e.preventDefault();
let array = this.state.choosenExercisesArray;
let id = this.state.id;
let obj = { name: this.state.name, time: this.state.time, repeats: this.state.repeats, restTime: this.state.restTime, id:id };
array.push(obj);
id ++;
this.setState({id:id, choosenExercisesArray: array});
}
updateExercisesArrayHandler = (newExercisesArray) => {
this.setState({choosenExercisesArray: newExercisesArray})
}
render() {
let {choosenExercisesArray} = this.state;
return (
<div className="container card-container">
<div className="myCard">
<div className="row card-row">
<div className="col-md-6">
<div className="myLeftCtn">
<header className="fs-30 px-4">Hi you! choose your exercise: </header>
<form className="exercise-form">
<div>
<div>
<button onClick={this.randomFunctionHandler} className="random-exercise-button"> Start random exercise!</button>
</div>
<Label pointing='right'>Select exrecise type</Label>
<Dropdown
fluid
selection
//value={this.state.type}
onChange={(event, data) => {
{this.filterExercise(data)}
}}
options={this.state.Types_of_exercises}
/>
<Label pointing='right'>Select exrecise</Label>
<Dropdown
fluid
selection
onChange={(event,data)=>{
this.setState({name: data.value})
}}
options={this.state.current_exercise}
/>
<Label pointing='right'>Select time</Label>
<Dropdown
fluid
selection
onChange={(event,data)=>{
this.setState({time:data.value})
}}
options={timeOptions}
/>
<Label pointing='right'>Select repeats</Label>
<Input
type="number"
onChange={(event,data)=>{
this.setState({repeats:data.value})
}}
/>
<button onClick={this.sumbitExerciseHandler} className="exercise-button" type="submit">
<i className="fas fa-plus-square"></i>
</button>
</div>
</form>
</div>
</div>
<div className="col-md-6">
<div className="myRightCtn">
<ExerciseList
choosenExercisesArray={choosenExercisesArray}
updateExercisesArray={this.updateExercisesArrayHandler}
totalTrainingTime={this.props.match.params.trainingtime}
/>
</div>
</div>
</div>
</div>
</div>
);
}
}
export default ExerciseForm;