From 167080441a34e2c589cf8379aef6dc81c136304f Mon Sep 17 00:00:00 2001 From: Sean Morley Date: Thu, 11 Apr 2024 21:15:34 +0000 Subject: [PATCH] Refactor AdventureCard component and shared page --- src/lib/components/AdventureCard.svelte | 28 +++++++++++++++++++++++++ src/routes/shared/[key]/+page.server.ts | 25 +++++++++++++++++++--- src/routes/shared/[key]/+page.svelte | 27 ++++++++++++++++++++++-- tailwind.config.js | 2 +- 4 files changed, 76 insertions(+), 6 deletions(-) diff --git a/src/lib/components/AdventureCard.svelte b/src/lib/components/AdventureCard.svelte index 01e296a..9146128 100644 --- a/src/lib/components/AdventureCard.svelte +++ b/src/lib/components/AdventureCard.svelte @@ -75,3 +75,31 @@ {/if} + +{#if type === "shared"} +
+
+

{name}

+ {#if location !== ""} +

+ Logo{location} +

+ {/if} + {#if created !== ""} +

+ Logo{created} +

+ {/if} +
+
+{/if} diff --git a/src/routes/shared/[key]/+page.server.ts b/src/routes/shared/[key]/+page.server.ts index ef5dc65..6dbe5c7 100644 --- a/src/routes/shared/[key]/+page.server.ts +++ b/src/routes/shared/[key]/+page.server.ts @@ -5,14 +5,33 @@ import type { Adventure } from "$lib/utils/types"; export async function load({ params }) { let key = params.key; + + // Fetch data from the database let result = await db .select() .from(sharedAdventures) .where(eq(sharedAdventures.id, key)) .execute(); - let adventure = result[0].data as Adventure; - console.log(adventure); + + // Assuming result is an array with a single object + let rawData = result[0]; + + // Parse the data field, which contains a JSON string + let adventures = JSON.parse(rawData.data as string); + + // Map the parsed adventures to the Adventure interface + let adventureArray = adventures.map((item: any) => { + return { + id: item.id, + name: item.name, + location: item.location, + created: item.created, + } as Adventure; + }); + + + // Return the array of Adventure objects return { - result: adventure, + adventureArray, }; } diff --git a/src/routes/shared/[key]/+page.svelte b/src/routes/shared/[key]/+page.svelte index 90e6a62..bb9f20d 100644 --- a/src/routes/shared/[key]/+page.svelte +++ b/src/routes/shared/[key]/+page.svelte @@ -1,7 +1,30 @@ -

{result}

+ + +

Shared Adventure List

+
+ {#each array as adventure (adventure.id)} + + {/each} +
diff --git a/tailwind.config.js b/tailwind.config.js index 389e6e9..2d48b1b 100644 --- a/tailwind.config.js +++ b/tailwind.config.js @@ -6,6 +6,6 @@ export default { }, plugins: [require("@tailwindcss/typography"), require("daisyui")], daisyui: { - themes: ["sunset"], + themes: ["night"], }, };