fix(challenges): Call resetQuiz() when dashedName of the quiz chang (#16828)

currentIndex, selectedChoice and correct state variables of the Quiz
component were not changing when navigating to other quiz challenges
through map. I fixed it by calling resetQuiz() whenever dashedName of
the quiz changes.
This commit is contained in:
Yogesh Sharma
2018-03-07 19:04:22 +05:30
committed by Stuart Taylor
parent 53901aa822
commit 9b480bd0ea

View File

@ -62,13 +62,21 @@ const propTypes = {
correct: PropTypes.number, correct: PropTypes.number,
currentIndex: PropTypes.number, currentIndex: PropTypes.number,
dashedName: PropTypes.string, dashedName: PropTypes.string,
description: PropTypes.string, description: PropTypes.arrayOf(
PropTypes.shape({
answer: PropTypes.number,
choices: PropTypes.arrayOf(PropTypes.string),
explanation: PropTypes.string,
question: PropTypes.string,
subtitle: PropTypes.string
})
),
meta: PropTypes.object, meta: PropTypes.object,
nextQuestion: PropTypes.fun, nextQuestion: PropTypes.func,
resetChoice: PropTypes.fun, resetChoice: PropTypes.func,
resetQuiz: PropTypes.fun, resetQuiz: PropTypes.func,
selectedChoice: PropTypes.number, selectedChoice: PropTypes.number,
submitChallenge: PropTypes.fun submitChallenge: PropTypes.func
}; };
export class QuizChallenge extends PureComponent { export class QuizChallenge extends PureComponent {
@ -79,6 +87,12 @@ export class QuizChallenge extends PureComponent {
this.submitChallenge = this.submitChallenge.bind(this); this.submitChallenge = this.submitChallenge.bind(this);
} }
componentWillReceiveProps(nextProps) {
if (this.props.dashedName !== nextProps.dashedName) {
this.props.resetQuiz();
}
}
nextQuestion() { nextQuestion() {
this.props.resetChoice(); this.props.resetChoice();
this.props.nextQuestion(); this.props.nextQuestion();