2015-07-24 21:54:19 -07:00
|
|
|
import React, { PropTypes } from 'react';
|
2015-10-27 15:40:04 -07:00
|
|
|
import { LinkContainer } from 'react-router-bootstrap';
|
2015-07-23 22:58:44 -07:00
|
|
|
import {
|
|
|
|
Col,
|
|
|
|
Nav,
|
2015-11-19 15:47:43 -08:00
|
|
|
NavbarBrand,
|
2015-07-23 22:58:44 -07:00
|
|
|
Navbar,
|
|
|
|
NavItem
|
|
|
|
} from 'react-bootstrap';
|
2015-07-03 19:50:18 -07:00
|
|
|
|
|
|
|
import navLinks from './links.json';
|
2015-07-03 19:34:20 -07:00
|
|
|
import FCCNavItem from './NavItem.jsx';
|
2015-06-04 10:53:01 -07:00
|
|
|
|
2015-07-03 19:50:18 -07:00
|
|
|
const fCClogo = 'https://s3.amazonaws.com/freecodecamp/freecodecamp_logo.svg';
|
|
|
|
|
|
|
|
const logoElement = (
|
|
|
|
<a href='/'>
|
|
|
|
<img
|
|
|
|
alt='learn to code javascript at Free Code Camp logo'
|
|
|
|
className='img-responsive nav-logo'
|
|
|
|
src={ fCClogo } />
|
|
|
|
</a>
|
|
|
|
);
|
|
|
|
|
2015-11-19 15:47:43 -08:00
|
|
|
const toggleButtonChild = (
|
2016-01-27 11:34:44 -08:00
|
|
|
<Col xs={ 12 }>
|
|
|
|
<span className='hamburger-text'>Menu</span>
|
|
|
|
</Col>
|
2015-07-23 22:58:44 -07:00
|
|
|
);
|
|
|
|
|
2016-01-27 11:34:44 -08:00
|
|
|
export default class extends React.Component {
|
|
|
|
static displayName = 'Nav';
|
2015-06-04 10:53:01 -07:00
|
|
|
|
2016-01-27 11:34:44 -08:00
|
|
|
static propTypes = {
|
2015-07-24 21:54:19 -07:00
|
|
|
points: PropTypes.number,
|
|
|
|
picture: PropTypes.string,
|
|
|
|
signedIn: PropTypes.bool,
|
|
|
|
username: PropTypes.string
|
2016-01-27 11:34:44 -08:00
|
|
|
};
|
2015-10-27 15:40:04 -07:00
|
|
|
|
|
|
|
renderLinks() {
|
2015-11-12 16:36:08 -08:00
|
|
|
return navLinks.map(({ content, link, react, target }, index) => {
|
2015-10-27 15:40:04 -07:00
|
|
|
if (react) {
|
|
|
|
return (
|
|
|
|
<LinkContainer
|
|
|
|
eventKey={ index + 1 }
|
|
|
|
key={ content }
|
|
|
|
to={ link }>
|
2015-11-13 12:54:46 -08:00
|
|
|
<NavItem
|
2015-11-19 15:47:43 -08:00
|
|
|
target={ target || null }>
|
2015-10-27 15:40:04 -07:00
|
|
|
{ content }
|
|
|
|
</NavItem>
|
|
|
|
</LinkContainer>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<NavItem
|
|
|
|
eventKey={ index + 1 }
|
|
|
|
href={ link }
|
2015-11-13 12:54:46 -08:00
|
|
|
key={ content }
|
|
|
|
target={ target || null }>
|
2015-10-27 15:40:04 -07:00
|
|
|
{ content }
|
|
|
|
</NavItem>
|
|
|
|
);
|
|
|
|
});
|
2016-01-27 11:34:44 -08:00
|
|
|
}
|
2015-06-04 10:53:01 -07:00
|
|
|
|
2015-07-24 21:54:19 -07:00
|
|
|
renderPoints(username, points) {
|
|
|
|
if (!username) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return (
|
2015-11-19 15:47:43 -08:00
|
|
|
<FCCNavItem
|
|
|
|
className='brownie-points-nav'
|
2015-07-24 21:54:19 -07:00
|
|
|
href={ '/' + username }>
|
|
|
|
[ { points } ]
|
2015-11-19 15:47:43 -08:00
|
|
|
</FCCNavItem>
|
2015-07-24 21:54:19 -07:00
|
|
|
);
|
2016-01-27 11:34:44 -08:00
|
|
|
}
|
2015-07-24 21:54:19 -07:00
|
|
|
|
|
|
|
renderSignin(username, picture) {
|
|
|
|
if (username) {
|
2015-06-04 10:53:01 -07:00
|
|
|
return (
|
2016-01-24 11:25:35 -05:00
|
|
|
<li
|
|
|
|
className='hidden-xs hidden-sm avatar'
|
2015-06-04 10:53:01 -07:00
|
|
|
eventKey={ 2 }>
|
2015-07-24 21:54:19 -07:00
|
|
|
<a href={ '/' + username }>
|
2015-07-28 11:18:11 -07:00
|
|
|
<img
|
|
|
|
className='profile-picture float-right'
|
|
|
|
src={ picture } />
|
2015-07-24 21:54:19 -07:00
|
|
|
</a>
|
2016-01-24 11:25:35 -05:00
|
|
|
</li>
|
2015-06-04 10:53:01 -07:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return (
|
2016-01-15 02:46:25 -08:00
|
|
|
<NavItem
|
2015-06-04 10:53:01 -07:00
|
|
|
eventKey={ 2 }
|
2016-05-03 15:06:20 +00:00
|
|
|
href='/signin'>
|
2015-06-17 21:04:28 -07:00
|
|
|
Sign In
|
2016-01-15 02:46:25 -08:00
|
|
|
</NavItem>
|
2015-06-04 10:53:01 -07:00
|
|
|
);
|
|
|
|
}
|
2016-01-27 11:34:44 -08:00
|
|
|
}
|
2015-06-04 10:53:01 -07:00
|
|
|
|
2015-06-17 21:04:28 -07:00
|
|
|
render() {
|
2015-07-24 21:54:19 -07:00
|
|
|
const { username, points, picture } = this.props;
|
2015-11-19 22:45:31 -08:00
|
|
|
|
2015-06-04 10:53:01 -07:00
|
|
|
return (
|
|
|
|
<Navbar
|
2015-06-17 21:04:28 -07:00
|
|
|
className='nav-height'
|
2015-11-19 15:47:43 -08:00
|
|
|
fixedTop={ true }>
|
|
|
|
<NavbarBrand>{ logoElement }</NavbarBrand>
|
|
|
|
<Navbar.Toggle children={ toggleButtonChild } />
|
|
|
|
<Navbar.Collapse eventKey={ 0 }>
|
2015-07-24 21:54:19 -07:00
|
|
|
<Nav
|
|
|
|
className='hamburger-dropdown'
|
|
|
|
navbar={ true }
|
2015-11-19 15:47:43 -08:00
|
|
|
pullRight={ true }>
|
2015-10-27 15:40:04 -07:00
|
|
|
{ this.renderLinks() }
|
|
|
|
{ this.renderPoints(username, points) }
|
2015-07-24 21:54:19 -07:00
|
|
|
{ this.renderSignin(username, picture) }
|
|
|
|
</Nav>
|
2015-11-19 15:47:43 -08:00
|
|
|
</Navbar.Collapse>
|
2015-06-04 10:53:01 -07:00
|
|
|
</Navbar>
|
|
|
|
);
|
|
|
|
}
|
2016-01-27 11:34:44 -08:00
|
|
|
}
|