From 2afe6a7cf1a5b0e880180d9efe3fae397df100ad Mon Sep 17 00:00:00 2001 From: Sean Morley Date: Thu, 11 Jul 2024 09:33:52 -0400 Subject: [PATCH 1/3] more filtering options --- frontend/src/lib/components/NotFound.svelte | 20 ++++++ .../src/routes/adventures/+page.server.ts | 45 +++++++++++- frontend/src/routes/adventures/+page.svelte | 70 +++++++++++++++++++ frontend/src/routes/visited/+page.svelte | 21 +----- 4 files changed, 136 insertions(+), 20 deletions(-) create mode 100644 frontend/src/lib/components/NotFound.svelte create mode 100644 frontend/src/routes/adventures/+page.svelte diff --git a/frontend/src/lib/components/NotFound.svelte b/frontend/src/lib/components/NotFound.svelte new file mode 100644 index 00000000..e05ade2a --- /dev/null +++ b/frontend/src/lib/components/NotFound.svelte @@ -0,0 +1,20 @@ + + +
+
+
+ Lost +
+

+ No adventures found +

+

+ There are no adventures to display. Add some using the plus button at the bottom right or try + changing filters! +

+
+
diff --git a/frontend/src/routes/adventures/+page.server.ts b/frontend/src/routes/adventures/+page.server.ts index ddd39356..572e0119 100644 --- a/frontend/src/routes/adventures/+page.server.ts +++ b/frontend/src/routes/adventures/+page.server.ts @@ -3,14 +3,35 @@ import type { PageServerLoad } from './$types'; const PUBLIC_SERVER_URL = process.env['PUBLIC_SERVER_URL']; import type { Adventure } from '$lib/types'; -const endpoint = PUBLIC_SERVER_URL || 'http://localhost:8000'; - import type { Actions } from '@sveltejs/kit'; import { fetchCSRFToken, tryRefreshToken } from '$lib/index.server'; import { checkLink } from '$lib'; const serverEndpoint = PUBLIC_SERVER_URL || 'http://localhost:8000'; +export const load = (async (event) => { + if (!event.locals.user) { + return redirect(302, '/login'); + } else { + let visitedFetch = await fetch(`${serverEndpoint}/api/adventures/`, { + headers: { + Cookie: `${event.cookies.get('auth')}` + } + }); + if (!visitedFetch.ok) { + console.error('Failed to fetch visited adventures'); + return redirect(302, '/login'); + } else { + let visited = (await visitedFetch.json()) as Adventure[]; + return { + props: { + visited + } + }; + } + } +}) satisfies PageServerLoad; + export const actions: Actions = { create: async (event) => { const formData = await event.request.formData(); @@ -316,5 +337,25 @@ export const actions: Actions = { let image_url = adventure.image; let link_url = adventure.link; return { image_url, link_url }; + }, + get: async (event) => { + const adventureId = event.params.adventureId; + + const res = await fetch(`${serverEndpoint}/api/adventures/${adventureId}/`, { + headers: { + Cookie: `${event.cookies.get('auth')}` + } + }); + + if (!res.ok) { + return { + status: res.status, + body: { error: 'Failed to fetch adventure' } + }; + } + + let adventure = await res.json(); + + return { adventure }; } }; diff --git a/frontend/src/routes/adventures/+page.svelte b/frontend/src/routes/adventures/+page.svelte new file mode 100644 index 00000000..ffcac5ce --- /dev/null +++ b/frontend/src/routes/adventures/+page.svelte @@ -0,0 +1,70 @@ + + +
+ +
+ +

My Adventures

+ {#if adventures.length === 0} + + {/if} +
+ +
+ {#each adventures as adventure} + + {/each} +
+
+
+
+ + +
+
diff --git a/frontend/src/routes/visited/+page.svelte b/frontend/src/routes/visited/+page.svelte index 3e64a7bc..3a8a8dec 100644 --- a/frontend/src/routes/visited/+page.svelte +++ b/frontend/src/routes/visited/+page.svelte @@ -7,6 +7,7 @@ import EditAdventure from '$lib/components/EditAdventure.svelte'; import Lost from '$lib/assets/undraw_lost.svg'; + import NotFound from '$lib/components/NotFound.svelte'; export let data: PageData; console.log(data); @@ -84,6 +85,8 @@ {#if adventures.length > 0}

Visited Adventures

+{:else} + {/if}
@@ -91,21 +94,3 @@ {/each}
- -{#if adventures.length === 0} -
-
-
- Lost -
-

- No visited adventures found -

-

- There are no adventures to display. Add some using the plus button at the bottom right! -

-
-
-{/if} From f220911d7afb778a3c668494ba335305cd70c237 Mon Sep 17 00:00:00 2001 From: Sean Morley Date: Thu, 11 Jul 2024 15:37:04 -0400 Subject: [PATCH 2/3] new adventure list --- frontend/src/lib/components/Navbar.svelte | 10 +- .../src/routes/adventures/+page.server.ts | 91 +++++++-- frontend/src/routes/adventures/+page.svelte | 191 +++++++++++++++--- 3 files changed, 242 insertions(+), 50 deletions(-) diff --git a/frontend/src/lib/components/Navbar.svelte b/frontend/src/lib/components/Navbar.svelte index 614ad355..42e36aef 100644 --- a/frontend/src/lib/components/Navbar.svelte +++ b/frontend/src/lib/components/Navbar.svelte @@ -53,10 +53,7 @@ > {#if data.user}
  • - -
  • -
  • - +
  • @@ -87,10 +84,7 @@ From 23af6b22034ee3aa29a231d5e55270fbe17c4760 Mon Sep 17 00:00:00 2001 From: Sean Morley Date: Thu, 11 Jul 2024 15:38:06 -0400 Subject: [PATCH 3/3] better labeling --- frontend/src/routes/adventures/+page.svelte | 2 ++ 1 file changed, 2 insertions(+) diff --git a/frontend/src/routes/adventures/+page.svelte b/frontend/src/routes/adventures/+page.svelte index b719c96d..5902e100 100644 --- a/frontend/src/routes/adventures/+page.svelte +++ b/frontend/src/routes/adventures/+page.svelte @@ -193,6 +193,7 @@

    Sort

    + sort({ attribute: 'name', order: 'asc' })} /> +