Feature(challenges): Update title on challenge change
This commit is contained in:
@ -17,6 +17,7 @@ import {
|
|||||||
resetUi
|
resetUi
|
||||||
} from '../redux/actions';
|
} from '../redux/actions';
|
||||||
import { challengeSelector } from '../redux/selectors';
|
import { challengeSelector } from '../redux/selectors';
|
||||||
|
import { updateTitle } from '../../../redux/actions';
|
||||||
|
|
||||||
const views = {
|
const views = {
|
||||||
step: Step,
|
step: Step,
|
||||||
@ -30,7 +31,8 @@ const bindableActions = {
|
|||||||
fetchChallenge,
|
fetchChallenge,
|
||||||
fetchChallenges,
|
fetchChallenges,
|
||||||
replaceChallenge,
|
replaceChallenge,
|
||||||
resetUi
|
resetUi,
|
||||||
|
updateTitle
|
||||||
};
|
};
|
||||||
|
|
||||||
const mapStateToProps = createSelector(
|
const mapStateToProps = createSelector(
|
||||||
@ -59,29 +61,35 @@ export class Challenges extends PureComponent {
|
|||||||
|
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
isStep: PropTypes.bool,
|
isStep: PropTypes.bool,
|
||||||
fetchChallenges: PropTypes.func,
|
fetchChallenges: PropTypes.func.isRequired,
|
||||||
replaceChallenge: PropTypes.func,
|
replaceChallenge: PropTypes.func.isRequired,
|
||||||
params: PropTypes.object,
|
params: PropTypes.object.isRequired,
|
||||||
areChallengesLoaded: PropTypes.bool,
|
areChallengesLoaded: PropTypes.bool,
|
||||||
resetUi: PropTypes.func
|
resetUi: PropTypes.func.isRequired,
|
||||||
|
updateTitle: PropTypes.func.isRequired
|
||||||
};
|
};
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillMount() {
|
||||||
this.props.resetUi();
|
this.props.updateTitle(this.props.params.dashedName);
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
if (!this.props.areChallengesLoaded) {
|
if (!this.props.areChallengesLoaded) {
|
||||||
this.props.fetchChallenges();
|
this.props.fetchChallenges();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillReceiveProps(nextProps) {
|
componentWillUnmount() {
|
||||||
if (this.props.params.dashedName !== nextProps.params.dashedName) {
|
|
||||||
this.props.resetUi();
|
this.props.resetUi();
|
||||||
this.props.replaceChallenge({
|
}
|
||||||
dashedName: nextProps.params.dashedName,
|
|
||||||
block: nextProps.params.block
|
componentWillReceiveProps(nextProps) {
|
||||||
});
|
const { block, dashedName } = nextProps.params;
|
||||||
|
const { resetUi, updateTitle, replaceChallenge } = this.props;
|
||||||
|
if (this.props.params.dashedName !== dashedName) {
|
||||||
|
updateTitle(dashedName);
|
||||||
|
resetUi();
|
||||||
|
replaceChallenge({ dashedName, block });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,8 +9,9 @@ import { Col } from 'react-bootstrap';
|
|||||||
import MapHeader from './Header.jsx';
|
import MapHeader from './Header.jsx';
|
||||||
import SuperBlock from './Super-Block.jsx';
|
import SuperBlock from './Super-Block.jsx';
|
||||||
import { fetchChallenges } from '../../redux/actions';
|
import { fetchChallenges } from '../../redux/actions';
|
||||||
|
import { updateTitle } from '../../../../redux/actions';
|
||||||
|
|
||||||
const bindableActions = { fetchChallenges };
|
const bindableActions = { fetchChallenges, updateTitle };
|
||||||
const mapStateToProps = createSelector(
|
const mapStateToProps = createSelector(
|
||||||
state => state.app.windowHeight,
|
state => state.app.windowHeight,
|
||||||
state => state.app.navHeight,
|
state => state.app.navHeight,
|
||||||
@ -30,9 +31,17 @@ export class ShowMap extends PureComponent {
|
|||||||
static displayName = 'Map';
|
static displayName = 'Map';
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
superBlocks: PropTypes.array,
|
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) {
|
renderSuperBlocks(superBlocks) {
|
||||||
if (!Array.isArray(superBlocks) || !superBlocks.length) {
|
if (!Array.isArray(superBlocks) || !superBlocks.length) {
|
||||||
return <div>No Super Blocks</div>;
|
return <div>No Super Blocks</div>;
|
||||||
|
Reference in New Issue
Block a user