you can now UPLAD IMAGES AND VIDS!!! in the quetions of kahootlone/quizzlet
This commit is contained in:
parent
5f53e923d0
commit
de7e3da139
29 changed files with 158 additions and 96 deletions
|
@ -53,6 +53,13 @@
|
|||
{/each}
|
||||
</div>
|
||||
<GenerateOptionsUsingAI {index} />
|
||||
<input type="file" onchange={() => UpLoadFiles(files[0])} bind:files accept="image/*,video/*" />
|
||||
<input
|
||||
type="file"
|
||||
onchange={async () => {
|
||||
questions.v[index].media = await UpLoadFiles(files[0]);
|
||||
}}
|
||||
bind:files
|
||||
accept="image/*,video/*"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
|
||||
import { DefaultQuestions } from "$lib/config.js";
|
||||
import toast from "svelte-5-french-toast";
|
||||
|
||||
export let Wait = $state({ v: false });
|
||||
export let questions = $state({
|
||||
|
@ -29,6 +31,6 @@ export function DeleteQuestion(index) {
|
|||
questions.v.splice(index, 1);
|
||||
}
|
||||
} else {
|
||||
alert("You need at least one question.");
|
||||
toast.error("You need at least one question.");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { questions } from "./GameCreateData.svelte.js";
|
||||
import { AiPrompts } from "$lib/config.js";
|
||||
import toast from "svelte-5-french-toast";
|
||||
|
||||
export function GenerateOptionsUsingAI(index) {
|
||||
fetch("https://ai.hackclub.com/chat/completions", {
|
||||
|
@ -26,9 +27,9 @@ export function GenerateOptionsUsingAI(index) {
|
|||
questions.v[index].name = question;
|
||||
})
|
||||
.catch((error) => {
|
||||
alert("Error:" + error);
|
||||
toast.error("Error:" + error);
|
||||
return;
|
||||
});
|
||||
|
||||
alert("added!");
|
||||
toast.success("added!");
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { questions } from "./GameCreateData.svelte.js";
|
||||
import { AiPrompts } from "$lib/config.js";
|
||||
import toast from "svelte-5-french-toast";
|
||||
|
||||
export function GenerateQuestionsUsingAI() {
|
||||
let topic = window.prompt(
|
||||
|
@ -30,9 +31,9 @@ export function GenerateQuestionsUsingAI() {
|
|||
questions.v = JSON.parse(data.choices[0].message.content);
|
||||
})
|
||||
.catch((error) => {
|
||||
alert("Error:" + error);
|
||||
toast.error("Error:" + error);
|
||||
return;
|
||||
});
|
||||
|
||||
alert("added!");
|
||||
toast.success("added!");
|
||||
}
|
|
@ -1,4 +1,6 @@
|
|||
import { supabase } from "$lib/supabase";
|
||||
import toast from "svelte-5-french-toast";
|
||||
|
||||
|
||||
export async function createGame(questions, gamePin) {
|
||||
const { data: gameData, error: gameError } = await supabase.from("games").insert({
|
||||
|
@ -9,7 +11,7 @@ export async function createGame(questions, gamePin) {
|
|||
});
|
||||
|
||||
if (gameError) {
|
||||
alert("Failed to create game: " + gameError.message + "\n\nPlease try again.");
|
||||
toast.error("Failed to create game: " + gameError.message + "\n\nPlease try again.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -18,6 +20,7 @@ export async function createGame(questions, gamePin) {
|
|||
gameid: gamePin,
|
||||
questionstext: q.name,
|
||||
correctanswer: q.correctAnswer,
|
||||
media: q.media || null,
|
||||
}));
|
||||
|
||||
const { data: questionsResult, error: questionsError } = await supabase
|
||||
|
@ -26,7 +29,7 @@ export async function createGame(questions, gamePin) {
|
|||
.select("id");
|
||||
|
||||
if (questionsError) {
|
||||
alert("Failed to insert questions: " + questionsError.message + "\n\nPlease try again.");
|
||||
toast.error("Failed to insert questions: " + questionsError.message + "\n\nPlease try again.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -43,9 +46,9 @@ export async function createGame(questions, gamePin) {
|
|||
const { error: answersError } = await supabase.from("answers").insert(answersData);
|
||||
|
||||
if (answersError) {
|
||||
alert("Failed to insert answers: " + answersError.message + "\n\nPlease try again.");
|
||||
toast.error("Failed to insert answers: " + answersError.message + "\n\nPlease try again.");
|
||||
return;
|
||||
}
|
||||
|
||||
window.location.href = `/host?gamepin=${gamePin}` ;
|
||||
window.location.href = `/kahootclone/host?gamepin=${gamePin}`;
|
||||
}
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
import { createGame } from "./InsertGameInDB.js";
|
||||
import { questions,Wait } from "./GameCreateData.svelte.js";
|
||||
import toast from "svelte-5-french-toast";
|
||||
|
||||
export async function startGame() {
|
||||
if (questions.v.some((q) => q.name === "")) return alert("Please fill all questions");
|
||||
if (questions.v.some((q) => q.answers.some((a) => a === ""))) return alert("Fill all options");
|
||||
if (questions.v.some((q) => q.name === "")) return toast.error("Please fill all questions");
|
||||
if (questions.v.some((q) => q.answers.some((a) => a === ""))) return toast.error("Fill all options");
|
||||
if (questions.v.some((q) => q.correctAnswer === undefined))
|
||||
return alert("Select correct answers");
|
||||
return toast.error("Select correct answers");
|
||||
|
||||
const gamePin = Math.floor(Math.random() * 1000000)
|
||||
.toString()
|
||||
|
|
|
@ -27,5 +27,5 @@ export async function UpLoadFiles(file) {
|
|||
// Retrieve public URL
|
||||
const { data: publicData } = supabase.storage.from("useruploadedcontent").getPublicUrl(filePath);
|
||||
|
||||
toast.success(publicData.publicUrl);
|
||||
return publicData.publicUrl;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue