routing for floors
This commit is contained in:
parent
645990bb86
commit
52539d891e
4 changed files with 14 additions and 8 deletions
|
@ -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>
|
||||
|
|
5
src/routes/(app)/[slug]/+page.svelte
Normal file
5
src/routes/(app)/[slug]/+page.svelte
Normal file
|
@ -0,0 +1,5 @@
|
|||
<script lang="ts">
|
||||
const { data } = $props();
|
||||
</script>
|
||||
|
||||
<h1>Hello Floor {data.slug}</h1>
|
5
src/routes/(app)/[slug]/+page.ts
Normal file
5
src/routes/(app)/[slug]/+page.ts
Normal file
|
@ -0,0 +1,5 @@
|
|||
import { PageLoad } from "./$types";
|
||||
|
||||
export const load: PageLoad = ({ params }) => {
|
||||
return { slug: params.slug };
|
||||
};
|
|
@ -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: "/" });
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue