From dfa5acde60d26b116e4fb816b7d3f55e67abc236 Mon Sep 17 00:00:00 2001 From: Berkeley Martinez Date: Thu, 19 Nov 2015 22:45:31 -0800 Subject: [PATCH] Add learn button to navbar --- common/app/components/Nav/Nav.jsx | 29 ++++++++++++++++++++++++ common/app/components/Nav/links.json | 4 ++++ common/app/components/NotFound/index.js | 14 ------------ common/app/components/NotFound/index.jsx | 22 ++++++++++++++++++ common/app/routes/index.js | 7 +++++- 5 files changed, 61 insertions(+), 15 deletions(-) delete mode 100644 common/app/components/NotFound/index.js create mode 100644 common/app/components/NotFound/index.jsx diff --git a/common/app/components/Nav/Nav.jsx b/common/app/components/Nav/Nav.jsx index b508a16b92..0184e1d67c 100644 --- a/common/app/components/Nav/Nav.jsx +++ b/common/app/components/Nav/Nav.jsx @@ -12,6 +12,7 @@ import { import navLinks from './links.json'; import FCCNavItem from './NavItem.jsx'; +const win = typeof window !== 'undefined' ? window : {}; const fCClogo = 'https://s3.amazonaws.com/freecodecamp/freecodecamp_logo.svg'; const logoElement = ( @@ -31,6 +32,16 @@ const toggleButton = ( ); +function getDashedName() { + let challengeDashedName; + if (typeof win.localStorage !== 'undefined') { + challengeDashedName = win.localStorage.getItem('currentDashedName'); + } + return challengeDashedName && challengeDashedName !== 'undefined' ? + challengeDashedName : + ''; +} + export default React.createClass({ displayName: 'Nav', @@ -68,6 +79,22 @@ export default React.createClass({ }); }, + renderLearnBtn() { + return ( + { + const challengeDashedName = getDashedName(); + const goTo = challengeDashedName ? + '/challenges/' + challengeDashedName : + '/map'; + win.location = goTo; + }}> + Learn + + ); + }, + renderPoints(username, points) { if (!username) { return null; @@ -107,6 +134,7 @@ export default React.createClass({ render() { const { username, points, picture } = this.props; + return ( + { this.renderLearnBtn() } { this.renderLinks() } { this.renderPoints(username, points) } { this.renderSignin(username, picture) } diff --git a/common/app/components/Nav/links.json b/common/app/components/Nav/links.json index 79cb418e11..9492a69f6b 100644 --- a/common/app/components/Nav/links.json +++ b/common/app/components/Nav/links.json @@ -17,4 +17,8 @@ "content": "Jobs", "link": "/jobs", "react": true +},{ + "content": "Links", + "link": "/links" +},{ }] diff --git a/common/app/components/NotFound/index.js b/common/app/components/NotFound/index.js deleted file mode 100644 index 8206b46115..0000000000 --- a/common/app/components/NotFound/index.js +++ /dev/null @@ -1,14 +0,0 @@ -import React from 'react'; - -export default class extends React.Component { - constructor(props) { - super(props); - } - static displayName = 'NotFound' - static propTypes = {} - componentDidMount() { - } - render() { - return null; - } -} diff --git a/common/app/components/NotFound/index.jsx b/common/app/components/NotFound/index.jsx new file mode 100644 index 0000000000..eb634a2f0d --- /dev/null +++ b/common/app/components/NotFound/index.jsx @@ -0,0 +1,22 @@ +import React, { PropTypes } from 'react'; + +const win = typeof window !== 'undefined' ? window : {}; + +function goToServer(path) { + win.location = '/' + path; +} + +export default React.createClass({ + displayName: 'NotFound', + propTypes: { + params: PropTypes.object + }, + componentWillMount() { + goToServer(this.props.params.splat); + }, + componentDidMount() { + }, + render() { + return ; + } +}); diff --git a/common/app/routes/index.js b/common/app/routes/index.js index 1f14733f82..1dd1b704fd 100644 --- a/common/app/routes/index.js +++ b/common/app/routes/index.js @@ -1,10 +1,15 @@ import Jobs from './Jobs'; import Hikes from './Hikes'; +import NotFound from '../components/NotFound/index.jsx'; export default { path: '/', childRoutes: [ Jobs, - Hikes + Hikes, + { + path: '*', + component: NotFound + } ] };