✨ navigation between questions okaydokay
Co-authored-by: haraldnilsen <harald_998@hotmail.com> Signed-off-by: Sindre Kjelsrud <kjelsrudsindre@gmail.com>
This commit is contained in:
parent
77ad823803
commit
5d829273da
6 changed files with 56 additions and 39 deletions
|
@ -2,12 +2,13 @@
|
||||||
import UserFormInput from "../../userform/UserFormInput.svelte";
|
import UserFormInput from "../../userform/UserFormInput.svelte";
|
||||||
|
|
||||||
export let answerText:string
|
export let answerText:string
|
||||||
|
export let answerNum:number
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="flex flex-col">
|
<div class="flex flex-col">
|
||||||
<div class="flex flex-col gap-2 mb-6">
|
<div class="flex flex-col gap-2 mb-6">
|
||||||
<h1 class="text-xl text-primary font-bold text-center">Svar 2:</h1>
|
<h1 class="text-xl text-primary font-bold text-center">Svar {answerNum}:</h1>
|
||||||
<div class="bg-secondary p-6 rounded-xl text-sm">
|
<div class="bg-secondary p-6 rounded-xl text-sm">
|
||||||
{answerText}
|
{answerText}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,20 +1,30 @@
|
||||||
<script>
|
<script lang="ts">
|
||||||
import ArrowChevron from "../../svg/ArrowChevron.svelte";
|
import ArrowChevron from "../../svg/ArrowChevron.svelte";
|
||||||
import ButtonComponent from "../../userform/inputs/ButtonComponent.svelte";
|
import ButtonComponent from "../../userform/inputs/ButtonComponent.svelte";
|
||||||
|
import { goto } from "$app/navigation";
|
||||||
|
|
||||||
|
export let questionNum:number
|
||||||
|
|
||||||
|
const gotoNextPage = async (questionNum: number) => {
|
||||||
|
goto(`${questionNum + 1}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
const gotoPrevPage = async (questionNum: number) => {
|
||||||
|
goto(`${questionNum - 1}`)
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="flex justify-center items-center gap-8">
|
<div class="flex justify-center items-center gap-8">
|
||||||
<a href="/">
|
<button disabled={questionNum == 0} class={`flex items-center gap-2 text-primary font-semibold ${questionNum == 0 && "opacity-50"}`} on:click={() => gotoPrevPage(questionNum)}>
|
||||||
<button class="flex items-center gap-2 text-primary font-semibold">
|
|
||||||
<ArrowChevron width=16 direction="left"/>
|
<ArrowChevron width=16 direction="left"/>
|
||||||
Forrige spørsmål
|
Forrige spørsmål
|
||||||
</button>
|
</button>
|
||||||
</a>
|
<button disabled={questionNum == 0 || questionNum % 4 != 0}
|
||||||
<ButtonComponent text="Send inn svar" url="/" filled={true} />
|
class={`${questionNum == 0 || questionNum % 4 != 0 ? "text-primary opacity-50" : "bg-primary text-bg hover:bg-bg hover:text-primary"} font-bold uppercase border-primary border-2 rounded-full px-8 py-3`}>
|
||||||
<a href="/">
|
Send inn svar
|
||||||
<button class="flex items-center gap-2 text-primary font-semibold opacity-50">
|
</button>
|
||||||
|
<button disabled={questionNum != 0 && questionNum % 4 == 0} class={`flex items-center gap-2 text-primary font-semibold ${questionNum != 0 && questionNum % 4 == 0 && "opacity-50"}`} on:click={() => gotoNextPage(questionNum)}>
|
||||||
Neste spørsmål
|
Neste spørsmål
|
||||||
<ArrowChevron width=16 direction="right"/>
|
<ArrowChevron width=16 direction="right"/>
|
||||||
</button>
|
</button>
|
||||||
</a>
|
|
||||||
</div>
|
</div>
|
|
@ -2,12 +2,13 @@
|
||||||
import CircleExclamation from "../../../components/svg/CircleExclamation.svelte";
|
import CircleExclamation from "../../../components/svg/CircleExclamation.svelte";
|
||||||
|
|
||||||
export let formQuestion:string
|
export let formQuestion:string
|
||||||
|
export let questionNum:number
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="flex justify-center items-center h-20">
|
<div class="flex justify-center items-center h-20">
|
||||||
<div class="w-1/3"/>
|
<div class="w-1/3"/>
|
||||||
<div class="flex justify-center items-center w-2/3 gap-4">
|
<div class="flex justify-center items-center w-2/3 gap-4">
|
||||||
<h1 class="text-xl text-primary font-bold text-center">Spørsmål 3</h1>
|
<h1 class="text-xl text-primary font-bold text-center">Spørsmål {Number(questionNum) + 1}</h1>
|
||||||
<div class="border-r-2 border-primary h-24"></div>
|
<div class="border-r-2 border-primary h-24"></div>
|
||||||
<p class="text-sm">{formQuestion}</p>
|
<p class="text-sm">{formQuestion}</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
export let text: string;
|
export let text: string;
|
||||||
export let filled = false;
|
export let filled = false;
|
||||||
export let onclick: () => {};
|
export let onclick: any;
|
||||||
|
|
||||||
let style:string;
|
let style:string;
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
import FormHeader from "../../../components/form/header/FormHeader.svelte";
|
import FormHeader from "../../../components/form/header/FormHeader.svelte";
|
||||||
import AnswerBox from "../../../components/form/answerbox/AnswerBox.svelte";
|
import AnswerBox from "../../../components/form/answerbox/AnswerBox.svelte";
|
||||||
import Footer from "../../../components/form/footer/Footer.svelte";
|
import Footer from "../../../components/form/footer/Footer.svelte";
|
||||||
|
|
||||||
import { onMount } from "svelte"
|
import { onMount } from "svelte"
|
||||||
|
|
||||||
export let data;
|
export let data;
|
||||||
|
@ -10,31 +9,36 @@
|
||||||
let formQuestion: string = ""
|
let formQuestion: string = ""
|
||||||
let questionAnswer1: string = ""
|
let questionAnswer1: string = ""
|
||||||
let questionAnswer2: string = ""
|
let questionAnswer2: string = ""
|
||||||
|
let questionNumber: number = 0
|
||||||
|
|
||||||
onMount(async () => {
|
// Reactive statement to react on 'data.slug' changes
|
||||||
const questionNumber = data.slug
|
$: if (data && data.slug !== undefined) {
|
||||||
|
questionNumber = data.slug;
|
||||||
|
updateQuestionData();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Refactored data updating logic into a function
|
||||||
|
function updateQuestionData() {
|
||||||
let localstoragequestions = localStorage.getItem("userQuestions");
|
let localstoragequestions = localStorage.getItem("userQuestions");
|
||||||
if (localstoragequestions) {
|
if (localstoragequestions) {
|
||||||
let questions = JSON.parse(localstoragequestions).questions
|
let questions = JSON.parse(localstoragequestions).questions;
|
||||||
console.log(questions)
|
formQuestion = questions[questionNumber].Question.QuestionText;
|
||||||
formQuestion = questions[questionNumber].Question.QuestionText
|
questionAnswer1 = questions[questionNumber].Answers[0].AnswerText;
|
||||||
questionAnswer1 = questions[questionNumber].Answers[0].AnswerText
|
questionAnswer2 = questions[questionNumber].Answers[1].AnswerText;
|
||||||
questionAnswer2 = questions[questionNumber].Answers[1].AnswerText
|
}
|
||||||
console.log(formQuestion)
|
}
|
||||||
console.log(questionAnswer1)
|
|
||||||
console.log(questionAnswer2)
|
// On mount, call the update function
|
||||||
};
|
onMount(() => {
|
||||||
})
|
updateQuestionData();
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="flex flex-col h-full">
|
<div class="flex flex-col h-full">
|
||||||
<FormHeader formQuestion={formQuestion}/>
|
<FormHeader questionNum={questionNumber} formQuestion={formQuestion}/>
|
||||||
<div class="flex h-full justify-between gap-12">
|
<div class="flex h-full justify-between gap-12">
|
||||||
<AnswerBox answerText={questionAnswer1}/>
|
<AnswerBox answerNum={1} answerText={questionAnswer1}/>
|
||||||
<AnswerBox answerText={questionAnswer2}/>
|
<AnswerBox answerNum={2} answerText={questionAnswer2}/>
|
||||||
</div>
|
</div>
|
||||||
<Footer />
|
<Footer questionNum={Number(questionNumber)}/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<style lang="postcss">
|
|
||||||
</style>
|
|
|
@ -15,6 +15,7 @@
|
||||||
let firstUserQuestion: number = 0
|
let firstUserQuestion: number = 0
|
||||||
|
|
||||||
const handleUserformSubmit = async (age: string, education: string, healthcare_personnel: string, gender: string) => {
|
const handleUserformSubmit = async (age: string, education: string, healthcare_personnel: string, gender: string) => {
|
||||||
|
localStorage.clear()
|
||||||
const response = await postUserformData(age, education, healthcare_personnel, gender)
|
const response = await postUserformData(age, education, healthcare_personnel, gender)
|
||||||
const userQuestions = await getUserQuestions(response.respondentID)
|
const userQuestions = await getUserQuestions(response.respondentID)
|
||||||
|
|
||||||
|
|
Reference in a new issue