From 63a260ae860bb4b04ed96084cb24914c84728da5 Mon Sep 17 00:00:00 2001 From: Berkeley Martinez Date: Wed, 20 Jul 2016 16:30:39 -0700 Subject: [PATCH] Feature(challenges): Update title on challenge change --- .../app/routes/challenges/components/Show.jsx | 34 ++++++++++++------- .../routes/challenges/components/map/Map.jsx | 13 +++++-- 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/common/app/routes/challenges/components/Show.jsx b/common/app/routes/challenges/components/Show.jsx index 185b86152b..8a1b155a9b 100644 --- a/common/app/routes/challenges/components/Show.jsx +++ b/common/app/routes/challenges/components/Show.jsx @@ -17,6 +17,7 @@ import { resetUi } from '../redux/actions'; import { challengeSelector } from '../redux/selectors'; +import { updateTitle } from '../../../redux/actions'; const views = { step: Step, @@ -30,7 +31,8 @@ const bindableActions = { fetchChallenge, fetchChallenges, replaceChallenge, - resetUi + resetUi, + updateTitle }; const mapStateToProps = createSelector( @@ -59,29 +61,35 @@ export class Challenges extends PureComponent { static propTypes = { isStep: PropTypes.bool, - fetchChallenges: PropTypes.func, - replaceChallenge: PropTypes.func, - params: PropTypes.object, + fetchChallenges: PropTypes.func.isRequired, + replaceChallenge: PropTypes.func.isRequired, + params: PropTypes.object.isRequired, areChallengesLoaded: PropTypes.bool, - resetUi: PropTypes.func + resetUi: PropTypes.func.isRequired, + updateTitle: PropTypes.func.isRequired }; - componentWillUnmount() { - this.props.resetUi(); + componentWillMount() { + this.props.updateTitle(this.props.params.dashedName); } + componentDidMount() { if (!this.props.areChallengesLoaded) { this.props.fetchChallenges(); } } + componentWillUnmount() { + this.props.resetUi(); + } + componentWillReceiveProps(nextProps) { - if (this.props.params.dashedName !== nextProps.params.dashedName) { - this.props.resetUi(); - this.props.replaceChallenge({ - dashedName: nextProps.params.dashedName, - block: nextProps.params.block - }); + const { block, dashedName } = nextProps.params; + const { resetUi, updateTitle, replaceChallenge } = this.props; + if (this.props.params.dashedName !== dashedName) { + updateTitle(dashedName); + resetUi(); + replaceChallenge({ dashedName, block }); } } diff --git a/common/app/routes/challenges/components/map/Map.jsx b/common/app/routes/challenges/components/map/Map.jsx index a591918c42..3c5ffaa277 100644 --- a/common/app/routes/challenges/components/map/Map.jsx +++ b/common/app/routes/challenges/components/map/Map.jsx @@ -9,8 +9,9 @@ import { Col } from 'react-bootstrap'; import MapHeader from './Header.jsx'; import SuperBlock from './Super-Block.jsx'; import { fetchChallenges } from '../../redux/actions'; +import { updateTitle } from '../../../../redux/actions'; -const bindableActions = { fetchChallenges }; +const bindableActions = { fetchChallenges, updateTitle }; const mapStateToProps = createSelector( state => state.app.windowHeight, state => state.app.navHeight, @@ -30,9 +31,17 @@ export class ShowMap extends PureComponent { static displayName = 'Map'; static propTypes = { superBlocks: PropTypes.array, - height: PropTypes.number + height: PropTypes.number, + updateTitle: PropTypes.func.isRequired, + fetchChallenges: PropTypes.func.isRequired }; + componentWillMount() { + this.props.updateTitle( + 'A Map to Learn to Code and Become a Software Engineer' + ); + } + renderSuperBlocks(superBlocks) { if (!Array.isArray(superBlocks) || !superBlocks.length) { return
No Super Blocks
;