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';
|
2018-09-09 17:22:44 -04:00
|
|
|
|
|
|
|
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';
|
2018-09-09 17:22:44 -04:00
|
|
|
import Header from './header';
|
2018-09-10 18:34:56 -04:00
|
|
|
import Legend from './legend';
|
2018-09-09 17:22:44 -04:00
|
|
|
import Login from './login';
|
2018-09-10 18:34:56 -04:00
|
|
|
import MyAccountPage from './my-account';
|
2018-09-09 17:22:44 -04:00
|
|
|
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,
|
|
|
|
};
|
2018-09-09 17:22:44 -04:00
|
|
|
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);
|
2018-09-09 17:22:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
login(user) {
|
2018-09-13 11:58:05 -04:00
|
|
|
console.log("Logging in")
|
|
|
|
console.log(user)
|
2018-09-09 17:22:44 -04:00
|
|
|
this.setState({user: user});
|
|
|
|
}
|
|
|
|
|
2018-09-10 18:34:56 -04:00
|
|
|
logout() {
|
2018-09-09 17:22:44 -04:00
|
|
|
this.setState({user: undefined});
|
|
|
|
}
|
|
|
|
|
2018-09-10 18:34:56 -04:00
|
|
|
selectBuilding(building) {
|
|
|
|
this.setState({building: building})
|
|
|
|
}
|
|
|
|
|
2018-09-09 17:22:44 -04:00
|
|
|
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>
|
2018-09-09 17:22:44 -04:00
|
|
|
</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>
|
2018-09-09 17:22:44 -04:00
|
|
|
</section>
|
|
|
|
</article>
|
|
|
|
);
|
|
|
|
|
|
|
|
export default App;
|