From 9eaff250e3a7d445bbdb890d8c035c2403935abd Mon Sep 17 00:00:00 2001 From: Delphine van Rossum <delphine.vanrossum@student.uclouvain.be> Date: Wed, 11 Dec 2024 13:55:46 +0000 Subject: [PATCH] correction on surveys --- frontend/src/routes/tests/[id]/+page.svelte | 41 +++++++++++++-------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/frontend/src/routes/tests/[id]/+page.svelte b/frontend/src/routes/tests/[id]/+page.svelte index 5fac9c32..93095006 100644 --- a/frontend/src/routes/tests/[id]/+page.svelte +++ b/frontend/src/routes/tests/[id]/+page.svelte @@ -31,6 +31,13 @@ let subStep = $state(0); let currentGroupId = $state(0); + survey.groups.sort((a, b) => { + //puts the demo questions first + if (a.demo === b.demo) { + return 0; + } + return a.demo ? -1 : 1; + }); let currentGroup = $derived(survey.groups[currentGroupId]); let questionsRandomized = $derived(getSortedQuestions(currentGroup)); let currentQuestionId = $state(0); @@ -76,20 +83,22 @@ } async function selectOption(option: string) { - if ( - !(await sendSurveyResponseAPI( - fetch, - code, - sid, - uid, - survey.id, - currentGroupId, - questionsRandomized[currentQuestionId]['_id'], - currentQuestion.options.findIndex((o: string) => o === option) + 1, - (new Date().getTime() - startTime) / 1000 - )) - ) { - return; + if (!currentGroup.demo) { + if ( + !(await sendSurveyResponseAPI( + fetch, + code, + sid, + uid, + survey.id, + currentGroup.id, + questionsRandomized[currentQuestionId].id, + currentQuestion.options.findIndex((o: string) => o === option) + 1, + (new Date().getTime() - startTime) / 1000 + )) + ) { + return; + } } if (currentQuestionId < questionsRandomized.length - 1) { setQuestionId(currentQuestionId + 1); @@ -114,8 +123,8 @@ sid, uid, survey.id, - currentGroupId, - questionsRandomized[currentQuestionId]['_id'], + currentGroup.id, + questionsRandomized[currentQuestionId].id, -1, (new Date().getTime() - startTime) / 1000, gapTexts -- GitLab