-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
227 lines (183 loc) · 5.72 KB
/
App.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
import { StatusBar } from "expo-status-bar";
import * as React from "react";
import { tabContext } from "./tabContext";
import RootStackScreen from "./navigation/RootStackScreen";
import AsyncStorage from "@react-native-async-storage/async-storage";
import Axios from 'axios';
import {
StyleSheet,
Text,
View,
Image,
TextInput,
Button,
TouchableOpacity,
} from "react-native";
import { NavigationContainer } from "@react-navigation/native";
export default function App() {
const [status, setStatus] = React.useState(null)
const [points, setPoints] = React.useState(0)
const [email, setEmail] = React.useState(0)
const [username, setUsername] = React.useState(0)
const [items, setItems] = React.useState(null)
const [eventEndTIme, setEventEndTime] = React.useState(0)
const [friends, setFriends] = React.useState([]);
const [requests, setRequests] = React.useState([]);
const [modalVis, setModalVis] = React.useState(true);
// Ask about this
// 6e930c12dc934cbd849bd2be
const statusColours = {
Healthy: "#05cf02",
Infected: "#f52718",
Immune: "#0aefff",
};
const screenColors = statusColours[status];
const getUserInventory = (email) => {
Axios.post("https://deco3801-betterlatethannever.uqcloud.net/user/getUserInventory", {
email: email,
}).then((response) => {
if (response.data.message) {
console.log("Couldn't get items")
} else {
const userInventory = []
console.log(response.data.items)
response.data.items.forEach(element => {
console.log(element.ItemID)
});
}
}).catch((error) => {
// console.log(error)
});
}
const updateStatusDB = (status) => {
Axios.post("https://deco3801-betterlatethannever.uqcloud.net/user/updateStatus", {
email: email,
infectionStatus: status,
}).then((response) => {
console.log("Here!")
if (response.data.message) {
alert('Status fail')
} else {
console.log("New Status: "+status)
alert('Status success')
}
}).catch((error) => {
// console.log(error)
});
}
const updatePointsDB = async (points) => {
console.log("These are the points going in: "+points)
await Axios.post("https://deco3801-betterlatethannever.uqcloud.net/user/updatePoints", {
email: email,
points: points,
}).then((response) => {
console.log("Points request made!")
if (response.data.message) {
alert('Points fail')
} else {
console.log("New Points again: "+points)
alert('Points success')
}
}).catch((error) => {
console.log("ERROR WITH POINTS UPDATE 1")
});
}
const updateDailyBD = () => {
Axios.post("https://deco3801-betterlatethannever.uqcloud.net/user/updateDaily", {
email: email,
}).then((response) => {
if (response.data.message) {
alert('Daily fail')
} else {
//alert('Daily success')
}
}).catch((error) => {
// console.log(error)
});;
}
const set_active_email = (userEmail) => {
setEmail(userEmail)
}
const set_active_username = (userName) => {
setUsername(userName)
}
const statusChange = async (new_status) => {
try {
await AsyncStorage.setItem("status", new_status)
setStatus(new_status)
updateStatusDB(new_status)
console.log("Status Change")
} catch(e) {
alert("Couldn't change the status")
}
}
const updateStatus = async (new_status) => {
try {
await AsyncStorage.setItem("status", new_status)
setStatus(new_status)
//updateStatusDB(new_status)
} catch(e) {
alert("Error updating status")
}
}
const addPoints = (new_points) => {
console.log(new_points, typeof(new_points))
try {
const value = parseInt(points) + new_points
// console.log(new_points)
// console.log(value)
//await AsyncStorage.setItem("points", JSON.stringify(value))
setPoints(value)
updatePointsDB(value)
} catch(e) {
alert("TROUBLE ADDING POINTS")
}
}
const updatePoints = async (new_points) => {
try {
//console.log(new_points)
await AsyncStorage.setItem("points", JSON.stringify(new_points))
setPoints(new_points)
//console.log(points)
//updatePointsDB(new_points)
} catch(e) {
alert("TROUBLE ADDING POINTS")
}
};
//Gets a user's current friend list
const myFriends = (getUserFriends) => {
Axios.post(
"https://deco3801-betterlatethannever.uqcloud.net/friends/approved",
{
username: getUserFriends,
}
).then((response) => {
console.log(email);
console.log(response.data);
setFriends(response.data.friends);
});
};
//Shows the requests a user currently has from others.
const showRequests = (getUserReq) => {
Axios.post(
"https://deco3801-betterlatethannever.uqcloud.net/friends/requested",
{
username: getUserReq,
}
).then((response) => {
console.log(response.data);
setRequests(response.data.friends);
});
};
return (
<tabContext.Provider value={{items, status, points, email, username, eventEndTIme, screenColors, setEventEndTime, setItems,
updateStatus, statusChange, updatePoints, addPoints, set_active_email, set_active_username, updateDailyBD, friends,
setFriends, myFriends, requests, setRequests, showRequests, modalVis, setModalVis}}>
<StatusBar style="dark" />
<NavigationContainer>
<RootStackScreen />
</NavigationContainer>
</tabContext.Provider>
);
}
const styles = StyleSheet.create({});