Refactor top-level routing

This commit is contained in:
Tom Russell 2018-10-03 21:46:51 +01:00
parent b180602a5b
commit 3539e1126c
2 changed files with 38 additions and 46 deletions

View File

@ -54,41 +54,38 @@ class App extends React.Component {
<BetaBanner />
<Header user={this.state.user} />
<main className="beta">
<Switch>
<Route path="/(map|building)?(/\w+)?(.html)?" render={(props) => (
<Fragment>
<TransitionGroup>
<CSSTransition timeout={3000} classNames='fade' key={props.location.key}>
<Switch location={props.location}>
<CSSTransition timeout={3000} classNames='fade'>
<Switch>
<Route exact path="/">
<Welcome />
</Route>
<Route exact path="/map/:map.html" component={Legend} />
<Route exact path="/building/:building.html">
<Route exact path="/building/:building.html" render={(props) => (
<BuildingView
{...props}
{...this.state.building}
{...props} // includes route history/match
user={this.state.user}
selectBuilding={this.selectBuilding}
/>
</Route>
<Route exact path="/building/:building/edit.html">
) } />
<Route exact path="/building/:building/edit.html" render={(props) => (
<BuildingEdit
{...props}
{...this.state.building}
{...props} // includes route history/match
user={this.state.user}
selectBuilding={this.selectBuilding}
/>
</Route>
) } />
</Switch>
</CSSTransition>
</TransitionGroup>
<Switch>
<Route exact path="/(map.*|building.*)?" render={(props) => (
<ColouringMap
{...props}
building={this.state.building}
selectBuilding={this.selectBuilding}
/>
</Fragment>
) } />
<Route exact path="/about.html" component={AboutPage} />
<Route exact path="/login.html">
@ -110,7 +107,7 @@ class App extends React.Component {
const NotFound = () => (
<article>
<section className="main-col">
<h1 class="h1">Page not found</h1>
<h1 className="h1">Page not found</h1>
<p className="lead">
We can't find that one anywhere.

View File

@ -63,17 +63,12 @@ class ColouringMap extends Component {
const attribution = 'Building attribute data is © Colouring London contributors. Maps contain OS data © Crown copyright: OS Maps baselayers and building outlines.'
// colour-data tiles
var data_tileset, is_building;
if (this.props.match && this.props.match.params && this.props.match.params[1]) {
data_tileset = this.props.match.params[1].replace("/", "")
is_building = this.props.match.params[0] === 'building'
} else {
is_building = false;
data_tileset = 'date_year';
}
const dataLayer = !is_building ? (
<TileLayer key={data_tileset} url={`/tiles/${data_tileset}/{z}/{x}/{y}.png`} />
) : null;
const is_building = /building/.test(this.props.match.url)
const themer = /theme=([^&]*)/
const data_tileset = themer.test(this.props.match.url)? themer.exec(this.props.match.url)[1] : 'date_year';
console.log(is_building, data_tileset)
const dataLayer = <TileLayer key={data_tileset} url={`/tiles/${data_tileset}/{z}/{x}/{y}.png`} />;
// highlight
const geometry_id = (this.props.building) ? this.props.building.geometry_id : undefined;