From 9da2ddc1232abcf7fa66b757f13cb40a9e14eda7 Mon Sep 17 00:00:00 2001 From: RezHackXYZ Date: Mon, 2 Jun 2025 15:51:42 +0530 Subject: [PATCH] it now also adds the awnsers to the db --- src/lib/config.js | 4 +- src/routes/kahootclone/create/+page.svelte | 2 +- src/routes/kahootclone/create/Buttons.svelte | 3 +- src/routes/kahootclone/create/createGame.js | 51 ++++++++++++++++++++ src/routes/tailwind.css | 3 +- 5 files changed, 58 insertions(+), 5 deletions(-) create mode 100644 src/routes/kahootclone/create/createGame.js diff --git a/src/lib/config.js b/src/lib/config.js index 8270aec..c685e6d 100644 --- a/src/lib/config.js +++ b/src/lib/config.js @@ -59,11 +59,11 @@ export let AnswersSymbolAndColorScheme = [ export let DefaultQuestions = [ { - questionText: "What should you do when you're free?", + questionText: "What should you do when you're free?", timeLimit: 15, type: "SingleAnswer", options: ["Do something in real life!", "Play video games", "Code!", "Touch grass!"], - CorrectOption: 2, + CorrectOption: { SingleAnswer: 2 }, hasMedia: false, mediaURL: null, }, diff --git a/src/routes/kahootclone/create/+page.svelte b/src/routes/kahootclone/create/+page.svelte index 50c5b13..be012d0 100644 --- a/src/routes/kahootclone/create/+page.svelte +++ b/src/routes/kahootclone/create/+page.svelte @@ -16,4 +16,4 @@
- + \ No newline at end of file diff --git a/src/routes/kahootclone/create/Buttons.svelte b/src/routes/kahootclone/create/Buttons.svelte index c673c8d..4985f05 100644 --- a/src/routes/kahootclone/create/Buttons.svelte +++ b/src/routes/kahootclone/create/Buttons.svelte @@ -1,6 +1,7 @@
@@ -10,7 +11,7 @@ -
diff --git a/src/routes/kahootclone/create/createGame.js b/src/routes/kahootclone/create/createGame.js new file mode 100644 index 0000000..782eb87 --- /dev/null +++ b/src/routes/kahootclone/create/createGame.js @@ -0,0 +1,51 @@ +import { supabase } from "$lib/supabase.js"; +import { QuestionsData } from "./create.svelte.js"; +import toast from "svelte-5-french-toast"; + +export async function createGame() { + let GamesData; + try { + GamesData = await toast.promise( + (async () => { + let { data, error } = await supabase.from("games").insert([{}]).select("id,gamepin"); + if (error) { + throw new Error(error.message); + } + return data; + })(), + { + loading: "Adding Game...", + success: "Game added!", + error: (err) => `Could not add game.\nError: ${err.message}\n\n Please try again.`, + }, + ); + + await toast.promise( + (async () => { + const { data, error } = await supabase + .from("questions") + .insert( + QuestionsData.v.map((_, index) => ({ + ...QuestionsData.v[index], + gameid: GamesData[0].id, + })), + ) + .select(); + if (error) { + throw new Error(error.message); + } + return data; + })(), + { + loading: "Adding Questions and Answers...", + success: "Questions and Answers added!", + error: (err) => + `Could not add Questions and Answers.\nError: ${err.message}\n\n Please try again.`, + }, + ); + } catch (error) { + return; + } + + toast.success(`Game created! Your game pin is: ${GamesData[0].gamepin}`); +} diff --git a/src/routes/tailwind.css b/src/routes/tailwind.css index 9caf8e9..3192c45 100644 --- a/src/routes/tailwind.css +++ b/src/routes/tailwind.css @@ -1,9 +1,10 @@ @import "https://www.nerdfonts.com/assets/css/webfont.css"; @import url("https://fonts.googleapis.com/css2?family=Comfortaa:wght@300..700&family=JetBrains+Mono:wght@200&family=Sour+Gummy:wght@300&display=swap"); +@import url("https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@300&display=swap"); @import "tailwindcss"; :root { - @apply bg-gray-950 font-[Sour_Gummy] text-white; + @apply bg-gray-950 font-[Space_Grotesk] text-white; } .btn {