import React, { PropTypes } from 'react';
import ReactDOM from 'react-dom';
import { LinkContainer } from 'react-router-bootstrap';
import {
Col,
Nav,
NavbarBrand,
Navbar,
NavItem
} from 'react-bootstrap';
import navLinks from './links.json';
import FCCNavItem from './NavItem.jsx';
import AvatarNavItem from './Avatar-Nav-Item.jsx';
const fCClogo = 'https://s3.amazonaws.com/freecodecamp/freecodecamp_logo.svg';
const toggleButtonChild = (
Menu
);
function handleNavLinkEvent(content) {
this.props.trackEvent({
category: 'Nav',
action: 'clicked',
label: `${content} link`
});
}
export default class extends React.Component {
constructor(...props) {
super(...props);
this.handleMapClickOnMap = this.handleMapClickOnMap.bind(this);
this.handleLogoClick = this.handleLogoClick.bind(this);
navLinks.forEach(({ content }) => {
this[`handle${content}Click`] = handleNavLinkEvent.bind(this, content);
});
}
static displayName = 'Nav';
static propTypes = {
points: PropTypes.number,
picture: PropTypes.string,
signedIn: PropTypes.bool,
username: PropTypes.string,
isOnMap: PropTypes.bool,
updateNavHeight: PropTypes.func,
toggleMapDrawer: PropTypes.func,
toggleMainChat: PropTypes.func,
shouldShowSignIn: PropTypes.bool,
trackEvent: PropTypes.func.isRequired,
loadCurrentChallenge: PropTypes.func.isRequired
};
componentDidMount() {
const navBar = ReactDOM.findDOMNode(this);
this.props.updateNavHeight(navBar.clientHeight);
}
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'
});
}
handleLogoClick(e) {
e.preventDefault();
this.props.loadCurrentChallenge();
}
renderMapLink(isOnMap, toggleMapDrawer) {
if (isOnMap) {
return (
Map
);
}
return (
{
if (!(e.ctrlKey || e.metaKey)) {
e.preventDefault();
toggleMapDrawer();
}
}}
target='/map'
>
Map
);
}
renderChat(toggleMainChat) {
return (
{
if (!(e.ctrlKey || e.metaKey)) {
e.preventDefault();
toggleMainChat();
}
}}
target='_blank'
>
Chat
);
}
renderLinks() {
return navLinks.map(({ content, link, react, target }, index) => {
if (react) {
return (
{ content }
);
}
return (
{ content }
);
});
}
renderPoints(username, points, shouldShowSignIn) {
if (!username || !shouldShowSignIn) {
return null;
}
return (
[ { points } ]
);
}
renderSignIn(username, picture, shouldShowSignIn) {
if (!shouldShowSignIn) {
return null;
}
if (username) {
return ;
} else {
return (
Sign In
);
}
}
render() {
const {
username,
points,
picture,
isOnMap,
toggleMapDrawer,
toggleMainChat,
shouldShowSignIn
} = this.props;
return (
);
}
}