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