diff --git a/frontend/src/routes/+layout.svelte b/frontend/src/routes/+layout.svelte index 6b8a0ee..6a40d42 100644 --- a/frontend/src/routes/+layout.svelte +++ b/frontend/src/routes/+layout.svelte @@ -1,4 +1,5 @@ @@ -31,7 +33,7 @@
diff --git a/frontend/src/routes/+page.svelte b/frontend/src/routes/+page.svelte index 7e3f72b..d062fc4 100644 --- a/frontend/src/routes/+page.svelte +++ b/frontend/src/routes/+page.svelte @@ -4,7 +4,6 @@ import { toast } from '$lib/toast'; import type { Technology } from '$lib/types'; import { getContextClient, gql, mutationStore, queryStore } from '@urql/svelte'; - import type { ChangeEventHandler } from 'svelte/elements'; import { writable } from 'svelte/store'; import { superForm } from 'sveltekit-superforms/client'; import type { PageData } from './$types'; @@ -13,8 +12,7 @@ const client = getContextClient(); const ltsTechnologies = writable([]); - const searchedTechnologies = writable([]); - const tbd = writable([]); + const searchedTechnologies = writable<(Technology & { checked: boolean })[]>([]); queryStore({ client: client, @@ -80,7 +78,7 @@ name: form.data.name, link: form.data.link, tags: form.data.tags.split(','), - userId: data.id + userId: data.user?.id } }).subscribe(({ error, data }) => { if (error) { @@ -139,28 +137,15 @@ toast({ message: error.message, type: 'error' }); console.log(error.message); } else if (data) { - searchedTechnologies.set(data.technology); + searchedTechnologies.set( + (data.technology as Technology[]).map((tech) => ({ ...tech, checked: false })) + ); } }); } } }); - const updateTBD = (id: string | 'all'): ChangeEventHandler => { - return (el) => { - if (el.target && (el.target as Record).checked) { - if (id === 'all') tbd.set($searchedTechnologies.map((tech) => tech.id)); - else tbd.update((v) => [...v, id]); - return; - } - - tbd.update((v) => { - const i = v.indexOf(id); - if (i > -1) v.splice(i, 1); - return v; - }); - }; - }; const deleteTBD = () => { mutationStore({ client, @@ -170,14 +155,15 @@ } `, variables: { - ids: $tbd + ids: $searchedTechnologies.filter((tech) => tech.checked).map((tech) => tech.id) } - }).subscribe(({ error }) => { + }).subscribe(({ error, data }) => { if (error) { toast({ message: error.message, type: 'error' }); - } else { + } else if (data) { toast({ message: 'technologies deleted!', type: 'success' }); invalidateAll().catch((error) => toast({ message: error.message, type: 'error' })); + searchedTechnologies.set([]); } }); }; @@ -265,7 +251,7 @@
-

Delete a technology

+

Search a technology

@@ -309,7 +295,15 @@ Name @@ -325,7 +319,7 @@ {tech.name} diff --git a/frontend/src/routes/auth/discord/+server.ts b/frontend/src/routes/auth/discord/+page.server.ts similarity index 72% rename from frontend/src/routes/auth/discord/+server.ts rename to frontend/src/routes/auth/discord/+page.server.ts index 9560c6f..1383b24 100644 --- a/frontend/src/routes/auth/discord/+server.ts +++ b/frontend/src/routes/auth/discord/+page.server.ts @@ -1,8 +1,9 @@ import { env } from '$env/dynamic/private'; import { env as publicEnv } from '$env/dynamic/public'; -import { redirect, type RequestHandler } from '@sveltejs/kit'; +import { redirect } from '@sveltejs/kit'; +import type { PageServerLoad } from './$types'; -export const GET: RequestHandler = async () => { +export const load: PageServerLoad = async () => { const params = new URLSearchParams({ client_id: env.CLIENT_ID, redirect_uri: `${publicEnv.PUBLIC_ORIGIN}/auth/discord/callback`, diff --git a/frontend/src/routes/logout/+server.ts b/frontend/src/routes/logout/+page.server.ts similarity index 62% rename from frontend/src/routes/logout/+server.ts rename to frontend/src/routes/logout/+page.server.ts index faa5b8d..62c75fa 100644 --- a/frontend/src/routes/logout/+server.ts +++ b/frontend/src/routes/logout/+page.server.ts @@ -1,7 +1,7 @@ import { redirect } from '@sveltejs/kit'; -import type { RequestHandler } from './$types'; +import type { PageServerLoad } from './$types'; -export const GET: RequestHandler = async ({ cookies }) => { +export const load: PageServerLoad = async ({ cookies }) => { cookies.set('access-token', '', { maxAge: -1 }); cookies.set('refresh-token', '', { maxAge: -1 });