diff --git a/frontend/src/lib/components/ActivityComplete.svelte b/frontend/src/lib/components/ActivityComplete.svelte index 58a1437..9415fc4 100644 --- a/frontend/src/lib/components/ActivityComplete.svelte +++ b/frontend/src/lib/components/ActivityComplete.svelte @@ -11,16 +11,16 @@ } onMount(async () => { - let res = await fetch('/api/activity-types/types/', { - method: 'GET', + let res = await fetch('/activities', { + method: 'POST', headers: { 'Content-Type': 'application/json' } }); let data = await res.json(); - console.log('ACTIVITIES' + data); - if (data) { - allActivities = data; + console.log('ACTIVITIES' + data.activities); + if (data && data.activities) { + allActivities = data.activities; } }); diff --git a/frontend/src/lib/components/NewAdventure.svelte b/frontend/src/lib/components/NewAdventure.svelte index 851a0c3..a18d80c 100644 --- a/frontend/src/lib/components/NewAdventure.svelte +++ b/frontend/src/lib/components/NewAdventure.svelte @@ -11,7 +11,7 @@ export let longitude: number | null = null; export let latitude: number | null = null; - export let collection_id: number | null = null; + export let collection_id: string | null = null; import MapMarker from '~icons/mdi/map-marker'; import Calendar from '~icons/mdi/calendar'; @@ -29,7 +29,7 @@ export let endDate: string | null = null; let newAdventure: Adventure = { - id: NaN, + id: '', type: type, name: '', location: '', @@ -43,7 +43,7 @@ latitude: null, longitude: null, is_public: false, - collection: collection_id || NaN + collection: collection_id || '' }; if (longitude && latitude) { diff --git a/frontend/src/lib/types.ts b/frontend/src/lib/types.ts index fa951d5..b00cf35 100644 --- a/frontend/src/lib/types.ts +++ b/frontend/src/lib/types.ts @@ -21,7 +21,7 @@ export type Adventure = { link?: string | null; image?: string | null; date?: string | null; // Assuming date is a string in 'YYYY-MM-DD' format - collection?: number | null; + collection?: string | null; latitude: number | null; longitude: number | null; is_public: boolean; diff --git a/frontend/src/routes/activities/+page.server.ts b/frontend/src/routes/activities/+page.server.ts index 106df86..4407eda 100644 --- a/frontend/src/routes/activities/+page.server.ts +++ b/frontend/src/routes/activities/+page.server.ts @@ -1,4 +1,4 @@ -import { redirect } from '@sveltejs/kit'; +import { redirect, type Actions } from '@sveltejs/kit'; import type { PageServerLoad } from './$types'; const PUBLIC_SERVER_URL = process.env['PUBLIC_SERVER_URL']; const endpoint = PUBLIC_SERVER_URL || 'http://localhost:8000'; @@ -24,3 +24,20 @@ export const load = (async (event) => { } }; }) satisfies PageServerLoad; + +export const actions: Actions = { + getActivities: async (event) => { + let allActivities: string[] = []; + let res = await fetch(`${endpoint}/api/activity-types/types/`, { + headers: { + 'Content-Type': 'application/json', + Cookie: `${event.cookies.get('auth')}` + } + }); + let data = await res.json(); + if (data) { + allActivities = data; + } + return { activities: allActivities }; + } +}; diff --git a/frontend/src/routes/activities/+server.ts b/frontend/src/routes/activities/+server.ts new file mode 100644 index 0000000..ebb4252 --- /dev/null +++ b/frontend/src/routes/activities/+server.ts @@ -0,0 +1,19 @@ +import { json } from '@sveltejs/kit'; +import type { RequestHandler } from '../data/$types'; +const PUBLIC_SERVER_URL = process.env['PUBLIC_SERVER_URL']; +const endpoint = PUBLIC_SERVER_URL || 'http://localhost:8000'; + +export const POST: RequestHandler = async (event) => { + let allActivities: string[] = []; + let res = await fetch(`${endpoint}/api/activity-types/types/`, { + headers: { + 'Content-Type': 'application/json', + Cookie: `${event.cookies.get('auth')}` + } + }); + let data = await res.json(); + if (data) { + allActivities = data; + } + return json({ activities: allActivities }); +}; diff --git a/frontend/src/routes/adventures/+page.svelte b/frontend/src/routes/adventures/+page.svelte index 2984dc9..5882cc5 100644 --- a/frontend/src/routes/adventures/+page.svelte +++ b/frontend/src/routes/adventures/+page.svelte @@ -98,7 +98,7 @@ let adventureToEdit: Adventure; let isEditModalOpen: boolean = false; - function deleteAdventure(event: CustomEvent) { + function deleteAdventure(event: CustomEvent) { adventures = adventures.filter((adventure) => adventure.id !== event.detail); } diff --git a/frontend/src/routes/collections/+page.svelte b/frontend/src/routes/collections/+page.svelte index df06848..59427ff 100644 --- a/frontend/src/routes/collections/+page.svelte +++ b/frontend/src/routes/collections/+page.svelte @@ -66,7 +66,7 @@ }; } - function deleteCollection(event: CustomEvent) { + function deleteCollection(event: CustomEvent) { collections = collections.filter((collection) => collection.id !== event.detail); } @@ -85,7 +85,7 @@ let collectionToEdit: Collection; let isEditModalOpen: boolean = false; - function deleteAdventure(event: CustomEvent) { + function deleteAdventure(event: CustomEvent) { collections = collections.filter((adventure) => adventure.id !== event.detail); } @@ -245,7 +245,7 @@ value="name" hidden /> - +