Last active
December 6, 2016 20:46
-
-
Save rlemon/9086014fc69fe16c4fc8dde16cf3acde to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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