From 9b480bd0ea26700c71ea5c43f3835a96197b4ee7 Mon Sep 17 00:00:00 2001 From: Yogesh Sharma Date: Wed, 7 Mar 2018 19:04:22 +0530 Subject: [PATCH] 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. --- .../app/routes/Challenges/views/quiz/Quiz.jsx | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/common/app/routes/Challenges/views/quiz/Quiz.jsx b/common/app/routes/Challenges/views/quiz/Quiz.jsx index 8638e319df..b5e0b17334 100644 --- a/common/app/routes/Challenges/views/quiz/Quiz.jsx +++ b/common/app/routes/Challenges/views/quiz/Quiz.jsx @@ -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();