forked from stephenpassero/parkingAssistant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
92 lines (82 loc) · 2.17 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
import React from 'react';
import Navigator from './utils/Navigator'
import Alerts from './utils/Alerts'
import StreetParkingSpot from './models/StreetParkingSpot'
import CompassView from './views/CompassView'
import HomeView from './views/HomeView'
import ParkedView from './views/ParkedView'
import { Text, View } from "react-native";
export default class App extends React.Component {
constructor(props){
super(props)
this._alerts = new Alerts()
this.state = {
location: false,
heading: false,
parkingSpot: false
}
}
setLocation(position) {
this.setState(() => {
return {
position: position
}
})
}
setHeading(newHeading) {
this.setState(() => {
return {
heading: newHeading
}
})
}
cancelCountdown(){
this._alerts.cancelScheduledAlerts()
this.setState(() => {
return {
position: false,
heading: false,
parkingSpot: false
}
})
}
setParkingSpot(newParkingSpot) {
this.setState(() => {
return {
parkingSpot: newParkingSpot
}
})
}
componentDidUpdate(prevProps, prevState) {
if (this.state.position && this.state.heading && !this.state.parkingSpot) {
const spot = this._makeParkingSpot()
spot.initialize().then(() => this.setParkingSpot(spot))
}
}
_makeParkingSpot() {
const coordinatesWithHeading = Object.assign(
{},
this.state.position.coords,
{ heading: this.state.heading }
)
return new StreetParkingSpot(coordinatesWithHeading, new Navigator(), this._alerts)
}
render() {
if(this.state.position && !this.state.heading) {
return (
<CompassView setHeading={this.setHeading.bind(this)}/>
)
} else if (this.state.position && this.state.heading && !this.state.parkingSpot) {
return <View/>
} else if (this.state.parkingSpot){
return (
<ParkedView cancel={this.cancelCountdown.bind(this)}
parkingSpot={this.state.parkingSpot}/>
)
} else if (!this.state.position && !this.state.heading) {
return (
<HomeView setLocation={this.setLocation.bind(this)}/>
)
}
}
}