Skip to content

Instantly share code, notes, and snippets.

@rlemon
Last active December 6, 2016 20:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rlemon/9086014fc69fe16c4fc8dde16cf3acde to your computer and use it in GitHub Desktop.
Save rlemon/9086014fc69fe16c4fc8dde16cf3acde to your computer and use it in GitHub Desktop.
import React, { Component } from 'react';
import { Link } from 'react-router';
import logoImageMain from '../logo-main.png';
export default class Header extends Component {
static contextTypes = {
currentUser: React.PropTypes.object
}
constructor(props) {
super(props);
}
* getLinks() {
const [,pathname = 'home'] = location.pathname.match(/^\/(\w+)/) || [];
const {loggedIn} = this.props;
const links = [
{
key: 'home',
props: {
to: '/'
}
},
{
key: 'addgist',
props: {
to: '/addgist'
},
authToggle: true
},
{
key: 'profile',
props: {
to: '/profile'
},
authToggle: true
},
{
key: 'login',
props: {
to: '/login'
},
authToggle: false
},
{
key: 'logout',
props: {
to: '/logout'
},
authToggle: true
}
]
for( const link of links ) {
const {key, props, authToggle = null} = link;
props.className = 'pop-button';
if( key === pathname ) {
props.className += ' active';
}
if( (authToggle === true && loggedIn) || authToggle === null || (authToggle === false && !loggedIn) ) {
yield (<Link key={key} {...props}>{key}</Link>);
}
}
}
render() {
return (
<div className="header" style={{backgroundImage: `url(${logoImageMain})`}}>
<div className="menu">
{Array.from(this.getLinks())}
</div>
</div>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment