add a route

This commit is contained in:
schreifuchs 2025-03-07 15:22:44 +01:00
parent 42e8605945
commit feb248e991
4 changed files with 45 additions and 9 deletions

View File

@ -1,11 +1,15 @@
<script lang="ts"> <script lang="ts">
import "./app.css"; import "./app.css";
import { Router, Route, Link, navigate } from "svelte-routing"; import { Router, Route, Link, navigate } from "svelte-routing";
import Home from "./routes/Home.svelte"; import Things from "./routes/Things.svelte";
import "./app.css"; import "./app.css";
import { Navbar, DarkMode, Heading } from "flowbite-svelte"; import { Navbar, DarkMode } from "flowbite-svelte";
import { HomeOutline } from "flowbite-svelte-icons"; import { HomeOutline } from "flowbite-svelte-icons";
import Thing from "./routes/Thing.svelte";
let url: string = $state("/"); let url: string = $state("/");
$effect(() => {
console.log(url);
});
</script> </script>
<div <div
@ -23,7 +27,10 @@
<DarkMode /> <DarkMode />
</Navbar> </Navbar>
<main class="size-full max-h-full max-w-full overflow-scroll"> <main class="size-full max-h-full max-w-full overflow-scroll">
<Route path="/"><Home /></Route> <Route path="/"><Things /></Route>
<Route path="/things/:id" let:params>
<Thing thingID={parseInt(params.id)} />
</Route>
</main> </main>
</Router> </Router>
</div> </div>

View File

@ -0,0 +1,26 @@
<script lang="ts">
import { GetThings } from "../../wailsjs/go/things/Service";
import { model } from "../../wailsjs/go/models";
import { onMount } from "svelte";
import { Heading } from "flowbite-svelte";
let { thingID }: { thingID: number } = $props();
let thing: model.Thing = $state(new model.Thing());
function update() {
GetThings().then((ts) => {
ts.forEach((t) => {
if (t.ID === thingID) {
thing = t;
}
});
});
}
onMount(update);
</script>
<div class="m-5">
<Heading>
{thing.Name}
</Heading>
</div>

View File

@ -17,6 +17,7 @@
TableBodyRow, TableBodyRow,
TableBodyCell, TableBodyCell,
} from "flowbite-svelte"; } from "flowbite-svelte";
import { navigate } from "svelte-routing";
let name: string = $state(); let name: string = $state();
let thingsList: model.Thing[] = $state([]); let thingsList: model.Thing[] = $state([]);
@ -33,10 +34,6 @@
name = ""; name = "";
} }
function deleteEvent(id: number) {
DeleteThing(id).then(update);
}
onMount(update); onMount(update);
</script> </script>
@ -53,6 +50,7 @@
<TableHead> <TableHead>
<TableHeadCell>ID</TableHeadCell> <TableHeadCell>ID</TableHeadCell>
<TableHeadCell>Name</TableHeadCell> <TableHeadCell>Name</TableHeadCell>
<TableHeadCell>View</TableHeadCell>
<TableHeadCell>Delete</TableHeadCell> <TableHeadCell>Delete</TableHeadCell>
</TableHead> </TableHead>
<TableBody> <TableBody>
@ -65,8 +63,13 @@
<TableBodyCell> <TableBodyCell>
{t.Name} {t.Name}
</TableBodyCell> </TableBodyCell>
<TableBodyCell> <TableBodyCell>
<Button on:click={(_) => deleteEvent(t.ID)}>Delete</Button> <Button onclick={() => navigate(`/things/${t.ID}`)}>View</Button>
</TableBodyCell>
<TableBodyCell>
<Button onclick={() => DeleteThing(t.ID).then(update)}>Delete</Button>
</TableBodyCell> </TableBodyCell>
</TableBodyRow> </TableBodyRow>
{/each} {/each}

View File

@ -4,7 +4,7 @@
CURRENT_DIR_NAME=$(basename "$PWD") CURRENT_DIR_NAME=$(basename "$PWD")
# Define the files to be updated # Define the files to be updated
FILES=("main.go" "go.mod" "wails.json") FILES=("main.go" "go.mod" "wails.json" "things/resource.go")
# String to be replaced # String to be replaced
OLD_STRING="wails-template" OLD_STRING="wails-template"