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

120 lines
4.7 KiB
JavaScript
Raw Normal View History

import React, { Fragment } from 'react';
2018-09-13 15:41:42 -04:00
import { Route, Switch, Link } from 'react-router-dom';
2018-09-13 17:13:53 -04:00
import { TransitionGroup, CSSTransition } from 'react-transition-group'
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) {
2018-09-13 11:58:05 -04:00
console.log("Logging in")
console.log(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-13 17:13:53 -04:00
<Route path="/(map|building)?(/\w+)?(.html)?" render={(props) => (
2018-09-10 07:41:00 -04:00
<Fragment>
2018-09-13 17:13:53 -04:00
<TransitionGroup>
<CSSTransition timeout={3000} classNames='fade' key={props.location.key}>
<Switch location={props.location}>
<Route exact path="/">
<Welcome />
</Route>
<Route exact path="/map/:map.html" component={Legend} />
<Route exact path="/building/:building.html">
2018-09-13 18:55:53 -04:00
<BuildingView
{...this.state.building}
user={this.state.user}
selectBuilding={this.selectBuilding}
/>
2018-09-13 17:13:53 -04:00
</Route>
<Route exact path="/building/:building/edit.html">
2018-09-13 18:55:53 -04:00
<BuildingEdit
{...this.state.building}
{...props} // includes route history/match
user={this.state.user}
selectBuilding={this.selectBuilding}
/>
2018-09-13 17:13:53 -04:00
</Route>
</Switch>
</CSSTransition>
</TransitionGroup>
2018-09-13 18:55:53 -04:00
<ColouringMap
{...props}
building={this.state.building}
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">
2018-09-13 15:41:42 -04:00
<h1 class="h1">Page not found</h1>
<p className="lead">
We can't find that one anywhere.
</p>
<Link className="btn btn-outline-dark" to="/">Back home</Link>
</section>
</article>
);
export default App;