✨ Added Check Choice question type
This commit is contained in:
@@ -120,6 +120,7 @@ class QuizQuestionType(str, Enum):
|
|||||||
SLIDE = "SLIDE"
|
SLIDE = "SLIDE"
|
||||||
TEXT = "TEXT"
|
TEXT = "TEXT"
|
||||||
ORDER = "ORDER"
|
ORDER = "ORDER"
|
||||||
|
CHECK = "CHECK"
|
||||||
|
|
||||||
|
|
||||||
class TextQuizAnswer(BaseModel):
|
class TextQuizAnswer(BaseModel):
|
||||||
@@ -136,6 +137,7 @@ class QuizQuestion(BaseModel):
|
|||||||
|
|
||||||
@validator("answers")
|
@validator("answers")
|
||||||
def answers_not_none_if_abcd_type(cls, v, values):
|
def answers_not_none_if_abcd_type(cls, v, values):
|
||||||
|
print(values)
|
||||||
# print(values)
|
# print(values)
|
||||||
if values["type"] == QuizQuestionType.ABCD and type(v[0]) != ABCDQuizAnswer:
|
if values["type"] == QuizQuestionType.ABCD and type(v[0]) != ABCDQuizAnswer:
|
||||||
raise ValueError("Answers can't be none if type is ABCD")
|
raise ValueError("Answers can't be none if type is ABCD")
|
||||||
@@ -149,6 +151,8 @@ class QuizQuestion(BaseModel):
|
|||||||
raise ValueError("Answer must be from type VotingQuizAnswer if type is ORDER")
|
raise ValueError("Answer must be from type VotingQuizAnswer if type is ORDER")
|
||||||
if values["type"] == QuizQuestionType.SLIDE and type(v[0]) != str:
|
if values["type"] == QuizQuestionType.SLIDE and type(v[0]) != str:
|
||||||
raise ValueError("Answer must be from type SlideElement if type is SLIDE")
|
raise ValueError("Answer must be from type SlideElement if type is SLIDE")
|
||||||
|
if values["type"] == QuizQuestionType.CHECK and type(v[0]) != ABCDQuizAnswer:
|
||||||
|
raise ValueError("Answers can't be none if type is CHECK")
|
||||||
return v
|
return v
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -359,6 +359,15 @@ async def submit_answer(sid: str, data: dict):
|
|||||||
if data.answer.lower() == q.answer.lower():
|
if data.answer.lower() == q.answer.lower():
|
||||||
answer_right = True
|
answer_right = True
|
||||||
break
|
break
|
||||||
|
elif game_data.questions[int(data.question_index)].type == QuizQuestionType.CHECK:
|
||||||
|
correct_string = ""
|
||||||
|
for i, a in enumerate(game_data.questions[int(float(data.question_index))].answers):
|
||||||
|
if a.right:
|
||||||
|
correct_string += str(i)
|
||||||
|
if correct_string == data.answer:
|
||||||
|
answer_right = True
|
||||||
|
else:
|
||||||
|
answer_right = False
|
||||||
else:
|
else:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
latency = int(float((await sio.get_session(sid))["ping"]))
|
latency = int(float((await sio.get_session(sid))["ping"]))
|
||||||
|
|||||||
@@ -231,7 +231,7 @@
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
{#if quiz_data.questions[selected_question].type === QuizQuestionType.ABCD || quiz_data.questions[selected_question].type === QuizQuestionType.VOTING}
|
{#if quiz_data.questions[selected_question].type === QuizQuestionType.ABCD || quiz_data.questions[selected_question].type === QuizQuestionType.VOTING || quiz_data.questions[selected_question].type === QuizQuestionType.CHECK}
|
||||||
<div class="grid grid-rows-2 grid-flow-col auto-cols-auto gap-2 w-full p-4">
|
<div class="grid grid-rows-2 grid-flow-col auto-cols-auto gap-2 w-full p-4">
|
||||||
{#each quiz_data.questions[selected_question].answers as answer, i}
|
{#each quiz_data.questions[selected_question].answers as answer, i}
|
||||||
<div
|
<div
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
import { QuizQuestionType } from '$lib/quiz_types.js';
|
import { QuizQuestionType } from '$lib/quiz_types.js';
|
||||||
import { getLocalization } from '$lib/i18n';
|
import { getLocalization } from '$lib/i18n';
|
||||||
import StartGamePopup from './start_game.svelte';
|
import StartGamePopup from './start_game.svelte';
|
||||||
import { onMount } from 'svelte';
|
// import { onMount } from 'svelte';
|
||||||
import viewport from './useViewportAction.js';
|
import viewport from './useViewportAction.js';
|
||||||
import Spinner from '$lib/Spinner.svelte';
|
import Spinner from '$lib/Spinner.svelte';
|
||||||
import GrayButton from '$lib/components/buttons/gray.svelte';
|
import GrayButton from '$lib/components/buttons/gray.svelte';
|
||||||
@@ -34,12 +34,6 @@
|
|||||||
};
|
};
|
||||||
let visibleImages = Array.from(Array(quizzes.length), () => []);
|
let visibleImages = Array.from(Array(quizzes.length), () => []);
|
||||||
|
|
||||||
const close_start_game_if_esc_is_pressed = (key: KeyboardEvent) => {
|
|
||||||
if (key.code === 'Escape') {
|
|
||||||
start_game = null;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const copy_id = (quiz_id: string) => {
|
const copy_id = (quiz_id: string) => {
|
||||||
navigator.clipboard.writeText(quiz_id);
|
navigator.clipboard.writeText(quiz_id);
|
||||||
copy_toast_open = true;
|
copy_toast_open = true;
|
||||||
@@ -58,9 +52,9 @@
|
|||||||
game_in_lobby = await res.json();
|
game_in_lobby = await res.json();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
onMount(() => {
|
// onMount(() => {
|
||||||
document.body.addEventListener('keydown', close_start_game_if_esc_is_pressed);
|
// document.body.addEventListener('keydown', close_start_game_if_esc_is_pressed);
|
||||||
});
|
// });
|
||||||
|
|
||||||
get_game_in_lobby_fn();
|
get_game_in_lobby_fn();
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -4,7 +4,8 @@
|
|||||||
- 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">
|
<script lang="ts">
|
||||||
import type { EditorData, Answer } from '../quiz_types';
|
import type { Answer, EditorData } from '../quiz_types';
|
||||||
|
import { QuizQuestionType } from '../quiz_types';
|
||||||
import { fade } from 'svelte/transition';
|
import { fade } from 'svelte/transition';
|
||||||
import { reach } from 'yup';
|
import { reach } from 'yup';
|
||||||
import { ABCDQuestionSchema } from '$lib/yupSchemas';
|
import { ABCDQuestionSchema } from '$lib/yupSchemas';
|
||||||
@@ -18,6 +19,7 @@
|
|||||||
console.log(get_foreground_color(default_colors[0]));
|
console.log(get_foreground_color(default_colors[0]));
|
||||||
|
|
||||||
export let selected_question: number;
|
export let selected_question: number;
|
||||||
|
export let check_choice = false;
|
||||||
export let data: EditorData;
|
export let data: EditorData;
|
||||||
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 = [];
|
||||||
@@ -41,6 +43,9 @@
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
$: save_colors(data);
|
$: save_colors(data);
|
||||||
|
data.questions[selected_question].type = check_choice
|
||||||
|
? QuizQuestionType.ABCD
|
||||||
|
: QuizQuestionType.CHECK;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="grid grid-rows-2 grid-flow-col auto-cols-auto gap-4 w-full px-10">
|
<div class="grid grid-rows-2 grid-flow-col auto-cols-auto gap-4 w-full px-10">
|
||||||
|
|||||||
@@ -52,11 +52,11 @@
|
|||||||
set_unique();
|
set_unique();
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
if (typeof data.questions[selected_question].type !== QuizQuestionType) {
|
if (typeof data.questions[selected_question].type !== QuizQuestionType) {
|
||||||
console.log(data.questions[selected_question].type !== QuizQuestionType.ABCD || data.questions[selected_question].type !== QuizQuestionType.RANGE)
|
console.log(data.questions[selected_question].type !== QuizQuestionType.ABCD || data.questions[selected_question].type !== QuizQuestionType.RANGE)
|
||||||
data.questions[selected_question].type = QuizQuestionType.ABCD;
|
data.questions[selected_question].type = QuizQuestionType.ABCD;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="w-full max-h-full pb-20 px-20 h-full">
|
<div class="w-full max-h-full pb-20 px-20 h-full">
|
||||||
@@ -81,6 +81,7 @@
|
|||||||
<svelte:component this={c.default} bind:data={data.questions[selected_question]} />
|
<svelte:component this={c.default} bind:data={data.questions[selected_question]} />
|
||||||
{/await}
|
{/await}
|
||||||
{:else}
|
{:else}
|
||||||
|
{@const type = data.questions[selected_question].type}
|
||||||
<div class="flex flex-col">
|
<div class="flex flex-col">
|
||||||
<div class="flex justify-center pt-10 w-full">
|
<div class="flex justify-center pt-10 w-full">
|
||||||
{#key unique}
|
{#key unique}
|
||||||
@@ -194,30 +195,36 @@
|
|||||||
<option value={QuizQuestionType.VOTING}>{$t('words.voting')}</option>
|
<option value={QuizQuestionType.VOTING}>{$t('words.voting')}</option>
|
||||||
<option value={QuizQuestionType.TEXT}>{$t('words.text')}</option>
|
<option value={QuizQuestionType.TEXT}>{$t('words.text')}</option>
|
||||||
<option value={QuizQuestionType.ORDER}>{$t('words.order')}</option>
|
<option value={QuizQuestionType.ORDER}>{$t('words.order')}</option>
|
||||||
|
<option value={QuizQuestionType.CHECK}>{$t('words.check_choice')}</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex justify-center py-10 w-full">
|
<div class="flex justify-center py-10 w-full">
|
||||||
{#if data.questions[selected_question].type === QuizQuestionType.ABCD}
|
{#if type === QuizQuestionType.ABCD || QuizQuestionType.CHECK}
|
||||||
{#await import('$lib/editor/ABCDEditorPart.svelte')}
|
{#await import('$lib/editor/ABCDEditorPart.svelte')}
|
||||||
<Spinner my_20={false} />
|
<Spinner my_20={false} />
|
||||||
{:then c}
|
{:then c}
|
||||||
<svelte:component this={c.default} bind:data bind:selected_question />
|
<svelte:component
|
||||||
|
this={c.default}
|
||||||
|
bind:data
|
||||||
|
bind:selected_question
|
||||||
|
check_choice={type === QuizQuestionType.CHECK}
|
||||||
|
/>
|
||||||
{/await}
|
{/await}
|
||||||
{:else if data.questions[selected_question].type === QuizQuestionType.RANGE}
|
{:else if type === QuizQuestionType.RANGE}
|
||||||
<RangeEditor bind:selected_question bind:data />
|
<RangeEditor bind:selected_question bind:data />
|
||||||
{:else if data.questions[selected_question].type === QuizQuestionType.VOTING}
|
{:else if type === QuizQuestionType.VOTING}
|
||||||
{#await import('$lib/editor/VotingEditorPart.svelte')}
|
{#await import('$lib/editor/VotingEditorPart.svelte')}
|
||||||
<Spinner my_20={false} />
|
<Spinner my_20={false} />
|
||||||
{:then c}
|
{:then c}
|
||||||
<svelte:component this={c.default} bind:data bind:selected_question />
|
<svelte:component this={c.default} bind:data bind:selected_question />
|
||||||
{/await}
|
{/await}
|
||||||
{:else if data.questions[selected_question].type === QuizQuestionType.TEXT}
|
{:else if type === QuizQuestionType.TEXT}
|
||||||
{#await import('$lib/editor/TextEditorPart.svelte')}
|
{#await import('$lib/editor/TextEditorPart.svelte')}
|
||||||
<Spinner my_20={false} />
|
<Spinner my_20={false} />
|
||||||
{:then c}
|
{:then c}
|
||||||
<svelte:component this={c.default} bind:data bind:selected_question />
|
<svelte:component this={c.default} bind:data bind:selected_question />
|
||||||
{/await}
|
{/await}
|
||||||
{:else if data.questions[selected_question].type === QuizQuestionType.ORDER}
|
{:else if type === QuizQuestionType.ORDER}
|
||||||
{#await import('$lib/editor/OrderEditorPart.svelte')}
|
{#await import('$lib/editor/OrderEditorPart.svelte')}
|
||||||
<Spinner my_20={false} />
|
<Spinner my_20={false} />
|
||||||
{:then c}
|
{:then c}
|
||||||
|
|||||||
@@ -211,7 +211,7 @@
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
{#if question.type === QuizQuestionType.ABCD}
|
{#if question.type === QuizQuestionType.ABCD || question.type === QuizQuestionType.CHECK}
|
||||||
<div class="grid grid-cols-2 gap-2">
|
<div class="grid grid-cols-2 gap-2">
|
||||||
{#if Array.isArray(question.answers)}
|
{#if Array.isArray(question.answers)}
|
||||||
{#each question.answers as answer}
|
{#each question.answers as answer}
|
||||||
|
|||||||
@@ -174,7 +174,8 @@
|
|||||||
"select": "Select",
|
"select": "Select",
|
||||||
"quiz": "Quiz",
|
"quiz": "Quiz",
|
||||||
"quiztivity": "Quiztivity",
|
"quiztivity": "Quiztivity",
|
||||||
"next": "Next"
|
"next": "Next",
|
||||||
|
"check_choice": "Check Choice"
|
||||||
},
|
},
|
||||||
"editor": {
|
"editor": {
|
||||||
"time_in_seconds": "Time in seconds",
|
"time_in_seconds": "Time in seconds",
|
||||||
|
|||||||
@@ -32,10 +32,10 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* if (typeof question_index === 'string') {
|
/* if (typeof question_index === 'string') {
|
||||||
question_index = parseInt(question_index);
|
question_index = parseInt(question_index);
|
||||||
} else {
|
} else {
|
||||||
throw new Error('question_index must be a string or number');
|
throw new Error('question_index must be a string or number');
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
let timer_res = question.time;
|
let timer_res = question.time;
|
||||||
let selected_answer: string;
|
let selected_answer: string;
|
||||||
@@ -251,30 +251,6 @@
|
|||||||
</BrownButton>
|
</BrownButton>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{:else if question.type === QuizQuestionType.ABCD}
|
|
||||||
{#if solution === undefined}
|
|
||||||
<Spinner />
|
|
||||||
{:else}
|
|
||||||
<div class="grid grid-rows-2 grid-flow-col auto-cols-auto gap-2 w-full p-4">
|
|
||||||
{#each solution.answers as answer}
|
|
||||||
{#if answer.right}
|
|
||||||
<button
|
|
||||||
class="text-3xl rounded-lg h-fit flex align-middle justify-center p-3 bg-green-600"
|
|
||||||
disabled
|
|
||||||
class:opacity-30={answer.answer !== selected_answer}
|
|
||||||
>{answer.answer}</button
|
|
||||||
>
|
|
||||||
{:else}
|
|
||||||
<button
|
|
||||||
class="text-3xl rounded-lg h-fit flex align-middle justify-center p-3 bg-red-500"
|
|
||||||
disabled
|
|
||||||
class:opacity-30={answer.answer !== selected_answer}
|
|
||||||
>{answer.answer}</button
|
|
||||||
>
|
|
||||||
{/if}
|
|
||||||
{/each}
|
|
||||||
</div>
|
|
||||||
{/if}
|
|
||||||
{:else if question.type === QuizQuestionType.RANGE}
|
{:else if question.type === QuizQuestionType.RANGE}
|
||||||
{#if solution === undefined}
|
{#if solution === undefined}
|
||||||
<Spinner />
|
<Spinner />
|
||||||
@@ -291,8 +267,8 @@
|
|||||||
{/if}
|
{/if}
|
||||||
{:else if question.type === QuizQuestionType.ORDER}
|
{:else if question.type === QuizQuestionType.ORDER}
|
||||||
<!-- {#if solution === undefined}
|
<!-- {#if solution === undefined}
|
||||||
<Spinner />
|
<Spinner />
|
||||||
{:else}-->
|
{:else}-->
|
||||||
<div class="flex flex-col w-full h-full gap-4 px-4 py-6">
|
<div class="flex flex-col w-full h-full gap-4 px-4 py-6">
|
||||||
{#each question.answers as answer, i (answer.id)}
|
{#each question.answers as answer, i (answer.id)}
|
||||||
<div
|
<div
|
||||||
@@ -365,14 +341,34 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!--{/if}-->
|
<!--{/if}-->
|
||||||
|
{:else if question.type === QuizQuestionType.CHECK}
|
||||||
|
{#await import('./questions/check.svelte')}
|
||||||
|
<Spinner />
|
||||||
|
{:then c}
|
||||||
|
<svelte:component
|
||||||
|
this={c.default}
|
||||||
|
bind:question
|
||||||
|
bind:selected_answer
|
||||||
|
bind:game_mode
|
||||||
|
/>
|
||||||
|
<div class="flex justify-center h-[5%]">
|
||||||
|
<div class="w-1/2">
|
||||||
|
<BrownButton
|
||||||
|
disabled={!selected_answer}
|
||||||
|
on:click={() => selectAnswer(selected_answer)}
|
||||||
|
>{$t('words.submit')}
|
||||||
|
</BrownButton>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{/await}
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<!--{:else if question.type === QuizQuestionType.VOTING}
|
<!--{:else if question.type === QuizQuestionType.VOTING}
|
||||||
{#await import('$lib/play/admin/voting_results.svelte')}
|
{#await import('$lib/play/admin/voting_results.svelte')}
|
||||||
<Spinner />
|
<Spinner />
|
||||||
{:then c}
|
{:then c}
|
||||||
<svelte:component this={c.default} bind:data={question_results}
|
<svelte:component this={c.default} bind:data={question_results}
|
||||||
bind:question={quiz_data.questions[selected_question]} />
|
bind:question={quiz_data.questions[selected_question]} />
|
||||||
{/await}-->
|
{/await}-->
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -0,0 +1,63 @@
|
|||||||
|
<!--
|
||||||
|
- This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
- License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
- file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<script lang="ts">
|
||||||
|
import type { Question } from '$lib/quiz_types';
|
||||||
|
import { get_foreground_color } from '$lib/helpers';
|
||||||
|
import { kahoot_icons } from '$lib/play/kahoot_mode_assets/kahoot_icons';
|
||||||
|
// import CircularTimer from '$lib/play/circular_progress.svelte';
|
||||||
|
const default_colors = ['#D6EDC9', '#B07156', '#7F7057', '#4E6E58'];
|
||||||
|
export let question: Question;
|
||||||
|
export let selected_answer = '';
|
||||||
|
export let game_mode;
|
||||||
|
let _selected_answers = [false, false, false, false];
|
||||||
|
|
||||||
|
const selectAnswer = (i: number) => {
|
||||||
|
_selected_answers[i] = !_selected_answers[i];
|
||||||
|
selected_answer = '';
|
||||||
|
for (let i = 0; i < _selected_answers.length; i++) {
|
||||||
|
if (_selected_answers[i]) {
|
||||||
|
selected_answer += String(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
selected_answer = selected_answer;
|
||||||
|
console.log(_selected_answers, selected_answer);
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="w-full h-[95%]">
|
||||||
|
<!--
|
||||||
|
<div
|
||||||
|
class="absolute top-0 bottom-0 left-0 right-0 m-auto rounded-full h-fit w-fit border-2 border-black shadow-2xl z-50"
|
||||||
|
>
|
||||||
|
<CircularTimer
|
||||||
|
bind:text={timer_res}
|
||||||
|
bind:progress={circular_prgoress}
|
||||||
|
color="#ef4444"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
-->
|
||||||
|
|
||||||
|
<div class="grid grid-rows-2 grid-flow-col auto-cols-auto gap-2 w-full p-4 h-full">
|
||||||
|
{#each question.answers as answer, i}
|
||||||
|
<button
|
||||||
|
class="rounded-lg h-full flex align-middle justify-center disabled:opacity-60 p-3 border-2 border-black opacity-50 transition-all"
|
||||||
|
style="background-color: {answer.color ??
|
||||||
|
default_colors[i]}; color: {get_foreground_color(
|
||||||
|
answer.color ?? default_colors[i]
|
||||||
|
)}"
|
||||||
|
on:click={() => selectAnswer(i)}
|
||||||
|
class:opacity-100={_selected_answers[i]}
|
||||||
|
>
|
||||||
|
{#if game_mode === 'kahoot'}
|
||||||
|
<img class="h-2/3 inline-block m-auto" alt="Icon" src={kahoot_icons[i]} />
|
||||||
|
{:else}
|
||||||
|
<p class="m-auto">{answer.answer}</p>
|
||||||
|
{/if}
|
||||||
|
</button>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -31,7 +31,8 @@ export enum QuizQuestionType {
|
|||||||
VOTING = 'VOTING', // eslint-disable-line no-unused-vars
|
VOTING = 'VOTING', // eslint-disable-line no-unused-vars
|
||||||
SLIDE = 'SLIDE', // eslint-disable-line no-unused-vars
|
SLIDE = 'SLIDE', // eslint-disable-line no-unused-vars
|
||||||
TEXT = 'TEXT', // eslint-disable-line no-unused-vars
|
TEXT = 'TEXT', // eslint-disable-line no-unused-vars
|
||||||
ORDER = 'ORDER' // eslint-disable-line no-unused-vars
|
ORDER = 'ORDER', // eslint-disable-line no-unused-vars
|
||||||
|
CHECK = 'CHECK' // eslint-disable-line no-unused-vars
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface RangeQuizAnswer {
|
export interface RangeQuizAnswer {
|
||||||
|
|||||||
@@ -6,10 +6,11 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { QuizQuestionType } from '$lib/quiz_types';
|
import { QuizQuestionType } from '$lib/quiz_types';
|
||||||
import { getLocalization } from '$lib/i18n';
|
import { getLocalization } from '$lib/i18n';
|
||||||
|
import type { Question } from '$lib/quiz_types';
|
||||||
|
|
||||||
const { t } = getLocalization();
|
const { t } = getLocalization();
|
||||||
|
|
||||||
export let question;
|
export let question: Question;
|
||||||
|
|
||||||
interface Answer {
|
interface Answer {
|
||||||
username: string;
|
username: string;
|
||||||
@@ -24,8 +25,23 @@
|
|||||||
|
|
||||||
const get_answer_count_for_answer = (answer: string): number => {
|
const get_answer_count_for_answer = (answer: string): number => {
|
||||||
let count = 0;
|
let count = 0;
|
||||||
for (const a of answers) {
|
let answer_id = 0;
|
||||||
if (a.answer === answer) {
|
if (question.type === QuizQuestionType.CHECK) {
|
||||||
|
for (let i = 0; i < question.answers.length; i++) {
|
||||||
|
if (answer === question.answers[i].answer) {
|
||||||
|
answer_id = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (let i = 0; i < answers.length; i++) {
|
||||||
|
const a = answers[i];
|
||||||
|
if (question.type === QuizQuestionType.CHECK) {
|
||||||
|
console.log(a.answer.includes('2'), answer_id);
|
||||||
|
if (a.answer.includes(String(answer_id))) {
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
} else if (a.answer === answer) {
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -79,8 +95,8 @@
|
|||||||
<th class="p-1 mx-auto">{$t('words.answer')} </th>
|
<th class="p-1 mx-auto">{$t('words.answer')} </th>
|
||||||
{#if question.type !== QuizQuestionType.VOTING}
|
{#if question.type !== QuizQuestionType.VOTING}
|
||||||
<th class="border-l dark:border-gray-500 p-1 mx-auto border-gray-300"
|
<th class="border-l dark:border-gray-500 p-1 mx-auto border-gray-300"
|
||||||
>{$t('words.correct')}?</th
|
>{$t('words.correct')}?
|
||||||
>
|
</th>
|
||||||
{/if}
|
{/if}
|
||||||
</tr>
|
</tr>
|
||||||
{#each answers as answer}
|
{#each answers as answer}
|
||||||
|
|||||||
@@ -211,7 +211,7 @@
|
|||||||
</svg>
|
</svg>
|
||||||
<span class="text-lg">{question.time}s</span>
|
<span class="text-lg">{question.time}s</span>
|
||||||
</p>
|
</p>
|
||||||
{#if question.type === QuizQuestionType.ABCD || question.type === undefined}
|
{#if question.type === QuizQuestionType.ABCD || question.type === undefined || question.type === QuizQuestionType.CHECK}
|
||||||
<div class="grid grid-cols-2 gap-4 m-4 p-6">
|
<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
|
||||||
|
|||||||
Reference in New Issue
Block a user