🐛 Fixed crash where switched from Range to Multiple Choice

This commit is contained in:
Mawoka
2022-08-17 21:30:53 +02:00
parent 81eb4f01c4
commit 12ec2ebf94
2 changed files with 87 additions and 76 deletions
@@ -19,12 +19,17 @@
export let selected_question: number;
export let data: EditorData;
console.log(
data.questions[selected_question].answers,
Array.isArray(data.questions[selected_question].answers)
);
if (!Array.isArray(data.questions[selected_question].answers)) {
data.questions[selected_question].answers = [];
}
</script>
<div class="grid grid-cols-2 gap-4 w-full px-10">
{#if Array.isArray(data.questions[selected_question].answers)}
{#each data.questions[selected_question].answers as answer, index}
<div
on:contextmenu|preventDefault={() => {
@@ -36,7 +41,9 @@
class="p-4 rounded-lg flex justify-center w-full transition"
class:bg-red-500={!answer.right}
class:bg-green-500={answer.right}
class:bg-yellow-500={!reach(ABCDQuestionSchema, 'answer').isValidSync(answer.answer)}
class:bg-yellow-500={!reach(ABCDQuestionSchema, 'answer').isValidSync(
answer.answer
)}
>
<input
bind:value={answer.answer}
@@ -85,6 +92,7 @@
</button>
</div>
{/each}
{/if}
{#if data.questions[selected_question].answers.length < 4}
<button
class="p-4 rounded-lg bg-transparent border-gray-500 border-2 hover:bg-gray-300 transition dark:hover:bg-gray-600"
+6 -3
View File
@@ -179,14 +179,16 @@
{/if}
{#if question.type === QuizQuestionType.ABCD}
<div class="grid grid-cols-2 gap-2">
{#if Array.isArray(question.answers)}
{#each question.answers as answer}
<span
class="whitespace-nowrap truncate rounded-lg p-0.5 text-sm text-center border border-gray-700"
class:bg-green-500={answer.right}
class:bg-red-500={!answer.right}
class:bg-yellow-500={!reach(ABCDQuestionSchema, 'answer').isValidSync(
answer.answer
)}
class:bg-yellow-500={!reach(
ABCDQuestionSchema,
'answer'
).isValidSync(answer.answer)}
use:tippy={{
content: answer.answer === '' ? 'Empty...' : answer.answer
}}
@@ -197,6 +199,7 @@
{/if}</span
>
{/each}
{/if}
</div>
{:else if question.type === QuizQuestionType.RANGE}
<p class="text-center text-sm p-0.5">