diff --git a/src/routes/kahootclone/create/IsAllValuesFilled.js b/src/routes/kahootclone/create/IsAllValuesFilled.js new file mode 100644 index 0000000..5701d71 --- /dev/null +++ b/src/routes/kahootclone/create/IsAllValuesFilled.js @@ -0,0 +1,31 @@ +import toast from "svelte-5-french-toast"; +import { QuestionsData } from "./create.svelte.js"; + +export function IsAllValuesFilled() { + if (QuestionsData.v.length === 0) { + return false; + } + + for (let i = 0; i < QuestionsData.v.length; i++) { + const question = QuestionsData.v[i]; + + if (!question.questionText || question.questionText.trim() === "") { + toast.error(`Please fill in the question text for question ${i + 1}.`); + return false; + } + + for (let j = 0; j < question.options.length; j++) { + if (!question.options[j] || question.options[j].trim() === "") { + toast.error(`Please fill in all answers for question ${i + 1}.`); + return false; + } + } + + if (question.CorrectOption.SingleAnswer === null) { + toast.error(`Please select in the correct answer text for question ${i + 1}.`); + return false; + } + } + + return true; +} diff --git a/src/routes/kahootclone/create/createGame.js b/src/routes/kahootclone/create/createGame.js index f67a962..4707711 100644 --- a/src/routes/kahootclone/create/createGame.js +++ b/src/routes/kahootclone/create/createGame.js @@ -1,10 +1,13 @@ import { supabase } from "$lib/supabase.js"; import { QuestionsData, wait } from "./create.svelte.js"; +import { IsAllValuesFilled } from "./IsAllValuesFilled.js"; import toast from "svelte-5-french-toast"; export async function createGame() { + if (!IsAllValuesFilled()) return; + console.log("Creating game rn!"); - + if (wait.v) { return; }