diff --git a/package.json b/package.json index 23b847e7..2bc7a64e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "homepage", - "version": "1.31.2", + "version": "1.31.3", "private": true, "type": "module", "scripts": { diff --git a/src/lib/components/fitness/FoodSearch.svelte b/src/lib/components/fitness/FoodSearch.svelte index e04c93ce..dcccf005 100644 --- a/src/lib/components/fitness/FoodSearch.svelte +++ b/src/lib/components/fitness/FoodSearch.svelte @@ -9,6 +9,7 @@ * @type {{ * onselect: (food: { name: string, source: string, sourceId: string, amountGrams: number, per100g: any, portions?: any[], selectedPortion?: { description: string, grams: number } }) => void, * oncancel?: () => void, + * onfavoritechange?: (payload: { source: string, sourceId: string, name: string, favorited: boolean }) => void, * showFavorites?: boolean, * showDetailLinks?: boolean, * autofocus?: boolean, @@ -19,6 +20,7 @@ let { onselect, oncancel = undefined, + onfavoritechange = undefined, showFavorites = true, showDetailLinks = true, autofocus = false, @@ -166,6 +168,7 @@ body: JSON.stringify({ source: item.source, sourceId: item.id, name: item.name }) }); } + onfavoritechange?.({ source: item.source, sourceId: item.id, name: item.name, favorited: !wasFav }); } catch { item.favorited = wasFav; results = [...results]; diff --git a/src/routes/fitness/[nutrition=fitnessNutrition]/[[date=fitnessDate]]/+page.svelte b/src/routes/fitness/[nutrition=fitnessNutrition]/[[date=fitnessDate]]/+page.svelte index 6e333dea..e4192833 100644 --- a/src/routes/fitness/[nutrition=fitnessNutrition]/[[date=fitnessDate]]/+page.svelte +++ b/src/routes/fitness/[nutrition=fitnessNutrition]/[[date=fitnessDate]]/+page.svelte @@ -1035,13 +1035,45 @@ // svelte-ignore state_referenced_locally let quickFavorites = $state(data.favorites ?? []); // svelte-ignore state_referenced_locally - let recentFoods = $state(data.recentFoods ?? []); + let historicalRecents = $state(data.recentFoods ?? []); $effect(() => { quickFavorites = data.favorites ?? []; - recentFoods = data.recentFoods ?? []; + historicalRecents = data.recentFoods ?? []; }); + /** Recent foods: current-date entries (newest first) merged with historical recents from the server. */ + const recentFoods = $derived.by(() => { + const seen = new Set(); + const out = []; + for (let i = entries.length - 1; i >= 0; i--) { + const e = entries[i]; + if (!e?.source || !e?.sourceId || e.mealType === 'water') continue; + const key = `${e.source}:${e.sourceId}`; + if (seen.has(key)) continue; + seen.add(key); + out.push(e); + if (out.length >= 10) return out; + } + for (const e of historicalRecents) { + if (!e?.source || !e?.sourceId) continue; + const key = `${e.source}:${e.sourceId}`; + if (seen.has(key)) continue; + seen.add(key); + out.push(e); + if (out.length >= 10) break; + } + return out; + }); + + /** Callback from FoodSearch when a favorite is toggled — keep quick-log favorites in sync. */ + function handleFavoriteChange(/** @type {{ source: string, sourceId: string, name: string, favorited: boolean }} */ payload) { + const { source, sourceId, name, favorited } = payload; + const rest = quickFavorites.filter(f => !(f.source === source && f.sourceId === sourceId)); + quickFavorites = favorited ? [...rest, { source, sourceId, name }] : rest; + favTabLoaded = false; + } + /** @type {{ name: string, source: string, sourceId: string, per100g?: any, amountGrams?: number } | null} */ let qlSelected = $state(null); let qlGrams = $state(100); @@ -1169,7 +1201,7 @@ {:else if favTabItems.length === 0}

{isEn ? 'No favorites yet. Tap the heart on foods to add them here.' : 'Noch keine Favoriten. Tippe auf das Herz bei Lebensmitteln.'}

{:else} - + {/if} {/snippet} @@ -1829,7 +1861,7 @@ {#if inlineTab === 'search'} - + {:else if inlineTab === 'favorites'} {@render favoritesTab(inlineLogFood)} {:else} @@ -1950,7 +1982,7 @@ {#if fabTab === 'search'} - + {:else if fabTab === 'favorites'} {@render favoritesTab(fabLogFood)} {:else}