2018-09-09 17:22:44 -04:00
|
|
|
import React, { Fragment } from 'react';
|
2018-09-13 15:41:42 -04:00
|
|
|
import { Route, Switch, Link } from 'react-router-dom';
|
2019-05-27 13:26:29 -04:00
|
|
|
import PropTypes from 'prop-types';
|
2018-09-09 17:22:44 -04:00
|
|
|
|
2018-09-17 16:27:52 -04:00
|
|
|
import '../../node_modules/bootstrap/dist/css/bootstrap.min.css';
|
2018-10-20 06:33:27 -04:00
|
|
|
import './app.css';
|
2018-09-17 16:27:52 -04:00
|
|
|
|
2018-09-09 17:22:44 -04:00
|
|
|
import Header from './header';
|
|
|
|
|
2019-08-14 03:37:27 -04:00
|
|
|
import AboutPage from './pages/about';
|
|
|
|
import ContributorAgreementPage from './pages/contributor-agreement';
|
|
|
|
import PrivacyPolicyPage from './pages/privacy-policy';
|
|
|
|
|
2019-08-14 04:02:57 -04:00
|
|
|
import Login from './user/login';
|
|
|
|
import MyAccountPage from './user/my-account';
|
|
|
|
import SignUp from './user/signup';
|
2019-08-23 09:16:40 -04:00
|
|
|
import ForgottenPassword from './user/forgotten-password';
|
|
|
|
import PasswordReset from './user/password-reset';
|
2019-08-14 04:02:57 -04:00
|
|
|
|
2019-09-08 20:09:05 -04:00
|
|
|
import MapApp from './map-app';
|
|
|
|
|
|
|
|
|
|
|
|
interface AppProps {
|
|
|
|
user?: any;
|
|
|
|
building?: any;
|
|
|
|
building_like?: boolean;
|
|
|
|
}
|
2019-08-14 03:37:27 -04:00
|
|
|
|
2019-02-05 16:41:31 -05:00
|
|
|
/**
|
|
|
|
* App component
|
|
|
|
*
|
|
|
|
* This is the top-level stateful frontend component
|
|
|
|
* - rendered from props, instantiated either server-side in server.js or client-side in
|
|
|
|
* client.js
|
|
|
|
* - state (including user, current building) is initialised from props
|
|
|
|
* - callbacks to update top-level state are passed down to subcomponents
|
|
|
|
* - render method wraps a react-router switch - this drives which version of the sidebar and
|
|
|
|
* map or other pages are rendered, based on the URL. Use a react-router-dom <Link /> in
|
|
|
|
* child components to navigate without a full page reload.
|
|
|
|
*/
|
2019-09-08 20:09:05 -04:00
|
|
|
class App extends React.Component<AppProps, any> { // TODO: add proper types
|
2019-08-09 13:49:43 -04:00
|
|
|
static propTypes = { // TODO: generate propTypes from TS
|
|
|
|
user: PropTypes.object,
|
|
|
|
building: PropTypes.object,
|
|
|
|
building_like: PropTypes.bool
|
2019-09-08 20:09:05 -04:00
|
|
|
};
|
2019-08-09 13:49:43 -04:00
|
|
|
|
2019-09-08 20:09:05 -04:00
|
|
|
constructor(props: Readonly<AppProps>) {
|
2018-09-09 17:22:44 -04:00
|
|
|
super(props);
|
2019-09-08 20:09:05 -04:00
|
|
|
|
2018-09-10 18:34:56 -04:00
|
|
|
this.state = {
|
2019-09-08 20:09:05 -04:00
|
|
|
user: props.user
|
2018-09-10 18:34:56 -04:00
|
|
|
};
|
2018-09-09 17:22:44 -04:00
|
|
|
this.login = this.login.bind(this);
|
2018-10-20 07:20:10 -04:00
|
|
|
this.updateUser = this.updateUser.bind(this);
|
2018-09-09 17:22:44 -04:00
|
|
|
this.logout = this.logout.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
login(user) {
|
2018-09-30 15:28:33 -04:00
|
|
|
if (user.error) {
|
|
|
|
this.logout();
|
2019-09-08 20:09:05 -04:00
|
|
|
return;
|
2018-09-30 15:28:33 -04:00
|
|
|
}
|
2018-09-09 17:22:44 -04:00
|
|
|
this.setState({user: user});
|
|
|
|
}
|
|
|
|
|
2018-10-20 07:20:10 -04:00
|
|
|
updateUser(user){
|
|
|
|
this.setState({user: { ...this.state.user, ...user }});
|
|
|
|
}
|
|
|
|
|
2018-09-10 18:34:56 -04:00
|
|
|
logout() {
|
2018-09-09 17:22:44 -04:00
|
|
|
this.setState({user: undefined});
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<Fragment>
|
2019-08-14 14:33:26 -04:00
|
|
|
<Header user={this.state.user} />
|
|
|
|
<main>
|
|
|
|
<Switch>
|
|
|
|
<Route exact path="/about.html" component={AboutPage} />
|
|
|
|
<Route exact path="/login.html">
|
|
|
|
<Login user={this.state.user} login={this.login} />
|
|
|
|
</Route>
|
|
|
|
<Route exact path="/forgotten-password.html" component={ForgottenPassword} />
|
|
|
|
<Route exact path="/password-reset.html" component={PasswordReset} />
|
|
|
|
<Route exact path="/sign-up.html">
|
|
|
|
<SignUp user={this.state.user} login={this.login} />
|
|
|
|
</Route>
|
|
|
|
<Route exact path="/my-account.html">
|
|
|
|
<MyAccountPage
|
|
|
|
user={this.state.user}
|
|
|
|
updateUser={this.updateUser}
|
|
|
|
logout={this.logout}
|
|
|
|
/>
|
|
|
|
</Route>
|
|
|
|
<Route exact path="/privacy-policy.html" component={PrivacyPolicyPage} />
|
|
|
|
<Route exact path="/contributor-agreement.html" component={ContributorAgreementPage} />
|
2019-09-08 20:09:05 -04:00
|
|
|
<Route exact path="/:mode?/:category?/:building?" render={(props) => (
|
|
|
|
<MapApp
|
|
|
|
{...props}
|
|
|
|
building={this.props.building}
|
|
|
|
building_like={this.props.building_like}
|
|
|
|
user={this.state.user}
|
|
|
|
/>
|
|
|
|
)} />
|
2019-08-14 14:33:26 -04:00
|
|
|
<Route component={NotFound} />
|
|
|
|
</Switch>
|
|
|
|
</main>
|
2018-09-09 17:22:44 -04:00
|
|
|
</Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2019-02-05 16:41:31 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Component to fall back on in case of 404 or no other match
|
|
|
|
*/
|
2018-09-09 17:22:44 -04:00
|
|
|
const NotFound = () => (
|
|
|
|
<article>
|
|
|
|
<section className="main-col">
|
2018-10-03 16:46:51 -04:00
|
|
|
<h1 className="h1">Page not found</h1>
|
2018-09-13 15:41:42 -04:00
|
|
|
<p className="lead">
|
|
|
|
|
2019-05-27 11:23:58 -04:00
|
|
|
We can’t find that one anywhere.
|
2018-09-13 15:41:42 -04:00
|
|
|
|
|
|
|
</p>
|
|
|
|
<Link className="btn btn-outline-dark" to="/">Back home</Link>
|
2018-09-09 17:22:44 -04:00
|
|
|
</section>
|
|
|
|
</article>
|
|
|
|
);
|
|
|
|
|
|
|
|
export default App;
|