From 05604e32b6f18b0cd45a4459c5ff6cbca0276f03 Mon Sep 17 00:00:00 2001 From: Tom Russell Date: Mon, 10 Sep 2018 23:34:56 +0100 Subject: [PATCH] Select building, show view/edit --- app/src/frontend/app.js | 38 ++++++++++++++------ app/src/frontend/building-edit.js | 35 +++++++++--------- app/src/frontend/building-view.js | 59 ++++++++++++++++--------------- app/src/frontend/header.js | 4 +-- app/src/frontend/legend.js | 10 +++--- app/src/frontend/map.js | 33 ++++++++++------- app/src/frontend/welcome.js | 2 +- 7 files changed, 105 insertions(+), 76 deletions(-) diff --git a/app/src/frontend/app.js b/app/src/frontend/app.js index 13e4f557..b2080e3f 100644 --- a/app/src/frontend/app.js +++ b/app/src/frontend/app.js @@ -3,35 +3,45 @@ import { Route, Switch } from 'react-router-dom'; import AboutPage from './about'; import BetaBanner from './beta-banner'; -import Header from './header'; -import Login from './login'; +import BuildingEdit from './building-edit'; +import BuildingView from './building-view'; import ColouringMap from './map'; +import Header from './header'; +import Legend from './legend'; +import Login from './login'; +import MyAccountPage from './my-account'; import SignUp from './signup'; import Welcome from './welcome'; -import Legend from './legend'; import '../../node_modules/bootstrap/dist/css/bootstrap.min.css'; import './main.css' -import MyAccountPage from './my-account'; class App extends React.Component { constructor(props) { super(props); - this.state = { user: props.user }; + this.state = { + user: props.user, + building: props.building, + }; this.login = this.login.bind(this); this.logout = this.logout.bind(this); + this.selectBuilding = this.selectBuilding.bind(this); } login(user) { - console.log(user) this.setState({user: user}); } - logout(user) { + logout() { this.setState({user: undefined}); } + selectBuilding(building) { + console.log(building) + this.setState({building: building}) + } + render() { return ( @@ -39,15 +49,23 @@ class App extends React.Component {
- ( + ( - + + + + + + + - + ) } /> diff --git a/app/src/frontend/building-edit.js b/app/src/frontend/building-edit.js index c9c4aaac..c2cb5b48 100644 --- a/app/src/frontend/building-edit.js +++ b/app/src/frontend/building-edit.js @@ -1,6 +1,7 @@ import React from 'react'; +import { Link } from 'react-router-dom'; -const BuildingEdit = () => ( +const BuildingEdit = (props) => (

Edit building data

@@ -10,17 +11,17 @@ const BuildingEdit = () => ( data-toggle="collapse" data-target="#data-list-location">Location
- + - + - + - + - + - +
@@ -30,15 +31,15 @@ const BuildingEdit = () => ( data-toggle="collapse" data-target="#data-list-age">Age
- + - + - + - + - +
@@ -48,11 +49,11 @@ const BuildingEdit = () => ( data-toggle="collapse" data-target="#data-list-size">Size
- + - + - +
@@ -62,14 +63,14 @@ const BuildingEdit = () => ( data-toggle="collapse" data-target="#data-list-like">Like Me!
- +
- Cancel + Cancel
diff --git a/app/src/frontend/building-view.js b/app/src/frontend/building-view.js index dfd501fd..e947b3aa 100644 --- a/app/src/frontend/building-view.js +++ b/app/src/frontend/building-view.js @@ -1,30 +1,31 @@ import React from 'react'; +import { Link } from 'react-router-dom'; -const BuildingView = () => ( -
-

Building data

-
-

( +
+

Building data

+
+

Location

-

+

Section introduction of up to roughly 100 characters will take approx­imately this much space. Read more.

-
+
Building Name - + ? -
-
-
+
+
+
Hint tooltip content should be ~40 chars. @@ -32,24 +33,24 @@ const BuildingView = () => (
-
no data
+
no data
Building Number
-
no data
+
no data
Street
-
no data
+
no data
Address line 2
-
no data
+
no data
Town
-
no data
+
no data
Postcode
-
no data
+
no data
-
-

+

Age

-
+
Year built (best estimate)
2018
Year built (lower estimate)
@@ -62,11 +63,11 @@ const BuildingView = () => (
2018
-
-

+

Size

-
+
Attic storeys
0
Core storeys
@@ -75,18 +76,18 @@ const BuildingView = () => (
1
-
-

Like Me!

-
+
Likes
25
-
- Back to maps - Edit data +
+ Back to maps + Edit data
); diff --git a/app/src/frontend/header.js b/app/src/frontend/header.js index 25440d17..898dbe78 100644 --- a/app/src/frontend/header.js +++ b/app/src/frontend/header.js @@ -15,7 +15,7 @@ function Header(props) {
  • - View Maps + View Maps
  • About @@ -34,7 +34,7 @@ function Header(props) {
    • - View Maps + View Maps
    • About diff --git a/app/src/frontend/legend.js b/app/src/frontend/legend.js index bccb9360..bc98375f 100644 --- a/app/src/frontend/legend.js +++ b/app/src/frontend/legend.js @@ -64,7 +64,7 @@ const LegendItem = (props) => ( const LegendSection = (props) => (
      - { props.label } + { props.label }
        @@ -76,7 +76,7 @@ const LegendSection = (props) => ( const LegendGroup = (props) => (
        - +

        { props.label }

        @@ -97,15 +97,15 @@ class Legend extends Component {

        Maps

        { data_map.map((data_group) => ( - + { ( data_layer.match(data_group.slug) ) ? data_group.elements.map((data_section) => ( - + { ( data_layer.match(data_section.slug) ) ? data_section.elements.map((data_item) => ( - + )) : null } diff --git a/app/src/frontend/map.js b/app/src/frontend/map.js index 53fafda5..debd4f73 100644 --- a/app/src/frontend/map.js +++ b/app/src/frontend/map.js @@ -16,8 +16,7 @@ class ColouringMap extends Component { this.state = { lat: 51.5245255, lng: -0.1338422, - zoom: 16, - highlight: undefined + zoom: 16 }; this.handleClick = this.handleClick.bind(this); } @@ -26,26 +25,34 @@ class ColouringMap extends Component { var lat = e.latlng.lat var lng = e.latlng.lng fetch( - '/buildings?lat='+lat+'&lng='+lng + '/buildings.json?lat='+lat+'&lng='+lng ).then( (res) => res.json() ).then(function(data){ - console.log(data) - if (data.geometry_id){ - this.setState({highlight: data.geometry_id}); + if (data.geometry_id && data.id){ + this.props.history.push(`/building/${data.id}.html`); + this.props.selectBuilding(data); } else { - this.setState({highlight: undefined}); + // this.props.selectBuilding(undefined); } - }.bind(this)) + }.bind(this)).catch( + (err) => console.error(err) + ) } render() { + var map_type = undefined; + if (this.props.match && this.props.match.params && this.props.match.params[0]) { + map_type = this.props.match.params[0].replace("/", ""); + } else { + map_type = 'maps'; + } var data_layer = undefined; if (this.props.match && this.props.match.params && this.props.match.params[1]) { data_layer = this.props.match.params[1].replace("/", ""); } else { - data_layer = 'outline'; + data_layer = 'date_year'; } const position = [this.state.lat, this.state.lng]; @@ -56,9 +63,11 @@ 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.' const colour = `/tiles/${data_layer}/{z}/{x}/{y}.png`; - const highlight = `/tiles/highlight/{z}/{x}/{y}.png?highlight=${this.state.highlight}` - const highlightLayer = this.state.highlight ? ( - + + const geometry_id = (this.props.building) ? this.props.building.geometry_id : undefined; + const highlight = `/tiles/highlight/{z}/{x}/{y}.png?highlight=${geometry_id}` + const highlightLayer = this.props.building ? ( + ) : null; return ( diff --git a/app/src/frontend/welcome.js b/app/src/frontend/welcome.js index 5dd65d76..85a21aca 100644 --- a/app/src/frontend/welcome.js +++ b/app/src/frontend/welcome.js @@ -7,7 +7,7 @@ const Welcome = () => (

        Welcome to Colouring London

        Colour in, view and download data on London's buildings

        - Start Colouring