forked from binevolent/TrashApp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
96 lines (80 loc) · 2.32 KB
/
Copy pathApp.js
File metadata and controls
96 lines (80 loc) · 2.32 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
import React from "react";
import { View, Text } from "react-native";
import HomeScreen from "./src/HomeScreen";
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
// [{"id":1,"username":"Anna","age":25,"address":"20 Apple Street","points":2}]
user: {
id: 1,
username: "Anna2",
age: 25,
address: "20 Apple Street",
points: 34
},
// [{id, lat, lon, name, description, max_weight, current_weight},...]
bins: [
{
id: 0,
lat: 0,
lon: 0,
name: "wow",
description: "wowee",
max_weight: 10,
current_weight: 5
}
],
recycleCount: 0,
depositCount: 0
};
}
componentWillMount() {
fetch("http://trash.imkevinvo.com:5000/user/1")
.then(response => {
response.json().then(data => {
this.parseUserInformation(data);
});
})
.catch(error => {
console.log(error);
});
fetch("http://trash.imkevinvo.com:5000/all_bins")
.then(response => {
response.json().then(data => {
this.parseBinInformation(data);
});
})
.catch(error => {
console.log(error);
});
}
render() {
return <HomeScreen {...this.state} addPoints={(pointsAdded) => {this.addPoints(pointsAdded)}}
addRecycleCount={(recycleAdded) => {this.addRecycleCount(recycleAdded)}}
incrementDepositCount={() => {this.incrementDepositCount()}}
/>;
}
incrementDepositCount() {
this.setState({depositCount:(this.state.depositCount+1)});
}
addRecycleCount(recycleAdded) {
const newRecycleCount = this.state.recycleCount + recycleAdded;
this.setState({recycleCount : newRecycleCount});
}
addPoints(pointsAdded) {
const newUser = this.state.user;
const newPoints = Number.parseInt(newUser.points) + Number.parseInt(pointsAdded);
newUser.points = newPoints;
this.setState({user: newUser});
}
parseUserInformation(data) {
// [{"id":1,"username":"Anna","age":25,"address":"20 Apple Street","points":2}]
this.setState({ user: data[0] });
}
parseBinInformation(data) {
// [{id, lat, lon, name, description, max_weight, current_weight},...]
this.setState({ bins: data });
}
}
export default App;