From a5321d620ab726fe36aacf06405626480ae68e00 Mon Sep 17 00:00:00 2001 From: hsiegeln <37154749+hsiegeln@users.noreply.github.com> Date: Wed, 22 Apr 2026 14:33:42 +0200 Subject: [PATCH] feat(home): profile_id in alle /api/recipes/all-Fetches buildAllUrl-Helper haengt profile_id an wenn ein Profil aktiv ist; nutzt es loadAllMore, setAllSort und rehydrateAll. Voraussetzung fuer sort=viewed (Server braucht profile_id fuer den View-Join). Co-Authored-By: Claude Opus 4.7 (1M context) --- src/routes/+page.svelte | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index f0a7dd9..0d22295 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -34,6 +34,12 @@ { value: 'cooked', label: 'Zuletzt gekocht' }, { value: 'created', label: 'Hinzugefügt' } ]; + function buildAllUrl(sort: AllSort, limit: number, offset: number): string { + const profileId = profileStore.active?.id; + const profilePart = profileId ? `&profile_id=${profileId}` : ''; + return `/api/recipes/all?sort=${sort}&limit=${limit}&offset=${offset}${profilePart}`; + } + let allRecipes = $state([]); let allSort = $state('name'); let allExhausted = $state(false); @@ -79,7 +85,7 @@ async function rehydrateAll(sort: AllSort, count: number, exhausted: boolean) { allLoading = true; try { - const res = await fetch(`/api/recipes/all?sort=${sort}&limit=${count}&offset=0`); + const res = await fetch(buildAllUrl(sort, count, 0)); if (!res.ok) return; const body = await res.json(); const hits = body.hits as SearchHit[]; @@ -100,9 +106,7 @@ if (allLoading || allExhausted) return; allLoading = true; try { - const res = await fetch( - `/api/recipes/all?sort=${allSort}&limit=${ALL_PAGE}&offset=${allRecipes.length}` - ); + const res = await fetch(buildAllUrl(allSort, ALL_PAGE, allRecipes.length)); if (!res.ok) return; const body = await res.json(); const more = body.hits as SearchHit[]; @@ -126,9 +130,7 @@ const chipsBefore = allChips?.getBoundingClientRect().top ?? 0; allLoading = true; try { - const res = await fetch( - `/api/recipes/all?sort=${next}&limit=${ALL_PAGE}&offset=0` - ); + const res = await fetch(buildAllUrl(next, ALL_PAGE, 0)); if (!res.ok) return; const body = await res.json(); const hits = body.hits as SearchHit[];