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[];