✨ Improved public view for quizzes
This commit is contained in:
@@ -41,7 +41,12 @@ export const handle: Handle = async ({ event, resolve }) => {
|
|||||||
})
|
})
|
||||||
).text();
|
).text();
|
||||||
const resp = await resolve(event);
|
const resp = await resolve(event);
|
||||||
|
try {
|
||||||
resp.headers.set('Set-Cookie', res.headers.get('set-cookie'));
|
resp.headers.set('Set-Cookie', res.headers.get('set-cookie'));
|
||||||
|
} catch {
|
||||||
|
console.log('Cannot mutate immutable header');
|
||||||
|
}
|
||||||
|
|
||||||
return resp;
|
return resp;
|
||||||
} else {
|
} else {
|
||||||
event.locals.email = null;
|
event.locals.email = null;
|
||||||
|
|||||||
@@ -10,20 +10,26 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<h3 class="bg-white dark:bg-slate-800 m-0">
|
<h3 class="bg-transparent m-0">
|
||||||
<button
|
<button
|
||||||
aria-expanded={expanded}
|
aria-expanded={expanded}
|
||||||
on:click={() => (expanded = !expanded)}
|
on:click={() => (expanded = !expanded)}
|
||||||
class="bg-white dark:bg-slate-800 flex justify-between w-full border-none m-0 p-2"
|
class="bg-white dark:bg-gray-700 flex justify-between w-full border-none m-0 p-2 rounded-t-lg hover:bg-gray-200 dark:hover:bg-gray-500 transition"
|
||||||
|
class:rounded-b-lg={!expanded}
|
||||||
>{headerText}
|
>{headerText}
|
||||||
<svg viewBox="0 0 20 20" fill="none" class="my-auto">
|
<svg
|
||||||
<path class="vert" d="M10 1V19" stroke="black" stroke-width="2" />
|
viewBox="0 0 20 20"
|
||||||
<path d="M1 10L19 10" stroke="black" stroke-width="2" />
|
fill="none"
|
||||||
|
class="my-auto fill-black dark:fill-white"
|
||||||
|
stroke="currentColor"
|
||||||
|
>
|
||||||
|
<path class="vert" d="M10 1V19" stroke-width="2" stroke="currentColor" />
|
||||||
|
<path d="M1 10L19 10" stroke-width="2" stroke="currentColor" />
|
||||||
</svg>
|
</svg>
|
||||||
</button>
|
</button>
|
||||||
</h3>
|
</h3>
|
||||||
|
|
||||||
<div class="border-b-1 border-gray-500" class:hidden={!expanded}>
|
<div class:hidden={!expanded}>
|
||||||
<slot />
|
<slot />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -4,7 +4,9 @@
|
|||||||
- file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
- file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
-->
|
-->
|
||||||
<script lang="ts" context="module">
|
<script lang="ts" context="module">
|
||||||
export async function load({ params, fetch, session }) {
|
import type { Load } from '@sveltejs/kit';
|
||||||
|
|
||||||
|
export const load: Load = async ({ params, fetch, session }) => {
|
||||||
const { quiz_id } = params;
|
const { quiz_id } = params;
|
||||||
const res = await fetch(`/api/v1/quiz/get/public/${quiz_id}`);
|
const res = await fetch(`/api/v1/quiz/get/public/${quiz_id}`);
|
||||||
if (res.status === 404 || res.status === 400) {
|
if (res.status === 404 || res.status === 400) {
|
||||||
@@ -24,7 +26,7 @@
|
|||||||
status: 500
|
status: 500
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
@@ -130,13 +132,13 @@
|
|||||||
{#each quiz.questions as question, index_question}
|
{#each quiz.questions as question, index_question}
|
||||||
<div class="px-4 py-1">
|
<div class="px-4 py-1">
|
||||||
<CollapsSection headerText={question.question}>
|
<CollapsSection headerText={question.question}>
|
||||||
<div class="ml-8 grid grid-cols-1 gap-2 m-2 border border-black border-2">
|
<div class="grid grid-cols-1 gap-2 rounded-b-lg bg-white dark:bg-gray-700 -mt-1">
|
||||||
<h1 class="text-3xl m-1">{$t('words.question')} {index_question + 1}</h1>
|
<h3 class="text-3xl m-1 text-center">
|
||||||
|
{index_question + 1}: {question.question}
|
||||||
|
</h3>
|
||||||
|
|
||||||
<!-- <label class='m-1 flex flex-row gap-2 w-3/5'>-->
|
<!-- <label class='m-1 flex flex-row gap-2 w-3/5'>-->
|
||||||
<p class="text-black w-full bg-inherit text-black dark:text-gray-200">
|
|
||||||
{$t('words.question')}: {question.question}
|
|
||||||
</p>
|
|
||||||
<!-- </label>-->
|
<!-- </label>-->
|
||||||
{#if question.image}
|
{#if question.image}
|
||||||
<span>
|
<span>
|
||||||
@@ -144,44 +146,45 @@
|
|||||||
<img class="pl-8" src={question.image} alt="Not provided" />
|
<img class="pl-8" src={question.image} alt="Not provided" />
|
||||||
</span>
|
</span>
|
||||||
{/if}
|
{/if}
|
||||||
<span class="m-1 flex flex-row gap-2 w-3/5 flex-nowrap whitespace-nowrap">
|
<p
|
||||||
{$t('editor.time_in_seconds')}:
|
class="m-1 flex flex-row gap-2 flex-nowrap whitespace-nowrap w-full justify-center"
|
||||||
{question.time}
|
>
|
||||||
</span>
|
<svg
|
||||||
|
class="w-8 h-8 inline-block"
|
||||||
|
fill="none"
|
||||||
|
stroke="currentColor"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
><path
|
||||||
|
stroke-linecap="round"
|
||||||
|
stroke-linejoin="round"
|
||||||
|
stroke-width="2"
|
||||||
|
d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"
|
||||||
|
/></svg
|
||||||
|
>
|
||||||
|
<span class="text-lg">{question.time}s</span>
|
||||||
|
</p>
|
||||||
{#if question.type === QuizQuestionType.ABCD}
|
{#if question.type === QuizQuestionType.ABCD}
|
||||||
|
<div class="grid grid-cols-2 gap-4 m-4 p-6">
|
||||||
{#each question.answers as answer, index_answer}
|
{#each question.answers as answer, index_answer}
|
||||||
<div
|
<div
|
||||||
class="ml-8 grid grid-cols-1 gap-2 m-2 border border-black border-2 m-1"
|
class="p-1 rounded-lg py-4"
|
||||||
|
class:bg-green-500={answer.right}
|
||||||
|
class:bg-red-500={!answer.right}
|
||||||
>
|
>
|
||||||
<h1 class="text-3xl m-1">
|
<h4 class="text-center">
|
||||||
{$t('words.answer')}
|
{quiz.questions[index_question].answers[index_answer]
|
||||||
{index_answer + 1}
|
.answer}
|
||||||
</h1>
|
</h4>
|
||||||
<p class="m-1">
|
|
||||||
{$t('words.answer')}: {index_answer + 1}
|
|
||||||
{$t('words.question')}: {index_question + 1}
|
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
{$t('words.answer')}
|
|
||||||
: {quiz.questions[index_question].answers[index_answer].answer}
|
|
||||||
</p>
|
|
||||||
<label
|
|
||||||
class="m-1 flex flex-row gap-2 w-2/6 flex-nowrap whitespace-nowrap"
|
|
||||||
>
|
|
||||||
<input
|
|
||||||
type="checkbox"
|
|
||||||
bind:checked={answer.right}
|
|
||||||
class="text-black w-fit"
|
|
||||||
disabled
|
|
||||||
/>
|
|
||||||
<span class="w-fit">{$t('editor.right_or_true?')}</span>
|
|
||||||
</label>
|
|
||||||
</div>
|
</div>
|
||||||
{/each}
|
{/each}
|
||||||
|
</div>
|
||||||
{:else if question.type === QuizQuestionType.RANGE}
|
{:else if question.type === QuizQuestionType.RANGE}
|
||||||
|
<p class="m-1 text-center">
|
||||||
All numbers between {question.answers.min_correct}
|
All numbers between {question.answers.min_correct}
|
||||||
and {question.answers.max_correct} are correct, where numbers between {question
|
and {question.answers.max_correct} are correct, where numbers between {question
|
||||||
.answers.min} and {question.answers.max} can be selected.
|
.answers.min} and {question.answers.max} can be selected.
|
||||||
|
</p>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
</CollapsSection>
|
</CollapsSection>
|
||||||
|
|||||||
Reference in New Issue
Block a user