colouring-montreal/app/src/frontend/header.tsx

136 lines
5.8 KiB
TypeScript
Raw Normal View History

2018-10-02 16:48:13 -04:00
import React, { Fragment } from 'react';
import { NavLink } from 'react-router-dom';
2019-05-27 13:26:29 -04:00
import PropTypes from 'prop-types';
2019-08-14 03:56:00 -04:00
import { Logo } from './components/logo';
import './header.css';
interface HeaderProps {
user: any;
animateLogo: boolean;
}
interface HeaderState {
collapseMenu: boolean;
}
/**
* Render the main header using a responsive design
*/
class Header extends React.Component<HeaderProps, HeaderState> { // TODO: add proper types
static propTypes = { // TODO: generate propTypes from TS
user: PropTypes.shape({
username: PropTypes.string
}),
animateLogo: PropTypes.bool
};
2019-05-27 11:39:16 -04:00
constructor(props) {
super(props);
this.state = {collapseMenu: true};
this.handleClick = this.handleClick.bind(this);
2019-09-18 09:33:23 -04:00
this.handleNavigate = this.handleNavigate.bind(this);
2019-05-27 11:39:16 -04:00
}
2019-05-27 11:39:16 -04:00
handleClick() {
this.setState(state => ({
collapseMenu: !state.collapseMenu
}));
}
2019-09-18 09:33:23 -04:00
handleNavigate() {
this.setState({
collapseMenu: true
});
}
2019-05-27 11:39:16 -04:00
render() {
return (
<header className="main-header">
2019-09-04 12:04:07 -04:00
<nav className="navbar navbar-light navbar-expand-lg">
<span className="navbar-brand align-self-start">
2019-09-05 08:33:20 -04:00
<NavLink to="/">
<Logo variant={this.props.animateLogo ? 'animated' : 'default'}/>
2019-09-05 08:33:20 -04:00
</NavLink>
2019-05-27 11:39:16 -04:00
</span>
<button className="navbar-toggler navbar-toggler-right" type="button"
2019-09-04 12:04:07 -04:00
onClick={this.handleClick} aria-expanded={!this.state.collapseMenu} aria-label="Toggle navigation">
2019-05-27 11:39:16 -04:00
<span className="navbar-toggler-icon"></span>
</button>
<div className={this.state.collapseMenu ? 'collapse navbar-collapse' : 'navbar-collapse'}>
<ul className="navbar-nav ml-auto">
2019-09-04 12:04:07 -04:00
<li className="nav-item">
2019-09-18 09:33:23 -04:00
<NavLink to="/view/categories" className="nav-link" onClick={this.handleNavigate}>
2019-09-04 12:04:07 -04:00
View/Edit Maps
</NavLink>
</li>
2019-05-27 11:39:16 -04:00
<li className="nav-item">
<a className="nav-link" href="https://pages.colouring.london">
2019-09-04 12:04:07 -04:00
About
2019-05-27 11:39:16 -04:00
</a>
</li>
<li className="nav-item">
<a className="nav-link" href="https://pages.colouring.london/buildingcategories">
Data Categories
</a>
</li>
<li className="nav-item">
<a className="nav-link" href="https://pages.colouring.london/whoisinvolved">
Who&rsquo;s Involved?
</a>
</li>
2019-07-07 14:20:17 -04:00
<li className="nav-item">
2019-09-04 12:04:07 -04:00
<a className="nav-link" href="https://pages.colouring.london/data-ethics">
2019-07-07 14:20:17 -04:00
Data Ethics
</a>
</li>
2019-05-27 11:39:16 -04:00
<li className="nav-item">
<a className="nav-link" href="https://discuss.colouring.london">
Discuss
</a>
</li>
<li className="nav-item">
<NavLink to="/data-extracts.html" className="nav-link" onClick={this.handleNavigate}>
Downloads
</NavLink>
</li>
2019-10-02 13:38:12 -04:00
<li className="nav-item">
<NavLink to="/contact.html" className="nav-link" onClick={this.handleNavigate}>
Contact
</NavLink>
</li>
2019-05-27 11:39:16 -04:00
{
this.props.user?
(
<li className="nav-item">
2019-09-18 09:33:23 -04:00
<NavLink to="/my-account.html" className="nav-link" onClick={this.handleNavigate}>
2019-09-04 12:04:07 -04:00
Account <span className="shorten-username">({this.props.user.username})</span>
2019-05-27 11:39:16 -04:00
</NavLink>
</li>
):
(
<Fragment>
<li className="nav-item">
2019-09-18 09:33:23 -04:00
<NavLink to="/login.html" className="nav-link" onClick={this.handleNavigate}>
2019-05-27 11:39:16 -04:00
Log in
</NavLink>
</li>
<li className="nav-item">
2019-09-18 09:33:23 -04:00
<NavLink to="/sign-up.html" className="nav-link" onClick={this.handleNavigate}>
2019-05-27 11:39:16 -04:00
Sign up
</NavLink>
</li>
</Fragment>
)
}
</ul>
</div>
</nav>
</header>
);
}
}
2018-10-02 16:48:13 -04:00
export default Header;