From e0855a2c1be30210f35e51a3b502031b59556de8 Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Wed, 31 Jul 2024 22:30:29 +0530 Subject: [PATCH] fix: quiz question population issue --- frontend/src/components/Quiz.vue | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/frontend/src/components/Quiz.vue b/frontend/src/components/Quiz.vue index 9d1691e4..44149e6d 100644 --- a/frontend/src/components/Quiz.vue +++ b/frontend/src/components/Quiz.vue @@ -269,17 +269,19 @@ const quiz = createResource({ cache: ['quiz', props.quizName], auto: true, onSuccess(data) { - shuffleQuiz() + populateQuestions() }, }) -const shuffleQuiz = () => { +const populateQuestions = () => { let data = quiz.data if (data.shuffle_questions) { questions = shuffleArray(data.questions) - } - if (data.limit_questions_to) { - questions = questions.slice(0, data.limit_questions_to) + if (data.limit_questions_to) { + questions = questions.slice(0, data.limit_questions_to) + } + } else { + questions = data.questions } } @@ -322,7 +324,7 @@ const attempts = createResource({ watch( () => quiz.data, () => { - if (quiz.data) { + if (quiz.data && quiz.data.max_attempts) { attempts.reload() resetQuiz() } @@ -476,7 +478,7 @@ const submitQuiz = () => { const createSubmission = () => { quizSubmission.reload().then(() => { - attempts.reload() + if (quiz.data && quiz.data.max_attempts) attempts.reload() }) } @@ -485,7 +487,7 @@ const resetQuiz = () => { selectedOptions.splice(0, selectedOptions.length, ...[0, 0, 0, 0]) showAnswers.length = 0 quizSubmission.reset() - shuffleQuiz() + populateQuestions() } const getSubmissionColumns = () => {