diff --git a/frontend/src/lib/components/buttons/brown.svelte b/frontend/src/lib/components/buttons/brown.svelte index 5f3aba0..c4c6ce9 100644 --- a/frontend/src/lib/components/buttons/brown.svelte +++ b/frontend/src/lib/components/buttons/brown.svelte @@ -18,7 +18,11 @@ { - data.pages.slice(selected_slide, 1); + console.log(selected_slide); + data.pages.splice(selected_slide, 1); data.pages = data.pages; }; diff --git a/frontend/src/routes/dashboard/+page.svelte b/frontend/src/routes/dashboard/+page.svelte index f431eca..2507a42 100644 --- a/frontend/src/routes/dashboard/+page.svelte +++ b/frontend/src/routes/dashboard/+page.svelte @@ -11,6 +11,8 @@ // import Spinner from "$lib/Spinner.svelte"; import Fuse from 'fuse.js'; import BrownButton from '$lib/components/buttons/brown.svelte'; + import type { PageData } from './$types'; + import { fly } from 'svelte/transition'; // import GrayButton from "$lib/components/buttons/gray.svelte"; @@ -25,60 +27,73 @@ questions: Question[]; } + export let data: PageData; let search_term = ''; let start_game = null; signedIn.set(true); navbarVisible.set(true); const { t } = getLocalization(); - let quizzes_to_show = []; - let quizzes: Array; + let items_to_show = []; + let all_items: Array; let fuse; - /* const minisearch = new MiniSearch({ - fields: ['title', 'description'], - idField: 'id', - storeFields: ['id'] - })*/ let id_to_position_map = {}; const getData = async (): Promise> => { - const res = await fetch('/api/v1/quiz/list?page_size=100'); - quizzes_to_show = await res.json(); - fuse = new Fuse(quizzes_to_show, { - keys: ['title', 'description', 'questions.question'], + items_to_show = []; + for (let i = 0; i < data.quizzes.length; i++) { + items_to_show.push({ ...data.quizzes[i], type: 'quiz' }); + } + for (let i = 0; i < data.quiztivities.length; i++) { + items_to_show.push({ ...data.quiztivities[i], type: 'quiztivity' }); + } + fuse = new Fuse(items_to_show, { + keys: ['title', 'description', 'questions.title'], findAllMatches: true }); - quizzes = quizzes_to_show; - for (let i = 0; i < quizzes.length; i++) { - id_to_position_map[quizzes[i].id] = i; + all_items = items_to_show; + for (let i = 0; i < all_items.length; i++) { + id_to_position_map[all_items[i].id] = i; } - return quizzes_to_show; + return all_items; }; - let suggestions = []; - const search = () => { if (search_term === '') { - quizzes_to_show = []; - quizzes_to_show = quizzes; - quizzes_to_show = quizzes_to_show; + items_to_show = all_items; } else { const res = fuse.search(search_term); console.log(res, 'search_res'); - quizzes_to_show = []; + items_to_show = []; for (const quiz_data of res) { - quizzes_to_show.push(quiz_data.item); + items_to_show.push(quiz_data.item); } - quizzes_to_show = quizzes_to_show; + items_to_show = items_to_show; } }; $: { search_term; - // console.log(search_term); search(); } + + const deleteQuiz = async (to_delete: string, type: 'quiz' | 'quiztivity') => { + if (!confirm('Do you really want to delete this quiz?')) { + return; + } + if (type === 'quiz') { + await fetch(`/api/v1/quiz/delete/${to_delete}`, { + method: 'DELETE' + }); + } else { + await fetch(`/api/v1/quiztivity/${to_delete}`, { + method: 'DELETE' + }); + } + window.location.reload(); + }; + let create_button_clicked = false; @@ -104,7 +119,19 @@ Primary -->
- {$t('words.create')} + {#if create_button_clicked} +
+ {$t('words.quiz')} + {$t('words.quiztivity')} +
+ {:else} + { + create_button_clicked = true; + }}>{$t('words.create')} + {/if} {$t('words.import')} {$t('words.results')} @@ -123,8 +150,7 @@
- {#each quizzes_to_show as quiz} + {#each items_to_show as quiz}
@@ -160,28 +186,38 @@ /> {/if}
-
+

{@html quiz.title}

- {@html quiz.description} + {@html quiz.description ?? ''}

- {$t('words.edit')} + {#if quiz.type === 'quiz'} + { + start_game = quiz.id; + }} + > + {$t('words.start')} + + {:else} + + {$t('words.play')} + + {/if} + { - start_game = quiz.id; - }} - > - {$t('words.start')} - - { - // deleteQuiz(quiz.id); + deleteQuiz(quiz.id, quiz.type); }} flex={true} > @@ -201,7 +237,10 @@ /> - { + const quiz_res = await fetch('/api/v1/quiz/list?page_size=100'); + const quizzes = await quiz_res.json(); + const quiztivity_res = await fetch('/api/v1/quiztivity/'); + const quiztivities = await quiztivity_res.json(); + return { + quizzes, + quiztivities + }; +}) satisfies PageLoad; diff --git a/frontend/src/routes/quiztivity/create/+page.svelte b/frontend/src/routes/quiztivity/create/+page.svelte index b7a3c42..3d2c477 100644 --- a/frontend/src/routes/quiztivity/create/+page.svelte +++ b/frontend/src/routes/quiztivity/create/+page.svelte @@ -6,6 +6,7 @@