diff --git a/app/src/frontend/app.js b/app/src/frontend/app.js index 02d00e5b..32949f09 100644 --- a/app/src/frontend/app.js +++ b/app/src/frontend/app.js @@ -1,6 +1,7 @@ import React, { Fragment } from 'react'; import { Route, Switch, Link } from 'react-router-dom'; import PropTypes from 'prop-types'; +import { parse } from 'query-string'; import '../../node_modules/bootstrap/dist/css/bootstrap.min.css'; import './app.css'; @@ -16,6 +17,7 @@ import Login from './login'; import MyAccountPage from './my-account'; import SignUp from './signup'; import Welcome from './welcome'; +import { parseCategoryURL } from '../parse'; /** * App component @@ -116,9 +118,44 @@ class App extends React.Component { } colourBuilding(building) { - fetch(`/building/${building.building_id}.json`, { + const cat = parseCategoryURL(window.location.pathname); + const q = parse(window.location.search); + let data; + if (cat === 'like'){ + data = {like: true} + this.likeBuilding(building.building_id) + } else { + data = {} + data[q.k] = q.v; + this.updateBuilding(building.building_id, data) + } + } + + likeBuilding(building_id) { + fetch(`/building/${building_id}/like.json`, { method: 'POST', - body: JSON.stringify({date_year: 1999}), // TODO link to multi/pass in data + headers:{ + 'Content-Type': 'application/json' + }, + credentials: 'same-origin', + body: JSON.stringify({like: true}) + }).then( + res => res.json() + ).then(function(res){ + if (res.error) { + console.error({error: res.error}) + } else { + this.increaseRevision(res.revision_id); + } + }.bind(this)).catch( + (err) => console.error({error: err}) + ); + } + + updateBuilding(building_id, data){ + fetch(`/building/${building_id}.json`, { + method: 'POST', + body: JSON.stringify(data), headers:{ 'Content-Type': 'application/json' }, @@ -129,7 +166,6 @@ class App extends React.Component { if (res.error) { console.error({error: res.error}) } else { - console.log(res); this.increaseRevision(res.revision_id); } }).catch( diff --git a/app/src/frontend/building-edit.js b/app/src/frontend/building-edit.js index 7d7d42ec..b8f06321 100644 --- a/app/src/frontend/building-edit.js +++ b/app/src/frontend/building-edit.js @@ -19,7 +19,7 @@ const BuildingEdit = (props) => { return ( -
+
Back to maps
@@ -172,7 +172,9 @@ class EditForm extends Component { render() { const match = this.props.cat === this.props.slug; + const cat = this.props.cat; const buildingLike = this.props.building_like; + return (
@@ -204,61 +206,62 @@ class EditForm extends Component {
{ - match? ( - !this.props.inactive? -
- { - this.props.slug === 'location'? - - : null - } - - { - this.props.fields.map((props) => { - switch (props.type) { - case 'text': - return - case 'text_list': - return - case 'text_long': - return - case 'number': - return - case 'year_estimator': - return - case 'text_multi': - return - case 'checkbox': - return - case 'like': - return + { + this.props.slug === 'location'? + + : null + } + + { + this.props.fields.map((props) => { + switch (props.type) { + case "text": + return + case "text_list": + return + case "text_long": + return + case "number": + return + case "year_estimator": + return + case "text_multi": + return + case "checkbox": + return + case "like": + return - default: - return null - } - }) + value={this.state[props.slug]} key={props.slug} cat={cat} /> + default: + return null } - - - { - (this.props.slug === 'like')? // special-case for likes - null : -
- -
- } - - :
- ) : null + }) + } + + { + (this.props.slug === 'like')? // special-case for likes + null : +
+ +
+ } + + :
+ + + ) : null }
) @@ -281,7 +284,10 @@ EditForm.propTypes = { const TextInput = (props) => ( -