-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathloading.js
118 lines (101 loc) · 2.6 KB
/
loading.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
import React, {Component} from "react";
import {View, Text, ActivityIndicator, StyleSheet} from "react-native";
import {connect} from "react-redux";
import {setLoadingStatusLoaded} from "./actions";
import {getVehiclePoints, getStopPoints} from "./selectors";
export class Loading extends Component {
state = {
loading: true
};
loadingStatus = 0;
constructor(props) {
super(props);
}
componentDidUpdate() {
if (!this.state.loading || !this.props.totals) {
return;
}
let thingsLoaded =
this.props.stopPoints.features.length +
(this.props.routeShapes && this.props.routeShapes.length);
let totalThingsToLoad =
this.props.totals.stops + this.props.totals.route_shapes;
this.loadingStatus = Math.min(
Math.floor(thingsLoaded / totalThingsToLoad * 100),
100
);
if (this.props.stopPoints.features.length < this.props.totals.stops) {
return;
}
if (
!this.props.routeShapes ||
this.props.routeShapes.length < this.props.totals.route_shapes
) {
return;
}
// We don't need to wait until all the vehicles are loaded, just
// until we get the first response.
if (!this.props.receivedVehicles) {
return;
}
this.props.onLoadComplete();
this.setState({
loading: false
});
}
render() {
if (!this.props.connected) {
return (
<View style={styles.container}>
<ActivityIndicator
animating={this.state.loading}
size="small"
color="#FFFFFF"
/>
<Text style={[styles.text]}>Connecting to server...</Text>
</View>
);
}
return (
<View style={styles.container}>
<ActivityIndicator
animating={this.state.loading}
size="small"
color="#FFFFFF"
/>
<Text style={[styles.text, {opacity: this.state.loading ? 1 : 0}]}>
Loading GTFS data...
</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
alignItems: "flex-start",
flex: 1,
flexDirection: "row",
justifyContent: "center"
},
text: {
color: "#ecf0f1",
marginLeft: 10
}
});
function mapDispatchToProps(dispatch) {
return {
onLoadComplete: items => {
dispatch(setLoadingStatusLoaded());
}
};
}
function mapStateToProps(state) {
return {
connected: state.connected,
receivedVehicles: state.receivedVehicles,
routeShapes: state.routeShapes,
stopPoints: getStopPoints(state),
totals: state.totals
};
}
export default connect(mapStateToProps, mapDispatchToProps)(Loading);