diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 4fa864c..e5a463f 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -1 +1,59 @@ - + + +
+ Kochwas + +
+ +
+ {@render children()} +
+ + diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index bb390d1..ca7c74d 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -1,8 +1,18 @@ -
+

Kochwas

- +
-

Phase 1: Foundations — Suche folgt in Phase 3.

-
+ + +{#if recent.length > 0} +
+

Zuletzt hinzugefügt

+ +
+{/if} diff --git a/src/routes/recipes/[id]/+page.server.ts b/src/routes/recipes/[id]/+page.server.ts new file mode 100644 index 0000000..9baf2a7 --- /dev/null +++ b/src/routes/recipes/[id]/+page.server.ts @@ -0,0 +1,23 @@ +import type { PageServerLoad } from './$types'; +import { error } from '@sveltejs/kit'; +import { getDb } from '$lib/server/db'; +import { getRecipeById } from '$lib/server/recipes/repository'; +import { + listComments, + listCookingLog, + listRatings +} from '$lib/server/recipes/actions'; + +export const load: PageServerLoad = async ({ params }) => { + const id = Number(params.id); + if (!Number.isInteger(id) || id <= 0) error(400, { message: 'Invalid id' }); + const db = getDb(); + const recipe = getRecipeById(db, id); + if (!recipe) error(404, { message: 'Nicht gefunden' }); + const ratings = listRatings(db, id); + const comments = listComments(db, id); + const cooking_log = listCookingLog(db, id); + const avg_stars = + ratings.length === 0 ? null : ratings.reduce((s, r) => s + r.stars, 0) / ratings.length; + return { recipe, ratings, comments, cooking_log, avg_stars }; +}; diff --git a/src/routes/recipes/[id]/+page.svelte b/src/routes/recipes/[id]/+page.svelte new file mode 100644 index 0000000..60cde78 --- /dev/null +++ b/src/routes/recipes/[id]/+page.svelte @@ -0,0 +1,352 @@ + + + + {#snippet showActions()} +
+
+ Deine Bewertung: + + {#if data.avg_stars !== null} + ⌀ {data.avg_stars.toFixed(1)} ({ratings.length}) + {/if} +
+
+ + + + + +
+
+ {/snippet} +
+ +
+

Kommentare

+ {#if comments.length === 0} +

Noch keine Kommentare.

+ {/if} + +
+ + +
+
+ +{#if cookingLog.length > 0} +
+

Kochjournal

+ +
+{/if} + + diff --git a/src/routes/search/+page.svelte b/src/routes/search/+page.svelte new file mode 100644 index 0000000..6a18db3 --- /dev/null +++ b/src/routes/search/+page.svelte @@ -0,0 +1,175 @@ + + + + +{#if loading} +

Suche läuft …

+{:else if searched && hits.length === 0} +
+

Kein Rezept im Bestand für „{query}".

+

Bald: Internet durchsuchen.

+
+{:else if hits.length > 0} + + {#if canWebSearch} +

Weitersuchen im Internet — Phase 4.

+ {/if} +{/if} + +