import React, { Fragment } from 'react';
import { Route, Switch, Link } from 'react-router-dom';
import PropTypes from 'prop-types';
import '../../node_modules/bootstrap/dist/css/bootstrap.min.css';
import './app.css';
import Header from './header';
import AboutPage from './pages/about';
import ContributorAgreementPage from './pages/contributor-agreement';
import PrivacyPolicyPage from './pages/privacy-policy';
import DataExtracts from './data-extracts';
import Login from './user/login';
import MyAccountPage from './user/my-account';
import SignUp from './user/signup';
import ForgottenPassword from './user/forgotten-password';
import PasswordReset from './user/password-reset';
import MapApp from './map-app';
interface AppProps {
user?: any;
building?: any;
building_like?: boolean;
}
/**
* 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 in
* child components to navigate without a full page reload.
*/
class App extends React.Component { // TODO: add proper types
static propTypes = { // TODO: generate propTypes from TS
user: PropTypes.object,
building: PropTypes.object,
building_like: PropTypes.bool
};
constructor(props: Readonly) {
super(props);
this.state = {
user: props.user
};
this.login = this.login.bind(this);
this.updateUser = this.updateUser.bind(this);
this.logout = this.logout.bind(this);
}
login(user) {
if (user.error) {
this.logout();
return;
}
this.setState({user: user});
}
updateUser(user){
this.setState({user: { ...this.state.user, ...user }});
}
logout() {
this.setState({user: undefined});
}
render() {
return (
(
)} />
);
}
}
/**
* Component to fall back on in case of 404 or no other match
*/
const NotFound = () => (