From c1721e5e8e06c3d863f3b2392995c9ecfdd05dbf Mon Sep 17 00:00:00 2001 From: haraldnilsen Date: Sun, 14 Jan 2024 20:13:36 +0100 Subject: [PATCH] :sparkles: functionality to skip question or end survey Co-authored-by: Sindre Kjelsrud --- .../src/components/form/footer/Footer.svelte | 58 ++++++++++++++----- .../components/form/header/FormHeader.svelte | 2 +- frontend/src/routes/evaluation/+page.svelte | 2 +- frontend/src/routes/form/[slug]/+page.svelte | 6 +- 4 files changed, 49 insertions(+), 19 deletions(-) diff --git a/frontend/src/components/form/footer/Footer.svelte b/frontend/src/components/form/footer/Footer.svelte index c6e8daf..e28ef39 100644 --- a/frontend/src/components/form/footer/Footer.svelte +++ b/frontend/src/components/form/footer/Footer.svelte @@ -6,14 +6,34 @@ export let questionNum:number export let answeredAll:boolean + export let answer1ID:number + export let answer2ID:number const gotoNextPage = async (questionNum: number) => { goto(`${questionNum + 1}`) } - + const gotoPrevPage = async (questionNum: number) => { goto(`${questionNum - 1}`) } + + const skipQuestion = async (questionNum: number) => { + let allFormAnswers:string | null = localStorage.getItem("allFormAnswers") + if (allFormAnswers) { + const convertedAnswers:[] = JSON.parse(allFormAnswers) + let result = convertedAnswers.filter((item) => item[0] != answer1ID && item[0] != answer2ID) + const localStorageResult = JSON.stringify(result) + localStorage.setItem("allFormAnswers", localStorageResult) + + if (questionNum != 0 && questionNum % 4 == 0) { + handleFormSubmit() + } else { + goto(`${questionNum + 1}`) + } + } else { + goto(`${questionNum + 1}`) + } + } const handleFormSubmit = async () => { let allFormAnswers:string | null = localStorage.getItem("allFormAnswers") @@ -27,17 +47,27 @@ -
- - - +
+
+ + + +
+
+ + +
\ No newline at end of file diff --git a/frontend/src/components/form/header/FormHeader.svelte b/frontend/src/components/form/header/FormHeader.svelte index e49b057..bcb9165 100644 --- a/frontend/src/components/form/header/FormHeader.svelte +++ b/frontend/src/components/form/header/FormHeader.svelte @@ -5,7 +5,7 @@ export let questionNum:number -
+

Spørsmål {Number(questionNum) + 1}

diff --git a/frontend/src/routes/evaluation/+page.svelte b/frontend/src/routes/evaluation/+page.svelte index 2862e7e..90600e5 100644 --- a/frontend/src/routes/evaluation/+page.svelte +++ b/frontend/src/routes/evaluation/+page.svelte @@ -17,7 +17,7 @@
-
+

Takk for at du tok deg tid!

Tusen takk for hjelpen i denne undersøkelsen! Vi setter stor pris på det og håper du får en fin dag videre.

Har du tid så setter vi veldig pris på om du skrevet en liten tilbakemelding til oss i tekstfeltet under:

diff --git a/frontend/src/routes/form/[slug]/+page.svelte b/frontend/src/routes/form/[slug]/+page.svelte index 5ab411f..97d974b 100644 --- a/frontend/src/routes/form/[slug]/+page.svelte +++ b/frontend/src/routes/form/[slug]/+page.svelte @@ -70,9 +70,9 @@ }); -
+
-
+
{#key questionNumber}
question1Answered = e.detail} answerNum={1} answerText={questionAnswer1Text} answerID={questionAnswer1ID}/> @@ -83,6 +83,6 @@ {/key}
{#key questionNumber} -
\ No newline at end of file