Refactor database schema and add planner functionality
This commit is contained in:
21
src/routes/planner/+page.server.ts
Normal file
21
src/routes/planner/+page.server.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { db } from "$lib/db/db.server";
|
||||
import { userPlannedAdventures } from "$lib/db/schema";
|
||||
import { eq } from "drizzle-orm";
|
||||
import type { LayoutServerLoad } from "../$types";
|
||||
import { redirect } from "@sveltejs/kit";
|
||||
|
||||
export const load: LayoutServerLoad = async (event) => {
|
||||
if (event.locals.user) {
|
||||
let plannedAdventures = await db
|
||||
.select()
|
||||
.from(userPlannedAdventures)
|
||||
.where(eq(userPlannedAdventures.userId, event.locals.user.id));
|
||||
return {
|
||||
user: event.locals.user,
|
||||
isServerSetup: event.locals.isServerSetup,
|
||||
plannedAdventures,
|
||||
};
|
||||
} else {
|
||||
return redirect(302, "/login");
|
||||
}
|
||||
};
|
||||
29
src/routes/planner/+page.svelte
Normal file
29
src/routes/planner/+page.svelte
Normal file
@@ -0,0 +1,29 @@
|
||||
<script lang="ts">
|
||||
import { page } from "$app/stores";
|
||||
import type { Adventure } from "$lib/utils/types";
|
||||
import { onMount } from "svelte";
|
||||
import AdventureCard from "$lib/components/AdventureCard.svelte";
|
||||
|
||||
let plannedAdventures: Adventure[] = [];
|
||||
|
||||
onMount(async () => {
|
||||
plannedAdventures = $page.data.plannedAdventures;
|
||||
console.log(plannedAdventures);
|
||||
});
|
||||
</script>
|
||||
|
||||
<h1 class="font-extrabold text-center text-4xl">My Planned Adventures</h1>
|
||||
|
||||
<div
|
||||
class="grid xl:grid-cols-3 lg:grid-cols-3 md:grid-cols-2 sm:grid-cols-1 gap-4 mt-4 content-center auto-cols-auto ml-6 mr-6"
|
||||
>
|
||||
{#each plannedAdventures as adventure (adventure.id)}
|
||||
<AdventureCard
|
||||
type="planner"
|
||||
id={adventure.id}
|
||||
name={adventure.name}
|
||||
location={adventure.location}
|
||||
activityTypes={adventure.activityTypes}
|
||||
/>
|
||||
{/each}
|
||||
</div>
|
||||
Reference in New Issue
Block a user