import React, { Component, Fragment } from 'react'; import { Link, NavLink, Redirect } from 'react-router-dom'; import queryString from 'query-string'; import ErrorBox from './error-box'; import InfoBox from './info-box'; import Sidebar from './sidebar'; import Tooltip from './tooltip'; import { HelpIcon, CloseIcon, SaveIcon } from './icons'; import CONFIG from './fields-config.json'; const BuildingEdit = (props) => { if (!props.user){ return } if (!props.building_id){ return (
Back to maps
); } const search = (props.location && props.location.search)? queryString.parse(props.location.search): {}; return ( { CONFIG.map((conf_props) => { return }) } ); } class EditForm extends Component { constructor(props) { super(props); this.state = {...props} this.state.error = this.state.error || undefined; this.handleChange = this.handleChange.bind(this); this.handleLike = this.handleLike.bind(this); this.handleSubmit = this.handleSubmit.bind(this); } handleChange(event) { const target = event.target; const value = (target.value === '')? null : target.value; const name = target.name; this.setState({ [name]: value }); } handleLike(event) { const liked = event.target.checked; this.setState({ like: liked }); } handleSubmit(event) { event.preventDefault(); this.setState({error: undefined}) fetch(`/building/${this.props.building_id}.json`, { method: 'POST', body: JSON.stringify(this.state), headers:{ 'Content-Type': 'application/json' }, credentials: 'same-origin' }).then( res => res.json() ).then(function(res){ if (res.error) { this.setState({error: res.error}) } else { this.props.selectBuilding(res); const new_cat = this.props.search.cat; this.props.history.push(`/building/${res.building_id}.html?cat=${new_cat}`); } }.bind(this)).catch( (err) => this.setState({error: err}) ); } render() { const match = this.props.search.cat === this.props.slug; if (!match) { return null } return (

{this.props.title}

{ this.props.intro?

{ this.props.intro }

: null }
{ this.props.fields.map((props) => { var el; switch (props.type) { case "text": el = break; case "text_list": el = break; case "number": el = break; case "like": el = break; default: el = null break; } return el }) } { (this.props.inactive)? null : (
Cancel
) }

Colouring may take a few seconds - try zooming the map or hitting refresh after saving (we're working on making this smoother).

) } } const TextInput = (props) => ( ); const TextListInput = (props) => ( ) const NumberInput = (props) => ( ); const LikeButton = (props) => (
); const Label = (props) => ( ) export default BuildingEdit;