This repository was archived by the owner on Feb 28, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathAppContainer.js
More file actions
169 lines (135 loc) · 4.21 KB
/
Copy pathAppContainer.js
File metadata and controls
169 lines (135 loc) · 4.21 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
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
// import React/Redux dependencies
import React, { Component } from "react";
import { Route } from "react-router";
import { connect } from "react-redux";
import PropTypes from "prop-types";
import { loadResources } from "../action/resourceDataAction";
import { getAllSites } from "../api/directoryGoogleSheets";
// import components
import Header from "../components/Header/Header";
import MapPage from "../components/MapPage/MapPage";
import AdminPage from "../components/AdminPage/AdminPage";
import { SplitScreenTogglePane } from "../components/AdminPage/SplitScreenTogglePane";
import SavedResourcePanel from "../components/SavedResources/SavedResourcePanel";
import NotFoundPage from "../components/NotFoundPage/NotFoundPage";
import { Loading } from "../components/Common/Loading";
import { FeedbackContainer } from "../components/Common/FeedbackContainer";
import LandingPage from '../components/LandingPage/LandingPage';
// import Button from '../components/Button/Button'
const envSheetId = process.env.REACT_APP_GOOGLE_SHEETS_ID;
// unused code
// const revereSheetId = '1QolGVE4wVWSKdiWeMaprQGVI6MsjuLZXM5XQ6mTtONA';
function sheetIdFromPath(directory, path) {
for (let i = 0; i < directory.length; i++) {
if (directory[i].path === path) {
return directory[i].sheetId;
}
}
}
class AppContainer extends Component {
constructor(props) {
super(props);
this.state = {
position: {},
displayFeedbackLink: true,
isValidPage: true
};
}
static propTypes = {
dispatch: PropTypes.func
};
componentDidMount() {
const resourcePath = this.props.match.params.resource;
let resourceSheetId = null;
getAllSites.then(sites => {
resourceSheetId = sheetIdFromPath(sites, resourcePath) || envSheetId;
if (resourceSheetId == null) {
this.setState({ isValidPage: false });
} else {
const resourcesFromSheet = loadResources(resourceSheetId);
this.props.dispatch(resourcesFromSheet);
}
});
this.getLocation();
}
hideFeedbackLink = () => {
this.setState({ displayFeedbackLink: false });
};
getLocation = () => {
if (window.navigator.geolocation) {
window.navigator.geolocation.getCurrentPosition(
position => {
this.setState({
position: {
coordinates: {
lat: parseFloat(position.coords.latitude),
lng: parseFloat(position.coords.longitude)
}
}
});
},
error => {
console.log(error);
}
);
}
};
toggleSavedResourcesPane = () => {
this.setState({
isSavedResourcePaneOpen: !this.state.isSavedResourcePaneOpen
});
};
goToResources = () => {
this.setState({
landingPage: false
})
}
render() {
const { isFetchingResource } = this.props;
if (!this.state.isValidPage) {
return <NotFoundPage />;
}
if (isFetchingResource) {
return <Loading />;
}
return (
<div className="viewport" >
<div>
<div className="viewport-header">
<Header toggleSavedResourcesPane={this.toggleSavedResourcesPane} />
</div>
<div className="page">
<Route
exact
path="/:resource/admin"
render={() => <AdminPage currentPosition={this.state.position} />}
/>
<Route
exact
path="/:resource/"
render={() => (
<MapPage
currentPosition={this.state.position}
displayFeedbackLink={this.state.displayFeedbackLink}
/>
)}
/>
<SplitScreenTogglePane isOpen={this.state.isSavedResourcePaneOpen}>
<SavedResourcePanel
resourcePath={this.props.match.params.resource}
/>
</SplitScreenTogglePane>
</div>
{this.state.displayFeedbackLink && (
<FeedbackContainer hideFeedbackLink={this.hideFeedbackLink} />
)}
</div>
</div>
);
}
}
function mapStateToProps(state) {
const { isFetchingResource } = state;
return { isFetchingResource };
}
export default connect(mapStateToProps)(AppContainer);