diff --git a/src/routes/flashcards/+page.svelte b/src/routes/flashcards/+page.svelte index 4fd1731..409e5d6 100644 --- a/src/routes/flashcards/+page.svelte +++ b/src/routes/flashcards/+page.svelte @@ -3,38 +3,25 @@ import Card from "./card.svelte"; import StatsAndButtons from "./StatsAndButtons.svelte"; - import { stats, SelectNewDeck, SetNewDeck, StorageDeck } from "./logic.svelte.js"; + import { stats, resetDeck,SetNewDeck } from "./logic.svelte.js"; import { onMount } from "svelte"; import tempelateDeck from "./tempelateDeck.json"; onMount(() => { - SetNewDeck(JSON.parse(localStorage.getItem("deck")) || tempelateDeck, true); + SetNewDeck(JSON.parse(localStorage.getItem("deck")) || tempelateDeck); });
{#if stats.isDeckEmpty}
-

Choose a Deck To learn from!

-
- -
+

Hey, You learned everything!

+
{:else} -
+
-
+
diff --git a/src/routes/flashcards/editCards.svelte b/src/routes/flashcards/editCards.svelte index 5badab3..9830e5e 100644 --- a/src/routes/flashcards/editCards.svelte +++ b/src/routes/flashcards/editCards.svelte @@ -1,72 +1,24 @@
-
- - -
- -
- - -
-
Question Answer - +
- - {#each deck[CurrentlyEditingDeckId].cards as card, i} + {#each LocalDeck as card, i}
@@ -74,36 +26,20 @@ aria-label="delete" onclick={() => { if (confirm("Are you sure you want to delete this card?")) { - deck[CurrentlyEditingDeckId].cards.splice(i, 1); + LocalDeck.splice(i, 1); + toast.success("Card deleted successfully! To make it apply, please save the deck."); } }} - class="btn dull" + class="btn dull"> - -
{/each}
-
diff --git a/src/routes/flashcards/logic.svelte.js b/src/routes/flashcards/logic.svelte.js index 3fbb82f..c2ba1a4 100644 --- a/src/routes/flashcards/logic.svelte.js +++ b/src/routes/flashcards/logic.svelte.js @@ -1,3 +1,4 @@ + export let card = $state({ Q: "", a: "" }); export let statusOfCard = $state({ @@ -8,41 +9,37 @@ export let statusOfCard = $state({ entering: false, }); -export let StorageDeck = $state({ v: [] }); +export let deck = [ + { Q: "Best programer in the world?", a: "RezHackXYZ" }, + { Q: "Best coding community?", a: "HackClub" }, + { Q: "Will @Shub go totally bankrupt?", a: "yes!" }, +]; -export let deck = $state({ v: [] }); - -export function SetNewDeck(newDeck, ThisIsOfPageLoad = true) { - StorageDeck.v = newDeck; - resetDeck(); - stats.isDeckEmpty = ThisIsOfPageLoad; -} - -export function SelectNewDeck(deckNumber) { - deck.v = StorageDeck.v[deckNumber].cards; +export function SetNewDeck (newDeck) { + deck = newDeck; resetDeck(); } export let stats = $state({ - isDeckEmpty: true, + isDeckEmpty: false, AnswerKnown: 0, AnswerNotKnown: 0, - AnswerNotChecked: deck.v.length, + AnswerNotChecked: deck.length, }); let CurrentDeck = { AnswersKnown: [], AnswersNotKnown: [], - AnswersNotChecked: $state.snapshot(deck).v, + AnswersNotChecked: $state.snapshot(deck), }; export function resetDeck() { CurrentDeck.AnswersKnown = []; CurrentDeck.AnswersNotKnown = []; - CurrentDeck.AnswersNotChecked = $state.snapshot(deck).v; + CurrentDeck.AnswersNotChecked = $state.snapshot(deck); stats.AnswerKnown = 0; stats.AnswerNotKnown = 0; - stats.AnswerNotChecked = deck.v.length; + stats.AnswerNotChecked = deck.length; stats.isDeckEmpty = false; SetNewCard(); } diff --git a/src/routes/flashcards/tempelateDeck.json b/src/routes/flashcards/tempelateDeck.json index 55cf87d..cb40c1f 100644 --- a/src/routes/flashcards/tempelateDeck.json +++ b/src/routes/flashcards/tempelateDeck.json @@ -1,26 +1,5 @@ [ - { - "deckName": "Tech", - "cards": [ - { "Q": "What is Svelte?", "a": "Best web dev Framework ever." }, - { "Q": "What is a component?", "a": "A reusable piece of UI in Svelte." }, - { "Q": "How do you create a reactive variable?", "a": "$: variableName = value;" } - ] - }, - { - "deckName": "Math Basics", - "cards": [ - { "Q": "What is 2 + 2?", "a": "4" }, - { "Q": "What is the square root of 16?", "a": "4" }, - { "Q": "What is 5 * 6?", "a": "30" } - ] - }, - { - "deckName": "Geography", - "cards": [ - { "Q": "What is the capital of France?", "a": "Paris" }, - { "Q": "Which continent is Egypt in?", "a": "Africa" }, - { "Q": "What is the largest ocean?", "a": "Pacific Ocean" } - ] - } + { "Q": "Best programer in the world?", "a": "RezHackXYZ" }, + { "Q": "Best coding community?", "a": "HackClub" }, + { "Q": "Will @Shub go totally bankrupt?", "a": "yes!" } ] diff --git a/src/routes/kahootclone/create/Buttons.svelte b/src/routes/kahootclone/create/Buttons.svelte index 4ec60c3..2e944b2 100644 --- a/src/routes/kahootclone/create/Buttons.svelte +++ b/src/routes/kahootclone/create/Buttons.svelte @@ -6,7 +6,6 @@ import { createGame } from "./createGame.js"; let userInput = ""; - let numberOfQuestions; let AIPrompt = ` You are the AI of a quiz game. @@ -14,18 +13,19 @@ Generate a list of quiz questions with possible answers and the correct answer i Each question must have: - A "questionText" (what the question is about) - A "timeLimit" (in seconds, any of these: null (no time limit), 5, 10, 15, 30, 60, 120, 300) +- An "type" (only set to "SingleAnswer" for now) - An "options" (an array of options with at least 2 and at most 8 options) - A "CorrectOption" (an object with a key "SingleAnswer" and a value that is the index of the correct answer) +- A "hasMedia" (boolean indicating if the question has media) only set to true if you are sure the URL is valid and related to the question. +- A "mediaURL" (a URL to the media, can be null if no media is present) only add this if you are sure the URL is valid and related to the question. Ensure the questions are diverse. Example format: -[{"questionText":"What should you do when you're free?","timeLimit":15,"options":["Do something in real life!","Play video games","Code!","Touch grass!"],"CorrectOption":2},{"questionText":"Is RezHackXYZ the best programmer in the world?","timeLimit":5,"options":["Yes :)","No :("],"CorrectOption":0},{"questionText":"Best place in the world?","timeLimit":5,"options":["Google","Microsoft","Apple","Samsung","Hack Club!! :D","Amazon","Facebook","Twitter"],"CorrectOption":4}] +[{"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":{"SingleAnswer":2},"hasMedia":false,"mediaURL":null},{"questionText":"Is RezHackXYZ the best programmer in the world?","timeLimit":5,"type":"SingleAnswer","options":["Yes :)","No :("],"CorrectOption":{"SingleAnswer":0},"hasMedia":true,"mediaURL":"https://github.com/RezHackXYZ.png"},{"questionText":"Best place in the world?","timeLimit":5,"type":"SingleAnswer","options":["Google","Microsoft","Apple","Samsung","Hack Club!! :D","Amazon","Facebook","Twitter"],"CorrectOption":{"SingleAnswer":4},"hasMedia":false,"mediaURL":null}] JUST PROVIDE THE JSON AND NOTHING ELSE. The user's topic of interest is: [topic] - -The User wants [number of questions] questions. `; async function ApiCall() { @@ -38,7 +38,7 @@ The User wants [number of questions] questions. messages: [ { role: "user", - content: AIPrompt.replace("[topic]", userInput).replace("[number of questions]", numberOfQuestions), + content: AIPrompt.replace("[topic]", userInput), }, ], }), @@ -46,17 +46,7 @@ The User wants [number of questions] questions. const data = await response.json(); try { - QuestionsData.v = JSON.parse(data.choices[0].message.content).map((q) => ({ - questionText: q.questionText, - timeLimit: q.timeLimit, - type: "SingleAnswer", - options: q.options, - CorrectOption: {SingleAnswer: q.CorrectOption}, - hasMedia: false, - mediaURL: null, - })); - - + QuestionsData.v = JSON.parse(data.choices[0].message.content); } catch (error) { if (ParsingTry <= 5) { ParsingTry++; @@ -70,7 +60,7 @@ The User wants [number of questions] questions. async function GenerateQuestionsUsingAI() { ParsingTry = 0; userInput = prompt( - "Enter the topic you want with any instructions for the ai, note: doing this will delete all you previous questions and its not undo able", + "Enter the topic and number of questions you want with any instructions for the ai, note: doing this will delete all you previous questions and its not undo able", ); if (!userInput) { @@ -78,13 +68,6 @@ The User wants [number of questions] questions. return; } - numberOfQuestions = prompt("How many questions? (e.g. 5, not 'five')", "5"); - - if (isNaN(parseInt(numberOfQuestions)) || numberOfQuestions <= 0) { - toast.error("Please enter a valid number of questions."); - return; - } - await toast.promise( (async () => { try { diff --git a/src/routes/nav.svelte b/src/routes/nav.svelte index f9c8bd3..ca99afc 100644 --- a/src/routes/nav.svelte +++ b/src/routes/nav.svelte @@ -60,7 +60,7 @@ import { colseModal, ShowSeconds } from "./IdleScreen/logic/TimeAndTableData.svelte.js"; import EditTimetableDiv from "./IdleScreen/components/timetable/EditTimetable.svelte"; import { TabOpen } from "./randomname/+page.svelte"; - import { resetDeck, stats } from "./flashcards/logic.svelte"; + import { resetDeck } from "./flashcards/logic.svelte"; import EditCards from "./flashcards/editCards.svelte"; @@ -123,7 +123,7 @@ - + {/if}