From 3cbf89e8b327781d002378ceec2e17358f8777d6 Mon Sep 17 00:00:00 2001 From: Sindre Kjelsrud Date: Sun, 14 Jan 2024 14:57:49 +0100 Subject: [PATCH] :art: change logic of AnswerBox Co-authored-by: haraldnilsen Signed-off-by: Sindre Kjelsrud --- frontend/src/routes/form/[slug]/+page.svelte | 33 ++++++++------------ 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/frontend/src/routes/form/[slug]/+page.svelte b/frontend/src/routes/form/[slug]/+page.svelte index 8b46552..5ab411f 100644 --- a/frontend/src/routes/form/[slug]/+page.svelte +++ b/frontend/src/routes/form/[slug]/+page.svelte @@ -14,8 +14,6 @@ let questionAnswer2ID: number = 0 let questionNumber: number = 0 - let shouldSwitch = false; - let question1Answered: boolean = false let question2Answered: boolean = false @@ -31,10 +29,17 @@ if (localstoragequestions) { let questions = JSON.parse(localstoragequestions).questions; formQuestion = questions[questionNumber].Question.QuestionText; - questionAnswer1Text = questions[questionNumber].Answers[0].AnswerText; - questionAnswer1ID = questions[questionNumber].Answers[0].AnswerID; - questionAnswer2Text = questions[questionNumber].Answers[1].AnswerText; - questionAnswer2ID = questions[questionNumber].Answers[1].AnswerID; + if (Math.random() >= 0.5) { + questionAnswer1Text = questions[questionNumber].Answers[0].AnswerText; + questionAnswer1ID = questions[questionNumber].Answers[0].AnswerID; + questionAnswer2Text = questions[questionNumber].Answers[1].AnswerText; + questionAnswer2ID = questions[questionNumber].Answers[1].AnswerID; + } else { + questionAnswer1Text = questions[questionNumber].Answers[1].AnswerText; + questionAnswer1ID = questions[questionNumber].Answers[1].AnswerID; + questionAnswer2Text = questions[questionNumber].Answers[0].AnswerText; + questionAnswer2ID = questions[questionNumber].Answers[0].AnswerID; + } } let allFormAnswers:string | null = localStorage.getItem("allFormAnswers") @@ -62,32 +67,20 @@ // On mount, call the update function onMount(() => { updateQuestionData(); - shouldSwitch = Math.random() >= 0.5; });
- {#if shouldSwitch} - {#key questionNumber} -
- question2Answered = e.detail} answerNum={2} answerText={questionAnswer2Text} answerID={questionAnswer2ID}/> -
-
- question1Answered = e.detail} answerNum={1} answerText={questionAnswer1Text} answerID={questionAnswer1ID}/> -
- {/key} - {:else} - {#key questionNumber} + {#key questionNumber}
question1Answered = e.detail} answerNum={1} answerText={questionAnswer1Text} answerID={questionAnswer1ID}/>
question2Answered = e.detail} answerNum={2} answerText={questionAnswer2Text} answerID={questionAnswer2ID}/>
- {/key} - {/if} + {/key}
{#key questionNumber}