2019-05-09 04:16:36 -04:00
|
|
|
import React from 'react';
|
2019-05-10 11:10:16 -04:00
|
|
|
import { Link, Redirect } from 'react-router-dom';
|
|
|
|
import { parse } from 'query-string';
|
2019-05-09 04:16:36 -04:00
|
|
|
|
|
|
|
import Sidebar from './sidebar';
|
2019-05-10 11:10:16 -04:00
|
|
|
import CONFIG from './fields-config.json';
|
2019-05-09 04:16:36 -04:00
|
|
|
|
|
|
|
const MultiEdit = (props) => {
|
|
|
|
if (!props.user){
|
|
|
|
return <Redirect to="/sign-up.html" />
|
|
|
|
}
|
2019-05-10 09:00:20 -04:00
|
|
|
const cat = props.match.params.cat;
|
2019-05-10 11:10:16 -04:00
|
|
|
if (cat === 'like') {
|
|
|
|
// special case for likes
|
|
|
|
return (
|
|
|
|
<Sidebar
|
|
|
|
title={`Quick like`}
|
|
|
|
back={`/edit/${cat}.html`}>
|
|
|
|
<section className="data-section">
|
|
|
|
<p className="data-intro">Click all the buildings that you like and think contribute to the city!</p>
|
|
|
|
|
|
|
|
<div className="buttons-container ml-3 mr-3">
|
|
|
|
<Link to={`/view/like.html`} className="btn btn-secondary">Back to view</Link>
|
|
|
|
<Link to={`/edit/like.html`} className="btn btn-secondary">Back to edit</Link>
|
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
</Sidebar>
|
|
|
|
);
|
|
|
|
}
|
2019-05-10 09:00:20 -04:00
|
|
|
|
2019-05-10 11:10:16 -04:00
|
|
|
const q = parse(props.location.search);
|
|
|
|
const label = field_title_from_slug(q.k);
|
2019-05-09 04:16:36 -04:00
|
|
|
return (
|
|
|
|
<Sidebar
|
|
|
|
title={`Quick edit`}
|
|
|
|
back={`/edit/${cat}.html`}>
|
|
|
|
<section className="data-section">
|
|
|
|
<p className="data-intro">Click a building to colour</p>
|
2019-05-10 11:10:16 -04:00
|
|
|
<p className="data-intro">Set <strong>{label}</strong> to <strong>{q.v}</strong></p>
|
|
|
|
|
|
|
|
<div className="buttons-container ml-3">
|
|
|
|
<Link to={`/view/${cat}.html`} className="btn btn-secondary">Back to view</Link>
|
|
|
|
<Link to={`/edit/${cat}.html`} className="btn btn-secondary">Back to edit</Link>
|
|
|
|
</div>
|
2019-05-09 04:16:36 -04:00
|
|
|
</section>
|
|
|
|
</Sidebar>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-05-10 11:10:16 -04:00
|
|
|
function field_title_from_slug(slug) {
|
|
|
|
const fields = CONFIG.reduce(
|
|
|
|
(prev, section) => {
|
|
|
|
const el = prev.concat(
|
|
|
|
section.fields.filter(
|
|
|
|
field => field.slug === slug
|
|
|
|
)
|
|
|
|
)
|
|
|
|
return el
|
|
|
|
}, []
|
|
|
|
)
|
|
|
|
if (fields.length === 1 && fields[0].title) {
|
|
|
|
return fields[0].title
|
|
|
|
} else {
|
|
|
|
console.error('Expected single match, got', fields)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-09 04:16:36 -04:00
|
|
|
export default MultiEdit;
|