-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAddPreferences.jsx
170 lines (158 loc) · 5.11 KB
/
AddPreferences.jsx
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
import React, { useState } from "react";
import {
StyleSheet,
Text,
View,
Button,
Animated,
ScrollView,
} from "react-native";
import { Slider, Icon, CheckBox, ButtonGroup } from "react-native-elements";
import { postNewUser } from "../API";
function AddPreferences({ route, navigation }) {
const profileInfo = { ...route.params };
// console.log(profileInfo);
const [distance, setDistance] = useState(40);
const opponentHandButtons = ["left-handed", "right-handed", "either"];
const [opponentHand, setOpponentHand] = useState(2);
const abilityLevelButtons = [
"beginner",
"intermediate",
"advanced",
"expert",
];
const [opponentAbility, setOppoenentAbility] = useState([0, 3]);
const opponentGroupOptions = ["mens", "womens", "either"];
const [group, setGroup] = useState(2);
const [savedPreferences, setSavedPreferences] = useState(false);
// current queries set up are gender / playing hand / min ability / max ability
const addPreferences = (
profileData,
distance,
opponentAbility,
group,
opponentHand
) => {
profileData.distance = distance;
if (opponentAbility.length === 0) {
profileData.min_ability = 1;
profileData.max_ability = 4;
} else if (opponentAbility.length === 1) {
profileData.min_ability = opponentAbility[0] + 1;
profileData.max_ability = opponentAbility[0] + 1;
} else {
profileData.min_ability = opponentAbility.sort()[0] + 1;
profileData.max_ability =
opponentAbility.sort()[opponentAbility.length - 1] + 1;
}
if (group === 0) {
profileData.gender_preference = "m";
} else if (group === 1) {
profileData.gender_preference = "f";
} else {
profileData.gender_preference = "";
}
if (opponentHand === 0) {
profileData.hand_preference = "left-handed";
} else if (opponentHand === 1) {
profileData.hand_preference = "right-handed";
} else {
// this will not add anything could be removed
profileData.hand_preference = "";
}
return profileData;
};
return (
<ScrollView>
<Text style={styles.questions}>How far are you willing to travel?</Text>
<Text style={styles.questions}>Distance chosen: {distance} miles</Text>
<View>
<Slider
value={distance}
onValueChange={setDistance}
maximumValue={50}
minimumValue={1}
step={1}
trackStyle={{ height: 10, backgroundColor: "transparent" }}
thumbStyle={{ height: 20, width: 20, backgroundColor: "transparent" }}
thumbProps={{
children: (
<Icon
name="tennisball-outline"
type="ionicon"
size={20}
reverse
containerStyle={{ bottom: 20, right: 20 }}
color="#92a835"
/>
),
}}
/>
</View>
<Text style={styles.questions}>What would you like your opponent hand to be?</Text>
<ButtonGroup
selectedButtonStyle={{ backgroundColor: '#55008c', color: 'white' }}
onPress={(selected) => {
setOpponentHand(selected);
}}
selectedIndex={opponentHand}
buttons={opponentHandButtons}
></ButtonGroup>
<Text style={styles.questions}>What ability would you like your opponent to be?</Text>
<ButtonGroup
selectedButtonStyle={{ backgroundColor: '#55008c', color: 'white' }}
onPress={(selected) => setOppoenentAbility(selected)}
selectMultiple={true}
selectedIndexes={opponentAbility}
buttons={abilityLevelButtons}
></ButtonGroup>
<Text style={styles.questions}>What group do you want to play in?</Text>
<ButtonGroup
selectedButtonStyle={{ backgroundColor: '#55008c', color: 'white' }}
onPress={(selected) => {
setGroup(selected);
}}
selectedIndex={group}
buttons={opponentGroupOptions}
></ButtonGroup>
<Text style={styles.questions}>Hope you find your match!</Text>
<Button
color='#55008c'
title="Save Preferences"
onPress={() => {
addPreferences(
profileInfo,
distance,
opponentAbility,
group,
opponentHand
);
console.log(profileInfo, Object.keys(profileInfo).length);
postNewUser(profileInfo);
navigation.navigate("Matches", profileInfo);
}}
/>
{/* this button first needs to send post request then navigate to matches */}
</ScrollView>
);
}
// have a submit button with disabled until preferences saved ??? ternary ???
export default AddPreferences;
const styles = StyleSheet.create({
questions: {
margin: 10,
fontSize: 18
}
})
/* <Button
title="Submit Profile"
disabled={!savedPreferences}
onPress={() => {
// PROBLEM : READ THE CONSOLE.LOG --> Only on second click of the submit button are matches posted
console.log(
"Here is the final object to post",
profileInfo,
Object.keys(profileInfo).length
);
}}
/> */