Fix(challenges): Reset challenge ui on unmount

This commit is contained in:
Berkeley Martinez
2016-06-20 21:12:41 -07:00
parent fab3d72dce
commit 60cd5c76f8

View File

@ -13,7 +13,8 @@ import Video from './video/Video.jsx';
import { import {
fetchChallenge, fetchChallenge,
fetchChallenges, fetchChallenges,
replaceChallenge replaceChallenge,
resetUi
} from '../redux/actions'; } from '../redux/actions';
import { challengeSelector } from '../redux/selectors'; import { challengeSelector } from '../redux/selectors';
@ -28,7 +29,8 @@ const views = {
const bindableActions = { const bindableActions = {
fetchChallenge, fetchChallenge,
fetchChallenges, fetchChallenges,
replaceChallenge replaceChallenge,
resetUi
}; };
const mapStateToProps = createSelector( const mapStateToProps = createSelector(
@ -60,9 +62,13 @@ export class Challenges extends PureComponent {
fetchChallenges: PropTypes.func, fetchChallenges: PropTypes.func,
replaceChallenge: PropTypes.func, replaceChallenge: PropTypes.func,
params: PropTypes.object, params: PropTypes.object,
areChallengesLoaded: PropTypes.bool areChallengesLoaded: PropTypes.bool,
resetUi: PropTypes.func
}; };
componentWillUnmount() {
this.props.resetUi();
}
componentDidMount() { componentDidMount() {
if (!this.props.areChallengesLoaded) { if (!this.props.areChallengesLoaded) {
this.props.fetchChallenges(); this.props.fetchChallenges();
@ -71,6 +77,7 @@ export class Challenges extends PureComponent {
componentWillReceiveProps(nextProps) { componentWillReceiveProps(nextProps) {
if (this.props.params.dashedName !== nextProps.params.dashedName) { if (this.props.params.dashedName !== nextProps.params.dashedName) {
this.props.resetUi();
this.props.replaceChallenge({ this.props.replaceChallenge({
dashedName: nextProps.params.dashedName, dashedName: nextProps.params.dashedName,
block: nextProps.params.block block: nextProps.params.block