feat(nutrition): reactive quick-log recents and favorites

Derive recents from current-day entries merged with historical
server data so logging a food updates the quick-log bar instantly.
FoodSearch now emits onfavoritechange so toggling a heart keeps
the quick-log favorites tab in sync without reloading.
This commit is contained in:
2026-04-13 09:50:27 +02:00
parent 465bd9b25a
commit 4dba5ea4fd
3 changed files with 41 additions and 6 deletions
@@ -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];