colouring-montreal/app/src/frontend/overview.js

108 lines
3.5 KiB
JavaScript
Raw Normal View History

2019-04-04 08:16:04 -04:00
import React, { Fragment } from 'react';
2018-11-29 17:00:53 -05:00
import { NavLink, Redirect } from 'react-router-dom';
2019-05-27 13:26:29 -04:00
import PropTypes from 'prop-types';
2018-11-29 17:00:53 -05:00
import Sidebar from './sidebar';
import { EditIcon } from './icons';
import CONFIG from './fields-config.json';
const Overview = (props) => {
2019-05-27 13:26:29 -04:00
var dataLayer = 'age'; // always default
2018-11-29 17:00:53 -05:00
if (props.match && props.match.params && props.match.params.cat) {
2019-05-27 13:26:29 -04:00
dataLayer = props.match.params.cat;
2018-11-29 17:00:53 -05:00
}
if (props.mode === 'edit' && !props.user){
return <Redirect to="/sign-up.html" />
}
2019-05-27 13:35:12 -04:00
const title = (props.mode === 'view')? 'View maps' : 'Add or edit data';
const back = (props.mode === 'edit')? `/view/${dataLayer}.html` : undefined;
2018-11-29 17:00:53 -05:00
return (
2019-01-22 13:01:29 -05:00
<Sidebar title={title} back={back}>
2018-11-29 17:00:53 -05:00
{
2019-05-27 13:26:29 -04:00
CONFIG.map((dataGroup) => (
<OverviewSection {...dataGroup}
dataLayer={dataLayer} key={dataGroup.slug} mode={props.mode} />
2018-11-29 17:00:53 -05:00
))
}
</Sidebar>
);
}
2019-05-27 13:26:29 -04:00
Overview.propTypes = {
match: PropTypes.object,
mode: PropTypes.string,
user: PropTypes.object
}
2018-11-29 17:00:53 -05:00
const OverviewSection = (props) => {
2019-05-27 13:26:29 -04:00
const match = props.dataLayer === props.slug;
2018-11-29 17:00:53 -05:00
const inactive = props.inactive;
2019-04-04 08:16:04 -04:00
2018-11-29 17:00:53 -05:00
return (
2019-05-27 11:31:48 -04:00
<section className={(inactive? 'inactive ': '') + 'data-section legend'}>
<header className={`section-header ${props.mode} ${props.slug} ${(match? 'active' : '')}`}>
2018-11-29 17:00:53 -05:00
<NavLink
to={`/${props.mode}/${props.slug}.html`}
isActive={() => match}
title={(inactive)? 'Coming soon… Click the ? for more info.' :
(match)? '' : 'Show on map'}>
<h3 className="h3">{props.title}</h3>
</NavLink>
<nav className="icon-buttons">
{
props.help?
2019-05-27 11:39:16 -04:00
<a className="icon-button help" href={props.help}>
2019-01-22 14:39:16 -05:00
Info
2019-05-27 11:39:16 -04:00
</a>
: null
2018-11-29 17:00:53 -05:00
}
{
props.mode === 'view'?
2019-05-27 11:39:16 -04:00
<NavLink className="icon-button edit" title="Edit data"
to={`/edit/${props.slug}.html`}>
2018-11-29 17:00:53 -05:00
Edit
2019-05-27 11:39:16 -04:00
<EditIcon />
</NavLink>
: null
2018-11-29 17:00:53 -05:00
}
</nav>
</header>
2018-12-03 04:19:13 -05:00
{
(match && props.intro)?
2019-05-27 11:39:16 -04:00
(
<Fragment>
<p className="data-intro">{props.intro}</p>
<ul>
{
props.fields.map((field) => {
return (<li key={field.slug}>{field.title}</li>)
})
}
</ul>
</Fragment>
)
: null
2018-12-03 04:19:13 -05:00
}
2018-11-29 17:00:53 -05:00
</section>
)
};
2019-05-27 13:26:29 -04:00
OverviewSection.propTypes = {
title: PropTypes.string,
slug: PropTypes.string,
intro: PropTypes.string,
help: PropTypes.string,
dataLayer: PropTypes.string,
mode: PropTypes.string,
inactive: PropTypes.bool,
fields: PropTypes.arrayOf(PropTypes.shape({
title: PropTypes.string,
slug: PropTypes.string
}))
}
2018-11-29 17:00:53 -05:00
export default Overview;