colouring-montreal/app/src/frontend/app.js

103 lines
3.8 KiB
JavaScript
Raw Normal View History

import React, { Fragment } from 'react';
import { Route, Switch } from 'react-router-dom';
import AboutPage from './about';
import BetaBanner from './beta-banner';
2018-09-10 18:34:56 -04:00
import BuildingEdit from './building-edit';
import BuildingView from './building-view';
import ColouringMap from './map';
import Header from './header';
2018-09-10 18:34:56 -04:00
import Legend from './legend';
import Login from './login';
2018-09-10 18:34:56 -04:00
import MyAccountPage from './my-account';
import SignUp from './signup';
import Welcome from './welcome';
import '../../node_modules/bootstrap/dist/css/bootstrap.min.css';
import './main.css'
class App extends React.Component {
constructor(props) {
super(props);
2018-09-10 18:34:56 -04:00
this.state = {
user: props.user,
building: props.building,
};
this.login = this.login.bind(this);
this.logout = this.logout.bind(this);
2018-09-10 18:34:56 -04:00
this.selectBuilding = this.selectBuilding.bind(this);
}
login(user) {
this.setState({user: user});
}
2018-09-10 18:34:56 -04:00
logout() {
this.setState({user: undefined});
}
2018-09-10 18:34:56 -04:00
selectBuilding(building) {
this.setState({building: building})
}
render() {
return (
<Fragment>
<BetaBanner />
<Header user={this.state.user} />
<main className="beta">
2018-09-10 07:41:00 -04:00
<Switch>
2018-09-10 18:34:56 -04:00
<Route path="/(map|building)?(/\w+)?(.html)?" render={props => (
2018-09-10 07:41:00 -04:00
<Fragment>
<Switch>
<Route exact path="/">
<Welcome />
</Route>
2018-09-10 18:34:56 -04:00
<Route exact path="/map/:map.html" component={Legend} />
<Route exact path="/building/:building.html">
2018-09-11 18:30:17 -04:00
<BuildingView {...this.state.building}
user={this.state.user}
selectBuilding={this.selectBuilding}
/>
2018-09-10 18:34:56 -04:00
</Route>
<Route exact path="/building/:building/edit.html">
2018-09-11 18:30:17 -04:00
<BuildingEdit {...this.state.building}
user={this.state.user}
selectBuilding={this.selectBuilding}
/>
2018-09-10 18:34:56 -04:00
</Route>
2018-09-10 07:41:00 -04:00
</Switch>
2018-09-10 18:34:56 -04:00
<ColouringMap {...props}
building={this.state.building}
2018-09-11 18:30:17 -04:00
selectBuilding={this.selectBuilding}
/>
2018-09-10 07:41:00 -04:00
</Fragment>
2018-09-10 17:14:09 -04:00
) } />
2018-09-10 07:41:00 -04:00
<Route exact path="/about.html" component={AboutPage} />
<Route exact path="/login.html">
<Login user={this.state.user} login={this.login} />
</Route>
<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} logout={this.logout} />
</Route>
<Route component={NotFound} />
</Switch>
</main>
</Fragment>
);
}
}
const NotFound = () => (
<article>
<section className="main-col">
<h1>Not found&hellip;</h1>
</section>
</article>
);
export default App;