2015-07-24 21:54:19 -07:00
|
|
|
import React, { PropTypes } from 'react';
|
2016-03-05 21:06:04 -08:00
|
|
|
import ReactDOM from 'react-dom';
|
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';
|
2016-08-05 15:15:40 -07:00
|
|
|
import PointsNavItem from './Points-Nav-Item.jsx';
|
2016-07-28 20:33:16 -07:00
|
|
|
import AvatarNavItem from './Avatar-Nav-Item.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';
|
|
|
|
|
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-07-21 16:35:37 -07:00
|
|
|
function handleNavLinkEvent(content) {
|
|
|
|
this.props.trackEvent({
|
|
|
|
category: 'Nav',
|
|
|
|
action: 'clicked',
|
|
|
|
label: `${content} link`
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-01-27 11:34:44 -08:00
|
|
|
export default class extends React.Component {
|
2016-07-21 16:35:37 -07:00
|
|
|
constructor(...props) {
|
|
|
|
super(...props);
|
|
|
|
this.handleMapClickOnMap = this.handleMapClickOnMap.bind(this);
|
2016-08-03 12:56:00 -07:00
|
|
|
this.handleLogoClick = this.handleLogoClick.bind(this);
|
2016-07-21 16:35:37 -07:00
|
|
|
navLinks.forEach(({ content }) => {
|
|
|
|
this[`handle${content}Click`] = handleNavLinkEvent.bind(this, content);
|
|
|
|
});
|
|
|
|
}
|
2016-01-27 11:34:44 -08:00
|
|
|
static displayName = 'Nav';
|
|
|
|
static propTypes = {
|
2015-07-24 21:54:19 -07:00
|
|
|
points: PropTypes.number,
|
|
|
|
picture: PropTypes.string,
|
|
|
|
signedIn: PropTypes.bool,
|
2016-03-05 21:06:04 -08:00
|
|
|
username: PropTypes.string,
|
2016-06-27 20:11:52 -07:00
|
|
|
isOnMap: PropTypes.bool,
|
2016-06-03 13:43:42 -07:00
|
|
|
updateNavHeight: PropTypes.func,
|
2016-06-03 23:34:28 -07:00
|
|
|
toggleMapDrawer: PropTypes.func,
|
2016-06-20 11:35:19 -07:00
|
|
|
toggleMainChat: PropTypes.func,
|
2016-07-21 16:35:37 -07:00
|
|
|
shouldShowSignIn: PropTypes.bool,
|
2016-08-03 12:56:00 -07:00
|
|
|
trackEvent: PropTypes.func.isRequired,
|
|
|
|
loadCurrentChallenge: PropTypes.func.isRequired
|
2016-01-27 11:34:44 -08:00
|
|
|
};
|
2015-10-27 15:40:04 -07:00
|
|
|
|
2016-03-05 21:06:04 -08:00
|
|
|
componentDidMount() {
|
|
|
|
const navBar = ReactDOM.findDOMNode(this);
|
|
|
|
this.props.updateNavHeight(navBar.clientHeight);
|
|
|
|
}
|
|
|
|
|
2016-07-21 16:35:37 -07:00
|
|
|
handleMapClickOnMap(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
this.props.trackEvent({
|
|
|
|
category: 'Nav',
|
|
|
|
action: 'clicked',
|
|
|
|
label: 'map clicked while on map'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
handleNavClick() {
|
|
|
|
this.props.trackEvent({
|
|
|
|
category: 'Nav',
|
|
|
|
action: 'clicked',
|
|
|
|
label: 'map clicked while on map'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-08-03 12:56:00 -07:00
|
|
|
handleLogoClick(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
this.props.loadCurrentChallenge();
|
|
|
|
}
|
|
|
|
|
2016-06-03 13:43:42 -07:00
|
|
|
renderMapLink(isOnMap, toggleMapDrawer) {
|
|
|
|
if (isOnMap) {
|
|
|
|
return (
|
|
|
|
<li role='presentation'>
|
|
|
|
<a
|
|
|
|
href='#'
|
2016-07-21 16:35:37 -07:00
|
|
|
onClick={ this.handleMapClickOnMap }
|
2016-06-20 11:35:19 -07:00
|
|
|
>
|
2016-06-03 13:43:42 -07:00
|
|
|
Map
|
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<LinkContainer
|
|
|
|
eventKey={ 1 }
|
2016-06-20 11:35:19 -07:00
|
|
|
to='/map'
|
|
|
|
>
|
2016-06-03 13:43:42 -07:00
|
|
|
<NavItem
|
2016-06-04 21:37:11 -07:00
|
|
|
onClick={ e => {
|
|
|
|
if (!(e.ctrlKey || e.metaKey)) {
|
|
|
|
e.preventDefault();
|
|
|
|
toggleMapDrawer();
|
|
|
|
}
|
|
|
|
}}
|
2016-06-03 13:43:42 -07:00
|
|
|
target='/map'
|
2016-06-20 11:35:19 -07:00
|
|
|
>
|
2016-06-03 13:43:42 -07:00
|
|
|
Map
|
|
|
|
</NavItem>
|
|
|
|
</LinkContainer>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-06-03 23:34:28 -07:00
|
|
|
renderChat(toggleMainChat) {
|
|
|
|
return (
|
|
|
|
<NavItem
|
|
|
|
eventKey={ 2 }
|
|
|
|
href='//gitter.im/freecodecamp/freecodecamp'
|
2016-06-04 21:37:11 -07:00
|
|
|
onClick={ e => {
|
|
|
|
if (!(e.ctrlKey || e.metaKey)) {
|
|
|
|
e.preventDefault();
|
|
|
|
toggleMainChat();
|
|
|
|
}
|
|
|
|
}}
|
2016-06-03 23:34:28 -07:00
|
|
|
target='_blank'
|
2016-06-20 11:35:19 -07:00
|
|
|
>
|
2016-06-03 23:34:28 -07:00
|
|
|
Chat
|
|
|
|
</NavItem>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
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
|
2016-06-03 13:43:42 -07:00
|
|
|
eventKey={ index + 2 }
|
2015-10-27 15:40:04 -07:00
|
|
|
key={ content }
|
2016-07-21 16:35:37 -07:00
|
|
|
onClick={ this[`handle${content}Click`] }
|
2016-06-20 11:35:19 -07:00
|
|
|
to={ link }
|
|
|
|
>
|
2015-11-13 12:54:46 -08:00
|
|
|
<NavItem
|
2016-06-20 11:35:19 -07: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 }
|
2016-07-21 16:35:37 -07:00
|
|
|
onClick={ this[`handle${content}Click`] }
|
2016-06-20 11:35:19 -07:00
|
|
|
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
|
|
|
|
2016-06-20 11:35:19 -07:00
|
|
|
renderPoints(username, points, shouldShowSignIn) {
|
|
|
|
if (!username || !shouldShowSignIn) {
|
2015-07-24 21:54:19 -07:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return (
|
2016-07-15 14:42:47 -07:00
|
|
|
<LinkContainer
|
|
|
|
eventKey={ navLinks.length + 1 }
|
2016-06-20 11:35:19 -07:00
|
|
|
key='points'
|
2016-07-15 14:42:47 -07:00
|
|
|
to='/settings'
|
2016-06-20 11:35:19 -07:00
|
|
|
>
|
2016-08-05 15:15:40 -07:00
|
|
|
<PointsNavItem
|
|
|
|
className='brownie-points-nav'
|
|
|
|
points={ points }
|
|
|
|
/>
|
2016-07-15 14:42:47 -07:00
|
|
|
</LinkContainer>
|
2015-07-24 21:54:19 -07:00
|
|
|
);
|
2016-01-27 11:34:44 -08:00
|
|
|
}
|
2015-07-24 21:54:19 -07:00
|
|
|
|
2016-06-20 11:35:19 -07:00
|
|
|
renderSignIn(username, picture, shouldShowSignIn) {
|
|
|
|
if (!shouldShowSignIn) {
|
|
|
|
return null;
|
|
|
|
}
|
2015-07-24 21:54:19 -07:00
|
|
|
if (username) {
|
2016-07-28 20:33:16 -07:00
|
|
|
return <AvatarNavItem picture={ picture } />;
|
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-09-08 21:56:46 -07:00
|
|
|
href='/signup'
|
|
|
|
key='signup'
|
2016-06-20 11:35:19 -07:00
|
|
|
>
|
2016-09-08 21:56:46 -07:00
|
|
|
Sign Up
|
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() {
|
2016-06-03 13:43:42 -07:00
|
|
|
const {
|
|
|
|
username,
|
|
|
|
points,
|
|
|
|
picture,
|
2016-06-27 20:11:52 -07:00
|
|
|
isOnMap,
|
2016-06-03 23:34:28 -07:00
|
|
|
toggleMapDrawer,
|
2016-06-20 11:35:19 -07:00
|
|
|
toggleMainChat,
|
|
|
|
shouldShowSignIn
|
2016-06-03 13:43:42 -07:00
|
|
|
} = 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'
|
2016-06-20 11:35:19 -07:00
|
|
|
fixedTop={ true }
|
|
|
|
>
|
2016-08-03 12:56:00 -07:00
|
|
|
<NavbarBrand>
|
|
|
|
<a
|
2016-08-04 14:51:31 -07:00
|
|
|
href='/challenges/current-challenge'
|
2016-08-03 12:56:00 -07:00
|
|
|
onClick={ this.handleLogoClick }
|
|
|
|
>
|
|
|
|
<img
|
|
|
|
alt='learn to code javascript at Free Code Camp logo'
|
|
|
|
className='img-responsive nav-logo'
|
|
|
|
src={ fCClogo }
|
|
|
|
/>
|
|
|
|
</a>
|
|
|
|
</NavbarBrand>
|
2015-11-19 15:47:43 -08:00
|
|
|
<Navbar.Toggle children={ toggleButtonChild } />
|
2016-07-28 20:33:16 -07:00
|
|
|
<Navbar.Collapse>
|
2015-07-24 21:54:19 -07:00
|
|
|
<Nav
|
|
|
|
className='hamburger-dropdown'
|
|
|
|
navbar={ true }
|
2016-06-20 11:35:19 -07:00
|
|
|
pullRight={ true }
|
|
|
|
>
|
2016-06-03 13:43:42 -07:00
|
|
|
{ this.renderMapLink(isOnMap, toggleMapDrawer) }
|
2016-06-03 23:34:28 -07:00
|
|
|
{ this.renderChat(toggleMainChat) }
|
2015-10-27 15:40:04 -07:00
|
|
|
{ this.renderLinks() }
|
2016-06-20 11:35:19 -07:00
|
|
|
{ this.renderPoints(username, points, shouldShowSignIn) }
|
|
|
|
{ this.renderSignIn(username, picture, shouldShowSignIn) }
|
2015-07-24 21:54:19 -07:00
|
|
|
</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
|
|
|
}
|