Done!

This commit is contained in:
Mawoka
2022-10-04 20:04:08 +02:00
parent d52f8cc017
commit 6d0b88b56a
6 changed files with 65 additions and 17 deletions
+6 -3
View File
@@ -14,26 +14,26 @@
let captcha_selected = false;
let selected_game_mode = 'kahoot';
let loading = false;
let custom_field = '';
const start_game = async (id: string) => {
let res;
loading = true;
if (captcha_enabled && captcha_selected) {
res = await fetch(
`/api/v1/quiz/start/${id}?captcha_enabled=True&game_mode=${selected_game_mode}`,
`/api/v1/quiz/start/${id}?captcha_enabled=True&game_mode=${selected_game_mode}&custom_field=${custom_field}`,
{
method: 'POST'
}
);
} else {
res = await fetch(
`/api/v1/quiz/start/${id}?captcha_enabled=False&game_mode=${selected_game_mode}`,
`/api/v1/quiz/start/${id}?captcha_enabled=False&game_mode=${selected_game_mode}&custom_field=${custom_field}`,
{
method: 'POST'
}
);
}
if (res.status !== 200) {
alertModal.set({
open: true,
@@ -111,6 +111,9 @@
</p>
</div>
</div>
<div class="flex justify-center">
<input bind:value={custom_field} />
</div>
<button
class="mt-auto mx-auto bg-green-500 p-4 rounded-lg shadow-lg hover:bg-green-400 transition-all marck-script text-2xl"
+26 -7
View File
@@ -16,6 +16,10 @@
export let game_mode;
export let username;
let custom_field;
let custom_field_value;
let captcha_enabled;
let hcaptchaSitekey = import.meta.env.VITE_HCAPTCHA;
let hcaptcha = {
@@ -48,17 +52,13 @@
}
});
const setUsername = async () => {
if (username.length <= 3) {
return;
}
let captcha_resp: string;
const set_game_pin = async () => {
const res = await fetch(`/api/v1/quiz/play/check_captcha/${game_pin}`);
let captcha_enabled;
const json = await res.json();
game_mode = json.game_mode;
if (res.status === 200) {
captcha_enabled = json.enabled;
custom_field = json.custom_field;
}
if (res.status === 404) {
alertModal.set({
@@ -77,6 +77,17 @@
});
return;
}
};
$: if (game_pin.length >= 7) {
set_game_pin();
}
const setUsername = async () => {
if (username.length <= 3) {
return;
}
let captcha_resp: string;
if (captcha_enabled) {
try {
@@ -103,7 +114,8 @@
socket.emit('join_game', {
username: username,
game_pin: game_pin,
captcha: captcha_resp
captcha: captcha_resp,
custom_field: custom_field ? custom_field_value : undefined
});
};
socket.on('game_not_found', () => {
@@ -151,6 +163,13 @@
bind:value={username}
maxlength="17"
/>
{#if custom_field}
<h1 class="text-lg text-center">{custom_field}</h1>
<input
class="border border-gray-400 self-center text-center text-black ring-0 outline-none p-2 rounded-lg focus:shadow-2xl transition-all"
bind:value={custom_field_value}
/>
{/if}
<button
class="bg-amber-800 hover:bg-amber-700 text-white font-bold py-2 px-4 rounded disabled:cursor-not-allowed disabled:opacity-50 mt-2"
type="submit"