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:
@@ -34,6 +34,12 @@
|
|||||||
{ value: 'cooked', label: 'Zuletzt gekocht' },
|
{ value: 'cooked', label: 'Zuletzt gekocht' },
|
||||||
{ value: 'created', label: 'Hinzugefügt' }
|
{ 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 allRecipes = $state<SearchHit[]>([]);
|
||||||
let allSort = $state<AllSort>('name');
|
let allSort = $state<AllSort>('name');
|
||||||
let allExhausted = $state(false);
|
let allExhausted = $state(false);
|
||||||
@@ -79,7 +85,7 @@
|
|||||||
async function rehydrateAll(sort: AllSort, count: number, exhausted: boolean) {
|
async function rehydrateAll(sort: AllSort, count: number, exhausted: boolean) {
|
||||||
allLoading = true;
|
allLoading = true;
|
||||||
try {
|
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;
|
if (!res.ok) return;
|
||||||
const body = await res.json();
|
const body = await res.json();
|
||||||
const hits = body.hits as SearchHit[];
|
const hits = body.hits as SearchHit[];
|
||||||
@@ -100,9 +106,7 @@
|
|||||||
if (allLoading || allExhausted) return;
|
if (allLoading || allExhausted) return;
|
||||||
allLoading = true;
|
allLoading = true;
|
||||||
try {
|
try {
|
||||||
const res = await fetch(
|
const res = await fetch(buildAllUrl(allSort, ALL_PAGE, allRecipes.length));
|
||||||
`/api/recipes/all?sort=${allSort}&limit=${ALL_PAGE}&offset=${allRecipes.length}`
|
|
||||||
);
|
|
||||||
if (!res.ok) return;
|
if (!res.ok) return;
|
||||||
const body = await res.json();
|
const body = await res.json();
|
||||||
const more = body.hits as SearchHit[];
|
const more = body.hits as SearchHit[];
|
||||||
@@ -126,9 +130,7 @@
|
|||||||
const chipsBefore = allChips?.getBoundingClientRect().top ?? 0;
|
const chipsBefore = allChips?.getBoundingClientRect().top ?? 0;
|
||||||
allLoading = true;
|
allLoading = true;
|
||||||
try {
|
try {
|
||||||
const res = await fetch(
|
const res = await fetch(buildAllUrl(next, ALL_PAGE, 0));
|
||||||
`/api/recipes/all?sort=${next}&limit=${ALL_PAGE}&offset=0`
|
|
||||||
);
|
|
||||||
if (!res.ok) return;
|
if (!res.ok) return;
|
||||||
const body = await res.json();
|
const body = await res.json();
|
||||||
const hits = body.hits as SearchHit[];
|
const hits = body.hits as SearchHit[];
|
||||||
|
|||||||
Reference in New Issue
Block a user