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:
committed by
Stuart Taylor
parent
53901aa822
commit
9b480bd0ea
@ -62,13 +62,21 @@ const propTypes = {
|
||||
correct: PropTypes.number,
|
||||
currentIndex: PropTypes.number,
|
||||
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,
|
||||
nextQuestion: PropTypes.fun,
|
||||
resetChoice: PropTypes.fun,
|
||||
resetQuiz: PropTypes.fun,
|
||||
nextQuestion: PropTypes.func,
|
||||
resetChoice: PropTypes.func,
|
||||
resetQuiz: PropTypes.func,
|
||||
selectedChoice: PropTypes.number,
|
||||
submitChallenge: PropTypes.fun
|
||||
submitChallenge: PropTypes.func
|
||||
};
|
||||
|
||||
export class QuizChallenge extends PureComponent {
|
||||
@ -79,6 +87,12 @@ export class QuizChallenge extends PureComponent {
|
||||
this.submitChallenge = this.submitChallenge.bind(this);
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
if (this.props.dashedName !== nextProps.dashedName) {
|
||||
this.props.resetQuiz();
|
||||
}
|
||||
}
|
||||
|
||||
nextQuestion() {
|
||||
this.props.resetChoice();
|
||||
this.props.nextQuestion();
|
||||
|
Reference in New Issue
Block a user