Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes repeat question on shuffle #187

Merged
merged 2 commits into from
Jan 3, 2024
Merged

Conversation

chyke007
Copy link
Contributor

@chyke007 chyke007 commented Jan 2, 2024

There is an issue when the shuffle is enabled in the Quiz component. It repeats questions, this is happening due to the view not re-rendering when the shuffleQuestions function is done shuffling the questions, so the old question still happen to be in the view.

Example:

Screen Shot 2024-01-02 at 3 22 05 PM

This repeats again as Question 5:

Screen Shot 2024-01-02 at 3 22 27 PM

Looking at the result page shows that the new shuffled questions. We can see question 1 correctly displayed
Screen Shot 2024-01-02 at 3 23 29 PM

This fix resolves the issue by rerendering the Core view and updating the active questions.

  useEffect(() => {
    setActiveQuestion(questions[currentQuestionIndex]);
  }, [questions]);

Copy link
Owner

@wingkwong wingkwong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we can just combine it with L42 - L44.

useEffect(() => {
    setActiveQuestion(questions[currentQuestionIndex]);
  }, [currentQuestionIndex, questions]);

@chyke007
Copy link
Contributor Author

chyke007 commented Jan 3, 2024

i think we can just combine it with L42 - L44.

useEffect(() => {
    setActiveQuestion(questions[currentQuestionIndex]);
  }, [currentQuestionIndex, questions]);

Done

@wingkwong wingkwong merged commit 4a2be64 into wingkwong:develop Jan 3, 2024
@chyke007 chyke007 deleted the patch-1 branch January 3, 2024 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants