🎨 change logic of AnswerBox
Co-authored-by: haraldnilsen <harald_998@hotmail.com> Signed-off-by: Sindre Kjelsrud <kjelsrudsindre@gmail.com>
This commit is contained in:
parent
60ed8cab6c
commit
3cbf89e8b3
1 changed files with 13 additions and 20 deletions
|
@ -14,8 +14,6 @@
|
||||||
let questionAnswer2ID: number = 0
|
let questionAnswer2ID: number = 0
|
||||||
let questionNumber: number = 0
|
let questionNumber: number = 0
|
||||||
|
|
||||||
let shouldSwitch = false;
|
|
||||||
|
|
||||||
let question1Answered: boolean = false
|
let question1Answered: boolean = false
|
||||||
let question2Answered: boolean = false
|
let question2Answered: boolean = false
|
||||||
|
|
||||||
|
@ -31,10 +29,17 @@
|
||||||
if (localstoragequestions) {
|
if (localstoragequestions) {
|
||||||
let questions = JSON.parse(localstoragequestions).questions;
|
let questions = JSON.parse(localstoragequestions).questions;
|
||||||
formQuestion = questions[questionNumber].Question.QuestionText;
|
formQuestion = questions[questionNumber].Question.QuestionText;
|
||||||
|
if (Math.random() >= 0.5) {
|
||||||
questionAnswer1Text = questions[questionNumber].Answers[0].AnswerText;
|
questionAnswer1Text = questions[questionNumber].Answers[0].AnswerText;
|
||||||
questionAnswer1ID = questions[questionNumber].Answers[0].AnswerID;
|
questionAnswer1ID = questions[questionNumber].Answers[0].AnswerID;
|
||||||
questionAnswer2Text = questions[questionNumber].Answers[1].AnswerText;
|
questionAnswer2Text = questions[questionNumber].Answers[1].AnswerText;
|
||||||
questionAnswer2ID = questions[questionNumber].Answers[1].AnswerID;
|
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")
|
let allFormAnswers:string | null = localStorage.getItem("allFormAnswers")
|
||||||
|
@ -62,23 +67,12 @@
|
||||||
// On mount, call the update function
|
// On mount, call the update function
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
updateQuestionData();
|
updateQuestionData();
|
||||||
shouldSwitch = Math.random() >= 0.5;
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="flex flex-col h-full md:h-screen gap-10">
|
<div class="flex flex-col h-full md:h-screen gap-10">
|
||||||
<FormHeader questionNum={questionNumber} formQuestion={formQuestion}/>
|
<FormHeader questionNum={questionNumber} formQuestion={formQuestion}/>
|
||||||
<div class="flex flex-col md:flex-row h-full justify-between gap-12">
|
<div class="flex flex-col md:flex-row h-full justify-between gap-12">
|
||||||
{#if shouldSwitch}
|
|
||||||
{#key questionNumber}
|
|
||||||
<div class="flex-1">
|
|
||||||
<AnswerBox on:update={(e) => question2Answered = e.detail} answerNum={2} answerText={questionAnswer2Text} answerID={questionAnswer2ID}/>
|
|
||||||
</div>
|
|
||||||
<div class="flex-1">
|
|
||||||
<AnswerBox on:update={(e) => question1Answered = e.detail} answerNum={1} answerText={questionAnswer1Text} answerID={questionAnswer1ID}/>
|
|
||||||
</div>
|
|
||||||
{/key}
|
|
||||||
{:else}
|
|
||||||
{#key questionNumber}
|
{#key questionNumber}
|
||||||
<div class="flex-1">
|
<div class="flex-1">
|
||||||
<AnswerBox on:update={(e) => question1Answered = e.detail} answerNum={1} answerText={questionAnswer1Text} answerID={questionAnswer1ID}/>
|
<AnswerBox on:update={(e) => question1Answered = e.detail} answerNum={1} answerText={questionAnswer1Text} answerID={questionAnswer1ID}/>
|
||||||
|
@ -87,7 +81,6 @@
|
||||||
<AnswerBox on:update={(e) => question2Answered = e.detail} answerNum={2} answerText={questionAnswer2Text} answerID={questionAnswer2ID}/>
|
<AnswerBox on:update={(e) => question2Answered = e.detail} answerNum={2} answerText={questionAnswer2Text} answerID={questionAnswer2ID}/>
|
||||||
</div>
|
</div>
|
||||||
{/key}
|
{/key}
|
||||||
{/if}
|
|
||||||
</div>
|
</div>
|
||||||
{#key questionNumber}
|
{#key questionNumber}
|
||||||
<Footer answeredAll={question1Answered && question2Answered} questionNum={Number(questionNumber)}/>
|
<Footer answeredAll={question1Answered && question2Answered} questionNum={Number(questionNumber)}/>
|
||||||
|
|
Reference in a new issue