import React from 'react'; import { Link, Redirect } from 'react-router-dom'; import { parse } from 'query-string'; import PropTypes from 'prop-types'; import Sidebar from './sidebar'; import CONFIG from './fields-config.json'; import InfoBox from './info-box'; const MultiEdit = (props) => { if (!props.user){ return } const cat = props.match.params.cat; if (cat === 'like') { // special case for likes return (

Like me!

Back to view Back to edit
); } const q = parse(props.location.search); const label = fieldTitleFromSlug(q.k); const title = sectionTitleFromCat(cat); return (

{title}

Set {label} to {q.v}

Back to view Back to edit
); } MultiEdit.propTypes = { user: PropTypes.object, match: PropTypes.object, location: PropTypes.object } function sectionTitleFromCat(cat) { for (let index = 0; index < CONFIG.length; index++) { const section = CONFIG[index]; if (section.slug === cat) { return section.title } } return undefined } function fieldTitleFromSlug(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) } } export default MultiEdit;