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

87 lines
2.9 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';
import Sidebar from './sidebar';
import { EditIcon } from './icons';
import CONFIG from './fields-config.json';
const Overview = (props) => {
var data_layer = 'age'; // always default
if (props.match && props.match.params && props.match.params.cat) {
data_layer = props.match.params.cat;
}
if (props.mode === 'edit' && !props.user){
return <Redirect to="/sign-up.html" />
}
let title = (props.mode === 'view')? 'View maps' : 'Add or edit data';
2019-01-22 13:01:29 -05:00
let back = (props.mode === 'edit')? `/view/${data_layer}.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
{
CONFIG.map((data_group) => (
<OverviewSection {...data_group}
data_layer={data_layer} key={data_group.slug} mode={props.mode} />
))
}
</Sidebar>
);
}
const OverviewSection = (props) => {
const match = props.data_layer === props.slug;
const inactive = props.inactive;
2019-04-04 08:16:04 -04:00
2018-11-29 17:00:53 -05:00
return (
<section className={(inactive? "inactive ": "") + "data-section legend"}>
2019-01-22 13:36:36 -05:00
<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?
<a className="icon-button help" href={props.help}>
2019-01-22 14:39:16 -05:00
Info
2018-11-29 17:00:53 -05:00
</a>
: null
}
{
props.mode === 'view'?
<NavLink className="icon-button edit" title="Edit data"
to={`/edit/${props.slug}.html`}>
Edit
<EditIcon />
</NavLink>
: null
}
</nav>
</header>
2018-12-03 04:19:13 -05:00
{
(match && props.intro)?
2019-04-04 08:16:04 -04:00
(
<Fragment>
<p className="data-intro">{props.intro}</p>
<ul>
{
props.fields.map((field) => {
2019-04-18 12:07:00 -04:00
return (<li key={field.slug}>{field.title}</li>)
2019-04-04 08:16:04 -04:00
})
}
</ul>
</Fragment>
)
2018-12-03 04:19:13 -05:00
: null
}
2018-11-29 17:00:53 -05:00
</section>
)
};
export default Overview;