From 8a8a118309e032f3b83688feea9320c7841f3aa6 Mon Sep 17 00:00:00 2001 From: Sean Morley Date: Fri, 12 Apr 2024 00:12:55 +0000 Subject: [PATCH] Add navigation to World Travel page and create server load function for country regions --- src/lib/components/Navbar.svelte | 11 +++++++++-- .../worldtravel/[countrycode]/+page.server.ts | 16 ++++++++++++++++ .../worldtravel/[countrycode]/+page.svelte | 7 +++++++ 3 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 src/routes/worldtravel/[countrycode]/+page.server.ts create mode 100644 src/routes/worldtravel/[countrycode]/+page.svelte diff --git a/src/lib/components/Navbar.svelte b/src/lib/components/Navbar.svelte index 54960ee..e356ac5 100644 --- a/src/lib/components/Navbar.svelte +++ b/src/lib/components/Navbar.svelte @@ -20,9 +20,12 @@ async function toToLogin() { goto("/login"); } - async function toToSignup() { + async function goToSignup() { goto("/signup"); } + async function goToWorldTravel() { + goto("/worldtravel"); + } let count = 0; @@ -67,6 +70,10 @@ + {/if} {#if !user} - + {/if} {#if user} diff --git a/src/routes/worldtravel/[countrycode]/+page.server.ts b/src/routes/worldtravel/[countrycode]/+page.server.ts new file mode 100644 index 0000000..8b8458c --- /dev/null +++ b/src/routes/worldtravel/[countrycode]/+page.server.ts @@ -0,0 +1,16 @@ +// server laod function +import { db } from '$lib/db/db.server.js'; +import { worldTravelCountryRegions } from '$lib/db/schema.js'; +import { eq } from 'drizzle-orm'; + +export async function load({ params }) { + const { countrycode } = params; + let data = await db + .select() + .from(worldTravelCountryRegions) + .where(eq(worldTravelCountryRegions.country_code, countrycode)) + console.log(data) + return { + regions : data, + }; +} \ No newline at end of file diff --git a/src/routes/worldtravel/[countrycode]/+page.svelte b/src/routes/worldtravel/[countrycode]/+page.svelte new file mode 100644 index 0000000..86c8d74 --- /dev/null +++ b/src/routes/worldtravel/[countrycode]/+page.svelte @@ -0,0 +1,7 @@ + + +{#each data.regions as region} +

{region.name}

+{/each}