Refactor database schema and add planner functionality

This commit is contained in:
Sean Morley
2024-04-21 22:42:49 +00:00
parent 3072fedccf
commit b2184bdee3
17 changed files with 1593 additions and 14 deletions

View 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");
}
};

View 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>