fixed so that you cant start the game untill you fill all the values anda ll
This commit is contained in:
parent
b2906bd53b
commit
dd140e23d1
2 changed files with 35 additions and 1 deletions
31
src/routes/kahootclone/create/IsAllValuesFilled.js
Normal file
31
src/routes/kahootclone/create/IsAllValuesFilled.js
Normal file
|
@ -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;
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue