2019-11-05 15:13:10 -05:00
|
|
|
import React from 'react';
|
2021-02-08 11:03:30 -05:00
|
|
|
import { Link } from 'react-router-dom';
|
2019-05-09 04:16:36 -04:00
|
|
|
|
2019-11-26 07:09:27 -05:00
|
|
|
import { parseJsonOrDefault } from '../../helpers';
|
|
|
|
import ErrorBox from '../components/error-box';
|
2019-08-14 04:21:42 -04:00
|
|
|
import InfoBox from '../components/info-box';
|
2019-10-25 13:07:24 -04:00
|
|
|
import { dataFields } from '../data_fields';
|
2019-11-05 15:13:10 -05:00
|
|
|
import { User } from '../models/user';
|
2019-05-09 04:16:36 -04:00
|
|
|
|
2019-11-07 02:39:26 -05:00
|
|
|
import DataEntry from './data-components/data-entry';
|
|
|
|
import Sidebar from './sidebar';
|
2020-02-03 17:35:32 -05:00
|
|
|
import Categories from './categories';
|
2019-11-07 02:39:26 -05:00
|
|
|
|
2019-11-26 07:09:27 -05:00
|
|
|
interface MultiEditProps {
|
2019-11-05 15:13:10 -05:00
|
|
|
user?: User;
|
2019-11-26 07:09:27 -05:00
|
|
|
category: string;
|
|
|
|
dataString: string;
|
2019-11-05 15:13:10 -05:00
|
|
|
}
|
2019-08-23 09:18:08 -04:00
|
|
|
|
2019-11-05 15:13:10 -05:00
|
|
|
const MultiEdit: React.FC<MultiEditProps> = (props) => {
|
2019-11-26 07:09:27 -05:00
|
|
|
if (props.category === 'like') {
|
2019-05-10 11:10:16 -04:00
|
|
|
// special case for likes
|
|
|
|
return (
|
2019-08-14 14:27:28 -04:00
|
|
|
<Sidebar>
|
2020-02-03 17:35:32 -05:00
|
|
|
<Categories mode={'view'} />
|
2019-05-27 15:13:43 -04:00
|
|
|
<section className='data-section'>
|
2019-11-26 07:09:27 -05:00
|
|
|
<header className={`section-header view ${props.category} background-${props.category}`}>
|
2019-10-02 17:33:42 -04:00
|
|
|
<h2 className="h2">Like me!</h2>
|
2019-05-27 16:28:47 -04:00
|
|
|
</header>
|
|
|
|
<form className='buttons-container'>
|
|
|
|
<InfoBox msg='Click all the buildings that you like and think contribute to the city!' />
|
2019-05-10 11:10:16 -04:00
|
|
|
|
2019-09-08 20:11:45 -04:00
|
|
|
<Link to='/view/like' className='btn btn-secondary'>Back to view</Link>
|
|
|
|
<Link to='/edit/like' className='btn btn-secondary'>Back to edit</Link>
|
2019-05-27 16:28:47 -04:00
|
|
|
</form>
|
2019-05-10 11:10:16 -04:00
|
|
|
</section>
|
|
|
|
</Sidebar>
|
|
|
|
);
|
|
|
|
}
|
2019-05-10 09:00:20 -04:00
|
|
|
|
2019-11-26 07:09:27 -05:00
|
|
|
let data = parseJsonOrDefault(props.dataString);
|
2019-10-02 17:13:34 -04:00
|
|
|
|
2019-11-26 07:09:27 -05:00
|
|
|
let error: string;
|
|
|
|
if(data == null) {
|
|
|
|
error = 'Invalid parameters supplied';
|
|
|
|
data = {};
|
|
|
|
} else if(Object.values(data).some(x => x == undefined)) {
|
|
|
|
error = 'Cannot copy empty values';
|
|
|
|
data = {};
|
2019-10-02 17:13:34 -04:00
|
|
|
}
|
|
|
|
|
2019-05-09 04:16:36 -04:00
|
|
|
return (
|
2019-08-14 14:27:28 -04:00
|
|
|
<Sidebar>
|
2020-02-03 17:35:32 -05:00
|
|
|
<Categories mode={'view'} />
|
2019-05-27 15:13:43 -04:00
|
|
|
<section className='data-section'>
|
2019-11-26 07:09:27 -05:00
|
|
|
<header className={`section-header view ${props.category} background-${props.category}`}>
|
|
|
|
<h2 className="h2">Copy {props.category} data</h2>
|
2019-05-27 16:28:47 -04:00
|
|
|
</header>
|
2020-02-03 17:35:32 -05:00
|
|
|
<div className="section-body">
|
|
|
|
<form>
|
2019-11-26 07:09:27 -05:00
|
|
|
{
|
|
|
|
error ?
|
|
|
|
<ErrorBox msg={error} /> :
|
|
|
|
<InfoBox msg='Click buildings one at a time to colour using the data below' />
|
|
|
|
}
|
2020-02-03 17:35:32 -05:00
|
|
|
{
|
|
|
|
Object.keys(data).map((key => {
|
|
|
|
const info = dataFields[key] || {};
|
|
|
|
return (
|
|
|
|
<DataEntry
|
|
|
|
title={info.title || `Unknown field (${key})`}
|
|
|
|
slug={key}
|
|
|
|
disabled={true}
|
|
|
|
value={data[key]}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
</form>
|
|
|
|
<form className='buttons-container'>
|
|
|
|
<Link to={`/view/${props.category}`} className='btn btn-secondary'>Back to view</Link>
|
|
|
|
<Link to={`/edit/${props.category}`} className='btn btn-secondary'>Back to edit</Link>
|
|
|
|
</form>
|
|
|
|
</div>
|
2019-05-09 04:16:36 -04:00
|
|
|
</section>
|
|
|
|
</Sidebar>
|
|
|
|
);
|
2019-11-07 03:13:30 -05:00
|
|
|
};
|
2019-05-09 04:16:36 -04:00
|
|
|
|
|
|
|
export default MultiEdit;
|