2021-01-24 22:50:48 -05:00
|
|
|
import React, { useState } from 'react';
|
2018-09-09 17:22:44 -04:00
|
|
|
import { NavLink } from 'react-router-dom';
|
|
|
|
|
2019-11-13 14:20:47 -05:00
|
|
|
import './header.css';
|
|
|
|
|
2019-08-14 03:56:00 -04:00
|
|
|
import { Logo } from './components/logo';
|
2021-01-24 22:50:48 -05:00
|
|
|
import { WithSeparator } from './components/with-separator';
|
2021-02-08 11:03:30 -05:00
|
|
|
import { useAuth } from './auth-context';
|
2019-11-05 15:13:10 -05:00
|
|
|
|
2022-11-30 10:20:00 -05:00
|
|
|
import { CCConfig } from '../cc-config';
|
|
|
|
let config: CCConfig = require('../cc-config.json')
|
2019-10-28 12:46:22 -04:00
|
|
|
|
2021-01-24 22:50:48 -05:00
|
|
|
interface MenuLink {
|
|
|
|
to: string;
|
|
|
|
text: string;
|
|
|
|
external?: boolean;
|
2021-01-28 19:35:14 -05:00
|
|
|
disabled?: boolean;
|
|
|
|
note?: string;
|
2019-10-28 12:46:22 -04:00
|
|
|
}
|
|
|
|
|
2019-05-23 09:41:20 -04:00
|
|
|
|
2021-01-24 22:50:48 -05:00
|
|
|
function getCurrentMenuLinks(username: string): MenuLink[][] {
|
|
|
|
return [
|
|
|
|
[
|
|
|
|
{
|
|
|
|
to: "/view/categories",
|
2021-01-28 19:35:14 -05:00
|
|
|
text: "View Maps"
|
2021-01-24 22:50:48 -05:00
|
|
|
},
|
|
|
|
{
|
2021-01-28 19:35:14 -05:00
|
|
|
to: "/edit/categories",
|
|
|
|
text: "Edit Maps"
|
2021-01-24 22:50:48 -05:00
|
|
|
},
|
|
|
|
{
|
2021-01-28 19:35:14 -05:00
|
|
|
to: "/data-extracts.html",
|
|
|
|
text: "Download data"
|
2021-01-24 22:50:48 -05:00
|
|
|
},
|
|
|
|
{
|
2022-11-30 10:20:00 -05:00
|
|
|
to: config.githubURL,
|
2021-01-28 19:35:14 -05:00
|
|
|
text: "Access open code",
|
2021-01-24 22:50:48 -05:00
|
|
|
external: true
|
|
|
|
},
|
2021-01-28 19:35:14 -05:00
|
|
|
{
|
|
|
|
to: "/showcase.html",
|
|
|
|
text: "View Data Showcase",
|
|
|
|
disabled: true,
|
|
|
|
note: "Coming soon"
|
|
|
|
},
|
2021-01-24 22:50:48 -05:00
|
|
|
],
|
|
|
|
[
|
|
|
|
{
|
|
|
|
to: "https://pages.colouring.london",
|
|
|
|
text: "About",
|
|
|
|
external: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
to: "https://pages.colouring.london/buildingcategories",
|
|
|
|
text: "Data Categories",
|
|
|
|
external: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
to: "https://pages.colouring.london/whoisinvolved",
|
|
|
|
text: "Who's Involved?",
|
|
|
|
external: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
to: "https://pages.colouring.london/data-ethics",
|
|
|
|
text: "Data Ethics",
|
|
|
|
external: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
to: "https://pages.colouring.london/colouring-cities",
|
|
|
|
text: "Colouring Cities Research Programme",
|
|
|
|
external: true
|
|
|
|
},
|
|
|
|
],
|
|
|
|
[
|
|
|
|
{
|
2021-01-28 19:35:14 -05:00
|
|
|
to: "/leaderboard.html",
|
|
|
|
text: "Top Contributors"
|
2021-01-24 22:50:48 -05:00
|
|
|
},
|
2021-01-28 19:35:14 -05:00
|
|
|
{
|
|
|
|
to: "https://discuss.colouring.london",
|
|
|
|
text: "Discussion Forum",
|
|
|
|
external: true
|
|
|
|
},
|
2022-03-28 09:23:06 -04:00
|
|
|
{
|
|
|
|
to: "https://discuss.colouring.london/c/blog/9",
|
|
|
|
text: "Blog",
|
|
|
|
external: true
|
|
|
|
},
|
2021-01-28 19:35:14 -05:00
|
|
|
],
|
|
|
|
[
|
2021-01-24 22:50:48 -05:00
|
|
|
{
|
|
|
|
to: "/privacy-policy.html",
|
|
|
|
text: "Privacy Policy"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
to: "/contributor-agreement.html",
|
|
|
|
text: "Contributor Agreement"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
to: "/code-of-conduct.html",
|
|
|
|
text: "Code of Conduct"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
to: "/data-accuracy.html",
|
|
|
|
text: "Data Accuracy Agreement"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
to: "/ordnance-survey-uprn.html",
|
|
|
|
text: "Ordnance Survey terms of UPRN usage"
|
|
|
|
},
|
|
|
|
],
|
2021-01-28 19:35:14 -05:00
|
|
|
[
|
|
|
|
{
|
|
|
|
to: "/contact.html",
|
|
|
|
text: "Contact"
|
|
|
|
},
|
|
|
|
...(
|
|
|
|
username != undefined ?
|
|
|
|
[
|
|
|
|
{
|
|
|
|
to: "/my-account.html",
|
|
|
|
text: `Account (${username})`
|
|
|
|
}
|
|
|
|
] :
|
|
|
|
[
|
|
|
|
{
|
|
|
|
to: "/login.html",
|
|
|
|
text: "Log in"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
to: "/sign-up.html",
|
|
|
|
text: "Sign up"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
)
|
|
|
|
],
|
2021-01-24 22:50:48 -05:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2021-02-08 11:03:30 -05:00
|
|
|
const Menu: React.FC<{ onNavigate: () => void }> = ({ onNavigate }) => {
|
|
|
|
const { user } = useAuth();
|
2021-01-28 19:35:14 -05:00
|
|
|
|
2021-02-08 11:03:30 -05:00
|
|
|
const menuLinkSections = getCurrentMenuLinks(user?.username);
|
|
|
|
return (
|
|
|
|
<WithSeparator separator={<hr />}>
|
|
|
|
{menuLinkSections.map((section, idx) =>
|
|
|
|
<ul key={`menu-section-${idx}`} className="navbar-nav flex-container">
|
|
|
|
{section.map(item => (
|
|
|
|
<li className='nav-item' key={`${item.to}-${item.text}`}>
|
|
|
|
{
|
|
|
|
item.disabled ?
|
|
|
|
<LinkStub note={item.note}>{item.text}</LinkStub> :
|
|
|
|
item.external ?
|
|
|
|
<ExternalNavLink to={item.to}>{item.text}</ExternalNavLink> :
|
|
|
|
<InternalNavLink to={item.to} onClick={onNavigate}>{item.text}</InternalNavLink>
|
|
|
|
}
|
|
|
|
</li>
|
|
|
|
))}
|
|
|
|
</ul>
|
|
|
|
)}
|
|
|
|
</WithSeparator>
|
|
|
|
);
|
|
|
|
};
|
2021-01-28 19:35:14 -05:00
|
|
|
|
2021-02-08 11:03:30 -05:00
|
|
|
const InternalNavLink: React.FC<{to: string; onClick: () => void}> = ({ to, onClick, children}) => (
|
2021-01-28 19:35:14 -05:00
|
|
|
<NavLink className="nav-link" to={to} onClick={onClick}>
|
|
|
|
{children}
|
|
|
|
</NavLink>
|
|
|
|
);
|
|
|
|
|
2021-02-08 11:03:30 -05:00
|
|
|
const ExternalNavLink: React.FC<{to: string}> = ({ to, children }) => (
|
2021-01-28 19:35:14 -05:00
|
|
|
<a className="nav-link" href={to}>
|
|
|
|
{children}
|
|
|
|
</a>
|
|
|
|
);
|
|
|
|
|
|
|
|
const LinkStub: React.FC<{note: string}> = ({note, children}) => (
|
|
|
|
<a className="nav-link disabled">
|
|
|
|
{children}
|
|
|
|
<span className="link-note">{note}</span>
|
|
|
|
</a>
|
|
|
|
);
|
|
|
|
|
2021-02-08 11:03:30 -05:00
|
|
|
export const Header: React.FC<{
|
2021-01-24 22:50:48 -05:00
|
|
|
animateLogo: boolean;
|
2021-02-08 11:03:30 -05:00
|
|
|
}> = ({ animateLogo }) => {
|
2021-01-24 20:34:41 -05:00
|
|
|
const [collapseMenu, setCollapseMenu] = useState(true);
|
2019-05-23 09:41:20 -04:00
|
|
|
|
2021-01-24 22:50:48 -05:00
|
|
|
const toggleCollapse = () => setCollapseMenu(!collapseMenu);
|
2021-01-24 20:34:41 -05:00
|
|
|
const handleNavigate = () => setCollapseMenu(true);
|
2019-09-18 09:33:23 -04:00
|
|
|
|
2021-01-24 20:34:41 -05:00
|
|
|
return (
|
|
|
|
<header className="main-header navbar navbar-light">
|
|
|
|
<div className="nav-header">
|
|
|
|
<NavLink to="/">
|
2021-01-24 22:50:48 -05:00
|
|
|
<Logo variant={animateLogo ? 'animated' : 'default'}/>
|
2021-01-24 20:34:41 -05:00
|
|
|
</NavLink>
|
|
|
|
<button className="navbar-toggler" type="button"
|
2021-01-24 22:50:48 -05:00
|
|
|
onClick={toggleCollapse} aria-expanded={!collapseMenu} aria-label="Toggle navigation">
|
2021-01-24 20:34:41 -05:00
|
|
|
Menu
|
|
|
|
{
|
|
|
|
collapseMenu ?
|
|
|
|
<span className="navbar-toggler-icon"></span>
|
|
|
|
: <span className="close">×</span>
|
|
|
|
}
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
<nav className={collapseMenu ? 'collapse navbar-collapse' : 'navbar-collapse'}>
|
2021-02-08 11:03:30 -05:00
|
|
|
<Menu onNavigate={handleNavigate}></Menu>
|
2021-01-24 20:34:41 -05:00
|
|
|
</nav>
|
|
|
|
</header>
|
|
|
|
);
|
2019-05-23 09:41:20 -04:00
|
|
|
}
|