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) <noreply@anthropic.com>
This commit is contained in:
hsiegeln
2026-04-22 14:33:42 +02:00
parent b31223add5
commit a5321d620a

View File

@@ -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<SearchHit[]>([]);
let allSort = $state<AllSort>('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[];