diff --git a/classquiz/db/models.py b/classquiz/db/models.py index 6482e41..ae63ff4 100644 --- a/classquiz/db/models.py +++ b/classquiz/db/models.py @@ -158,6 +158,7 @@ class PlayGame(BaseModel): started: bool = False captcha_enabled: bool = False cover_image: str | None + game_mode: str | None class GamePlayer(BaseModel): diff --git a/classquiz/routers/quiz.py b/classquiz/routers/quiz.py index a9227b9..e14294e 100644 --- a/classquiz/routers/quiz.py +++ b/classquiz/routers/quiz.py @@ -90,7 +90,9 @@ async def get_public_quiz(quiz_id: str): @router.post("/start/{quiz_id}") -async def start_quiz(quiz_id: str, captcha_enabled: bool = True, user: User = Depends(get_current_user)): +async def start_quiz( + quiz_id: str, game_mode: str, captcha_enabled: bool = True, user: User = Depends(get_current_user) +): try: quiz_id = uuid.UUID(quiz_id) except ValueError: @@ -110,6 +112,7 @@ async def start_quiz(quiz_id: str, captcha_enabled: bool = True, user: User = De description=quiz.description, captcha_enabled=captcha_enabled, cover_image=quiz.cover_image, + game_mode=game_mode, ) await redis.set(f"game:{str(game.game_pin)}", (game.json()), ex=18000) return {**quiz.dict(exclude={"id"}), **game.dict(exclude={"questions"})} @@ -117,6 +120,7 @@ async def start_quiz(quiz_id: str, captcha_enabled: bool = True, user: User = De class CheckIfCaptchaEnabledResponse(BaseModel): enabled: bool + game_mode: str | None @router.get("/play/check_captcha/{game_pin}", response_model=CheckIfCaptchaEnabledResponse) @@ -124,10 +128,11 @@ async def check_if_captcha_enabled(game_pin: str): game = await redis.get(f"game:{game_pin}") if game is None: return JSONResponse(status_code=404, content={"detail": "game not found"}) - try: - return CheckIfCaptchaEnabledResponse(**{"enabled": json.loads(game)["captcha_enabled"]}) - except (KeyError, TypeError): - return CheckIfCaptchaEnabledResponse(**{"enabled": True}) + game = PlayGame.parse_raw(game) + if game.captcha_enabled: + return CheckIfCaptchaEnabledResponse(enabled=True, game_mode=game.game_mode) + else: + return CheckIfCaptchaEnabledResponse(enabled=False, game_mode=game.game_mode) @router.get("/join/{game_pin}", deprecated=True) diff --git a/frontend/src/lib/admin.svelte b/frontend/src/lib/admin.svelte index 6910989..e306e6f 100644 --- a/frontend/src/lib/admin.svelte +++ b/frontend/src/lib/admin.svelte @@ -9,9 +9,12 @@ import { get_question_title } from '$lib/admin.ts'; import type { PlayerAnswer } from '$lib/admin.ts'; import { socket } from './socket'; + import { QuizQuestionType } from '$lib/quiz_types'; + import { kahoot_icons } from './play/kahoot_mode_assets/kahoot_icons'; export let game_token: string; export let quiz_data: QuizData; + export let game_mode; const { t } = getLocalization(); @@ -84,11 +87,26 @@
Content for Question
{/if} + {#if game_mode === 'kahoot'} + {#if quiz_data.questions[selected_question].type === QuizQuestionType.ABCD} +
+ {#each quiz_data.questions[selected_question].answers as answer, i} +
+ icon + {answer.answer} +
+ {/each} +
+ {/if} + {/if} {/if}
{#if timer_res === '0'} diff --git a/frontend/src/lib/dashboard/main_slider.svelte b/frontend/src/lib/dashboard/main_slider.svelte index 04bc401..fae683d 100644 --- a/frontend/src/lib/dashboard/main_slider.svelte +++ b/frontend/src/lib/dashboard/main_slider.svelte @@ -11,8 +11,9 @@ import { Pagination, EffectCoverflow, Keyboard, Mousewheel, Navigation } from 'swiper'; import { QuizQuestionType } from '$lib/quiz_types.js'; import { getLocalization } from '../i18n'; - import { start_game } from './start_game'; + import StartGamePopup from './start_game.svelte'; + let start_game = null; const { t } = getLocalization(); export let quizzes; @@ -149,7 +150,7 @@ > - {/each} - + {#if game_mode === 'normal'} +
+ {#each question.answers as answer} + + {/each} +
+ {:else if game_mode === 'kahoot'} +
+ {#each question.answers as answer, i} + + {/each} +
+ {:else} +

Error

+ {/if} {:else if question.type === QuizQuestionType.RANGE} {#await import('svelte-range-slider-pips')} diff --git a/frontend/src/routes/admin/+page.svelte b/frontend/src/routes/admin/+page.svelte index aaf4c99..b2a04ea 100644 --- a/frontend/src/routes/admin/+page.svelte +++ b/frontend/src/routes/admin/+page.svelte @@ -12,6 +12,7 @@ import type { PlayerAnswer, Player } from '$lib/admin.ts'; import SomeAdminScreen from '$lib/admin.svelte'; import { browser } from '$app/environment'; + import { onMount } from 'svelte'; navbarVisible.set(false); @@ -22,6 +23,7 @@ // game_pin: '66190765' // }; export let data; + let game_mode; let { game_pin, auto_connect, game_token } = data; let players: Array = []; @@ -35,15 +37,21 @@ let dataexport_download_a; let warnToLeave = true; - const connect = () => { + const connect = async () => { socket.emit('register_as_admin', { game_pin: game_pin, game_id: game_token }); + const res = await fetch(`/api/v1/quiz/play/check_captcha/${game_pin}`); + const json = await res.json(); + game_mode = json.game_mode; }; - if (auto_connect) { - connect(); - } + onMount(() => { + if (auto_connect) { + connect(); + } + }); + socket.on('registered_as_admin', (data) => { quiz_data = JSON.parse(data['game']); console.log(quiz_data); @@ -152,7 +160,13 @@ {/if} {:else} - + {/if} | Array> = [null]; interface PlayerAnswer { @@ -118,7 +119,7 @@
{#if !gameMeta.started && gameData === undefined} - + {:else if JSON.stringify(final_results) !== JSON.stringify([null])} {:else if gameData !== undefined && question_index === ''} @@ -130,6 +131,7 @@ {:else if gameMeta.started && gameData !== undefined && question_index !== '' && answer_results === undefined} {#key unique} diff --git a/frontend/src/routes/view/[quiz_id]/+page.svelte b/frontend/src/routes/view/[quiz_id]/+page.svelte index b4bf72b..8de4044 100644 --- a/frontend/src/routes/view/[quiz_id]/+page.svelte +++ b/frontend/src/routes/view/[quiz_id]/+page.svelte @@ -9,7 +9,7 @@ import { createTippy } from 'svelte-tippy'; import ImportedOrNot from '$lib/view_quiz/imported_or_not.svelte'; import { QuizQuestionType } from '$lib/quiz_types.js'; - import { start_game } from '$lib/dashboard/start_game'; + import { start_game } from '../../../lib/dashboard/start_game.svelte'; const tippy = createTippy({ arrow: true,