From 24ddd39f35f8fb918babde5af84587ef3a578134 Mon Sep 17 00:00:00 2001 From: AlexBocken Date: Sun, 2 Jul 2023 23:39:31 +0200 Subject: [PATCH] API routes now return proper Responses and basic errors are handled slight improvements in layouting --- .../components/Header.svelte} | 30 +-- src/routes/+page.svelte | 14 +- src/routes/api/add/+server.ts | 21 +- src/routes/api/delete/+server.ts | 11 +- src/routes/api/edit/+server.ts | 7 +- src/routes/api/img/add/+server.ts | 7 +- src/routes/api/img/add/+server.ts_ | 20 -- src/routes/rezepte/+layout.svelte | 15 ++ src/routes/rezepte/[name]/+page.svelte | 22 +- src/routes/rezepte/add/+page.svelte | 12 +- src/routes/rezepte/edit/[name]/+page.svelte | 19 +- src/routes/test/+page.svelte_ | 249 ++++++++++++++++++ 12 files changed, 349 insertions(+), 78 deletions(-) rename src/{routes/+layout.svelte => lib/components/Header.svelte} (88%) delete mode 100644 src/routes/api/img/add/+server.ts_ create mode 100644 src/routes/rezepte/+layout.svelte create mode 100644 src/routes/test/+page.svelte_ diff --git a/src/routes/+layout.svelte b/src/lib/components/Header.svelte similarity index 88% rename from src/routes/+layout.svelte rename to src/lib/components/Header.svelte index b10e458..5d932f3 100644 --- a/src/routes/+layout.svelte +++ b/src/lib/components/Header.svelte @@ -5,6 +5,7 @@ function show_sidebar(){ const nav_el = document.querySelector("nav") nav_el.hidden = !nav_el.hidden } + - - -
{data.icon}

{data.name}

+ {#if data.description && ! data.preamble} +

{data.description}

+ {/if} {#if data.preamble}

{data.preamble}

{/if} diff --git a/src/routes/rezepte/add/+page.svelte b/src/routes/rezepte/add/+page.svelte index ea6dfc8..1d3394f 100644 --- a/src/routes/rezepte/add/+page.svelte +++ b/src/routes/rezepte/add/+page.svelte @@ -126,7 +126,17 @@ bearer: password, } }) - }) + }); + if(res.status === 200){ + const url = location.href.split('/') + url.splice(url.length -1, 1); + url.push(short_name) + location.assign(url.join('/')) + } + else{ + const item = await res.json(); + alert(item.message) + } } diff --git a/src/routes/rezepte/edit/[name]/+page.svelte b/src/routes/rezepte/edit/[name]/+page.svelte index 01744a1..839186d 100644 --- a/src/routes/rezepte/edit/[name]/+page.svelte +++ b/src/routes/rezepte/edit/[name]/+page.svelte @@ -98,6 +98,15 @@ }) }) + if(res.status === 200){ + const url = location.href.split('/') + url.splice(url.length -2, 2); + location.assign(url.join('/')) + } + else{ + const item = await res.json(); + alert(item.message) + } } async function doEdit() { const res = await fetch('/api/edit', { @@ -124,7 +133,15 @@ } }) }) - const item = await res.json(); + if(res.status === 200){ + const url = location.href.split('/'); + url.splice(url.length -2, 1); + location.assign(url.join('/')) + } + else{ + const item = await res.json() + alert(item.message) + } } diff --git a/src/routes/test/+page.svelte_ b/src/routes/test/+page.svelte_ new file mode 100644 index 0000000..e8d5be9 --- /dev/null +++ b/src/routes/test/+page.svelte_ @@ -0,0 +1,249 @@ +
+ + + +
+ + + + +

Rezept erstellen

+
+ + +

Kurzname (für URL):

+ + +
+
+

Eine etwas längere Beschreibung:

+

+
+

Saison:

+ +
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+

Nachtrag:

+
+
+ +
+

Neues Rezept hinzufügen:

+ + + +