-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExercisesViewer.js
More file actions
142 lines (140 loc) · 4.11 KB
/
Copy pathExercisesViewer.js
File metadata and controls
142 lines (140 loc) · 4.11 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
import React, { Component } from "react";
import { ScrollView } from "react-native";
import { View, Subtitle, Text, TextInput, Button } from "@shoutem/ui";
import Swipeout from "react-native-swipeout";
class ExercisesViewer extends React.Component {
constructor(props) {
super(props);
this.state = {
workout: "",
reps: "",
editKey: null
};
}
render() {
return (
<View>
<ScrollView
style={{
borderWidth: 2,
height: "60%",
marginHorizontal: 10
}}
>
{Object.keys(this.props.exercises).map((key, index) => (
<Swipeout
key={index}
right={[
{
text: "Edit",
backgroundColor: "blue",
underlayColor: "rgba(0, 0, 0, 1, 0.6)",
onPress: () => {
this.setState({
workout: this.props.exercises[key].workout,
reps: this.props.exercises[key].reps,
editKey: key
});
}
},
{
text: "Delete",
backgroundColor: "red",
underlayColor: "rgba(0, 0, 0, 1, 0.6)",
onPress: () => {
this.props.deleteExercise(key);
if (this.state.editKey == key) {
this.setState({
workout: "",
reps: "",
editKey: null
});
}
}
}
]}
autoClose={true}
backgroundColor="transparent"
>
<View
styleName="vertical"
style={{
margin: 5
}}
>
<Subtitle styleName="bold" style={{ fontSize: 18 }}>
{this.props.exercises[key].workout}
</Subtitle>
<Text style={{ fontSize: 12 }}>
{this.props.exercises[key].reps}
</Text>
</View>
</Swipeout>
))}
</ScrollView>
<View
style={{
borderWidth: 2,
marginHorizontal: 10,
height: "30%",
marginTop: 10,
justifyContent: "center"
}}
>
<TextInput
placeholder="EXERCISE NAME"
multiline
style={{
fontSize: 25,
padding: 0,
textAlign: "center",
flex: 1
}}
onChangeText={text => this.setState({ workout: text })}
value={this.state.workout}
/>
<TextInput
placeholder="REPS"
style={{
fontSize: 20,
padding: 0,
textAlign: "center",
flex: 0.6
}}
onChangeText={text => this.setState({ reps: text })}
value={this.state.reps}
/>
<Button
styleName="secondary"
style={{ marginBottom: 20, marginHorizontal: 20, flex: 0.6 }}
onPress={() => {
if (this.state.workout != "") {
if (this.state.editKey == null) {
this.props.addNewExercise(
new Date().valueOf(),
this.state.workout,
this.state.reps
);
} else {
this.props.editExercise(
this.state.editKey,
this.state.workout,
this.state.reps
);
}
}
this.setState({ workout: "", reps: "", editKey: null });
}}
>
{this.state.editKey ? (
<Text style={{ fontSize: 20 }}>Confirm Edit</Text>
) : (
<Text style={{ fontSize: 20 }}>+</Text>
)}
</Button>
</View>
</View>
);
}
}
export default ExercisesViewer;