-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbody.js
270 lines (253 loc) · 8.21 KB
/
body.js
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
import React, { Component } from 'react';
import { TextInput, Button, Modal, StyleSheet, Text, View, TouchableHighlight, Dimensions, FlatList, Image, KeyboardAvoidingView, TouchableWithoutFeedback, Keyboard } from 'react-native';
import DropdownMenu from 'react-native-dropdown-menu';
import StatusBar from './StatusBar'
import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view'
import { Provider, connect } from 'react-redux'
import { addDataToAPI, changeWorkout, changeReps, changeMax, addWorkoutToAPI } from './actions'
import DialogInput from 'react-native-dialog-input';
import { Icon } from 'react-native-elements'
BigCricle = (props) => {
return(
<View style={styles.bigCricle}>
<Text style={styles.maxText}> Max </Text>
<Text style={styles.maxWeight}> {props.data.max} </Text>
</View>
)
}
class WeightInput extends Component {
constructor(props) {
super(props);
this.state = {
inputText: ''
};
}
render() {
return (
<View
style={{flex:1,alignItems:'center'}}>
<Text style= {styles.largeText}> What weight did you do today? </Text>
<View style={{flexDirection:'row'}}>
<TextInput
style={styles.textInput}
value={this.state.inputText}
onChangeText = {(text) => this.setState({inputText:text})}
placeholder="Enter Weight"
keyboardType="numeric"
returnKeyType="send"
/>
<TouchableHighlight style={{marginLeft:10, height:40,width:50, borderRadius:10, justifyContent:'center', alignItems: 'center', backgroundColor:'#F7B733', marginTop: 20}}
onPress= { () => {
// Adds text input to database
this.props.addData({body:this.props.data.body, workout:this.props.data.curWorkout, weight:parseInt(this.state.inputText,10), reps:this.props.data.curReps})
this.setState({inputText:''})
} }
underlayColor='green'>
<View >
<Text style={{color:'#DFDCE3', fontWeight:'bold'}}>Send</Text>
</View>
</TouchableHighlight>
</View>
</View>
)
}
}
HistoryButton = (props) => {
return (
<TouchableHighlight
style={{height:75, backgroundColor:'#F7B733'}}
onPress={() => props.navigation.navigate('History')}
underlayColor='green'>
<View style={{flex:1,justifyContent:'center',alignItems:'center'}}>
<Text style={styles.historyText}> History </Text>
</View>
</TouchableHighlight>
)
}
class Prompt extends Component {
constructor(props) {
super(props)
this.state = {
inputText: ''
}
}
render() {
return (
<Modal
animationType="fade"
visible={this.props.isVisible}
transparent={true}
onRequestClose={() => {
alert('Modal has been closed.');
}}>
<TouchableWithoutFeedback onPress={Keyboard.dismiss} accessible={false} style={styles.modalContainer}>
<View style={styles.modalContainer}>
<View style={styles.dialogBox}>
<TextInput
value={this.state.inputText}
onChangeText = {(text) => this.setState({inputText:text})}
style={{fontSize:30}}
placeholder="Add Workout"
/>
<View style={{flexDirection:'row'}}>
<Button
onPress={() =>{
this. props.toggleVisibility();
this.setState({inputText:''})
}}
title = "Cancel"
/>
<Button
onPress={() => {
this.props.addWorkout({workout:this.state.inputText, body:this.props.data.body});
this.setState({inputText:''})
this. props.toggleVisibility()
}}
title = "Ok"
/>
</View>
</View>
</View>
</TouchableWithoutFeedback>
</Modal>
)
}
}
function upperCase(word) {
return word.charAt(0).toUpperCase() + word.substr(1);
}
class Body extends Component {
constructor(props) {
super(props)
this.state = {
isDialogVisible: false
}
}
_toggleVisibility = () => {
this.setState({ isDialogVisible: !this.state.isDialogVisible });
};
componentDidMount() {
this.props.navigation.setParams({ toggleVisibility: this._toggleVisibility, body: upperCase(this.props.data.body)});
}
static navigationOptions = ({ navigation }) => {
return {
headerRight: (
<TouchableHighlight
underlayColor='gray'
onPress={navigation.getParam('toggleVisibility')}
style={{marginRight:5}}
>
<Icon
name='add'
size={30}
color='black'/>
</TouchableHighlight>
),
title: navigation.getParam('body')
};
}
render() {
var data = [this.props.data.workouts, this.props.data.reps]
return(
<TouchableWithoutFeedback onPress={Keyboard.dismiss} accessible={false}>
<View style={{flex:1, backgroundColor: '#4ABDAC'}}>
{/*<StatusBar/>*/}
<Prompt isVisible={this.state.isDialogVisible} toggleVisibility={this._toggleVisibility} {...this.props}/>
<View style={{flex:1}}>
<DropdownMenu
bgColor={'white'}
tintColor={'#666666'}
activityTintColor={'green'}
handler={(selection, row) => {
if (selection == 0) {
this.props.changeWorkout(data[selection][row]);
this.props.changeMax({workout:data[0][row], reps:this.props.data.curReps, body: this.props.data.body})
}
else {
this.props.changeReps(data[selection][row]);
this.props.changeMax({workout:this.props.data.curWorkout, reps:data[1][row], body: this.props.data.body})
}
}}
data={data}>
<View style={{flex:2, justifyContent:'center', alignItems: 'center'}}>
<BigCricle {...this.props}/>
</View>
<KeyboardAvoidingView
style={{flex:1,alignItems:'center'}}
behavior="padding">
<WeightInput {...this.props}/>
</KeyboardAvoidingView>
<HistoryButton {...this.props}/>
</DropdownMenu>
</View>
</View>
</TouchableWithoutFeedback>)
}
}
const {height, width} = Dimensions.get('window');
const styles = StyleSheet.create({
dialogBox : {
backgroundColor:'#FFFFFFE0',
borderRadius: 30,
alignItems: 'center',
padding: 8
},
bigCricle : {
width: 250,
height: 250,
backgroundColor: '#FC4A1A',
borderRadius: 150,
alignItems: 'center',
justifyContent: 'center'
},
modalContainer : {
flex:1,
justifyContent:'center',
alignItems:'center'
},
maxText : {
fontSize: 50,
fontWeight: 'bold',
color: 'white',
marginBottom: 10
},
historyText : {
fontSize: 25,
fontWeight: 'bold',
color: '#DFDCE3'
},
maxWeight : {
fontSize: 40,
fontWeight: 'bold',
color: 'yellow'
},
largeText: {
fontSize: 25,
marginTop: 40,
color: 'white'
},
textInput: {
width: 130,
height:40,
paddingLeft: 20,
marginTop: 20,
backgroundColor: '#2a7064',
borderRadius: 30
}
});
function mapStateToProps(state) {
return {
data: state.data,
history: state.history
}
}
function mapDispatchToProps(dispatch) {
return {
addData: (data) => dispatch(addDataToAPI(data)),
changeWorkout: (workout) => dispatch(changeWorkout(workout)),
changeReps: (reps) => dispatch(changeReps(reps)),
changeMax: (max) => dispatch(changeMax(max)),
addWorkout: (data) => dispatch(addWorkoutToAPI(data))
}
}
export default connect(mapStateToProps, mapDispatchToProps)(Body)