routing for floors

This commit is contained in:
David Senoner 2025-05-18 23:58:46 +02:00
parent 645990bb86
commit 52539d891e
4 changed files with 14 additions and 8 deletions

View file

@ -36,7 +36,7 @@
<Sidebar.MenuItem>
<Sidebar.MenuButton>
{#snippet child({ props })}
<a href={item.url} {...props}>
<a href="/{item.floor}" {...props}>
<House />
<span>{getFloorName(item.floor)}</span>
</a>

View file

@ -0,0 +1,5 @@
<script lang="ts">
const { data } = $props();
</script>
<h1>Hello Floor {data.slug}</h1>

View file

@ -0,0 +1,5 @@
import { PageLoad } from "./$types";
export const load: PageLoad = ({ params }) => {
return { slug: params.slug };
};

View file

@ -4,9 +4,7 @@ import { fail } from "@sveltejs/kit";
import { eq } from "drizzle-orm";
export const load = async (event) => {
const floors = await db.select().from(table.floors).orderBy(table.floors.floor);
return { floors: floors };
return {};
};
export const actions = {
@ -19,10 +17,8 @@ export const actions = {
const exists = await db
.select({ floor: table.floors.floor })
.from(table.floors)
.where(eq(table.floors.floor, n))
.execute();
console.log(n);
console.log(exists);
.where(eq(table.floors.floor, n));
if (exists.length == 1) return fail(400, { message: "Floor " + n + " already exists!" });
await db.insert(table.floors).values({ floor: n, url: "/" });