🐛 Fixed crash where switched from Range to Multiple Choice
This commit is contained in:
@@ -19,12 +19,17 @@
|
|||||||
|
|
||||||
export let selected_question: number;
|
export let selected_question: number;
|
||||||
export let data: EditorData;
|
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)) {
|
if (!Array.isArray(data.questions[selected_question].answers)) {
|
||||||
data.questions[selected_question].answers = [];
|
data.questions[selected_question].answers = [];
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="grid grid-cols-2 gap-4 w-full px-10">
|
<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}
|
{#each data.questions[selected_question].answers as answer, index}
|
||||||
<div
|
<div
|
||||||
on:contextmenu|preventDefault={() => {
|
on:contextmenu|preventDefault={() => {
|
||||||
@@ -36,7 +41,9 @@
|
|||||||
class="p-4 rounded-lg flex justify-center w-full transition"
|
class="p-4 rounded-lg flex justify-center w-full transition"
|
||||||
class:bg-red-500={!answer.right}
|
class:bg-red-500={!answer.right}
|
||||||
class:bg-green-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
|
<input
|
||||||
bind:value={answer.answer}
|
bind:value={answer.answer}
|
||||||
@@ -85,6 +92,7 @@
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
{/each}
|
{/each}
|
||||||
|
{/if}
|
||||||
{#if data.questions[selected_question].answers.length < 4}
|
{#if data.questions[selected_question].answers.length < 4}
|
||||||
<button
|
<button
|
||||||
class="p-4 rounded-lg bg-transparent border-gray-500 border-2 hover:bg-gray-300 transition dark:hover:bg-gray-600"
|
class="p-4 rounded-lg bg-transparent border-gray-500 border-2 hover:bg-gray-300 transition dark:hover:bg-gray-600"
|
||||||
|
|||||||
@@ -179,14 +179,16 @@
|
|||||||
{/if}
|
{/if}
|
||||||
{#if question.type === QuizQuestionType.ABCD}
|
{#if question.type === QuizQuestionType.ABCD}
|
||||||
<div class="grid grid-cols-2 gap-2">
|
<div class="grid grid-cols-2 gap-2">
|
||||||
|
{#if Array.isArray(question.answers)}
|
||||||
{#each question.answers as answer}
|
{#each question.answers as answer}
|
||||||
<span
|
<span
|
||||||
class="whitespace-nowrap truncate rounded-lg p-0.5 text-sm text-center border border-gray-700"
|
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-green-500={answer.right}
|
||||||
class:bg-red-500={!answer.right}
|
class:bg-red-500={!answer.right}
|
||||||
class:bg-yellow-500={!reach(ABCDQuestionSchema, 'answer').isValidSync(
|
class:bg-yellow-500={!reach(
|
||||||
answer.answer
|
ABCDQuestionSchema,
|
||||||
)}
|
'answer'
|
||||||
|
).isValidSync(answer.answer)}
|
||||||
use:tippy={{
|
use:tippy={{
|
||||||
content: answer.answer === '' ? 'Empty...' : answer.answer
|
content: answer.answer === '' ? 'Empty...' : answer.answer
|
||||||
}}
|
}}
|
||||||
@@ -197,6 +199,7 @@
|
|||||||
{/if}</span
|
{/if}</span
|
||||||
>
|
>
|
||||||
{/each}
|
{/each}
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
{:else if question.type === QuizQuestionType.RANGE}
|
{:else if question.type === QuizQuestionType.RANGE}
|
||||||
<p class="text-center text-sm p-0.5">
|
<p class="text-center text-sm p-0.5">
|
||||||
|
|||||||
Reference in New Issue
Block a user