{activePage === "start" && (
-
- <>
- setActivePageAndHash("log")}
- onGoToDailyPlan={() => {
- setActivePageAndHash("menu");
- }}
- onFetchDayHint={fetchDayHint}
- dayHintText={dayHintText}
- dayHintBusy={dayHintBusy}
- onAddMeal={() => {
- log.setSelectedDate(todayISODate());
- setActivePageAndHash("log");
- scheduleTransient(() => {
- log.setAddMealPhotoResult(null);
- log.setAddMealSheetOpen(true);
- }, 80);
- }}
- />
- {
- if (!e.currentTarget.open) setPhotoCardForceOpen(false);
- }}
- >
-
-
- Аналіз фото страви
-
-
-
}
- onPickPhoto={photo.onPickPhoto}
- photoPreviewUrl={photo.photoPreviewUrl}
- photoResult={photo.photoResult}
- fmtMacro={fmtMacro}
- portionGrams={photo.portionGrams}
- setPortionGrams={photo.setPortionGrams}
- refinePhoto={photo.refinePhoto}
- answers={photo.answers}
- setAnswers={photo.setAnswers}
- onSaveToLog={
- photo.photoResult ? handleSaveToLog : undefined
- }
- />
-
-
- >
-
+
)}
{activePage === "pantry" && (
-
- <>
- setPantrySubTab(id as PantrySubTab)}
- tabs={[
- { id: "items", label: "Склад" },
- { id: "shopping", label: "Покупки" },
- ]}
- />
- {pantrySubTab === "items" ? (
- <>
- {
- if (pantry.pantryItems.length > 0) {
- const removed = pantry.pantryItems[idx];
- pantry.removeItemAt(idx);
- if (removed) {
- showUndoToast(toast, {
- msg: `Прибрано «${removed.name}» з комори`,
- onUndo: () => pantry.upsertItem(removed),
- });
- }
- } else if (name) {
- pantry.removeItem(name);
- }
- }}
- pantryItemsLength={pantry.pantryItems.length}
- pantrySummary={pantry.pantrySummary}
- onScanBarcode={() => {
- setPantryScanStatus("");
- setPantryScannerOpen(true);
- }}
- />
- {pantryScanStatus && (
-
- {pantryScanStatus}
-
- )}
- >
- ) : (
-
- )}
- >
-
+
setPantrySubTab(id as PantrySubTab)}
+ pantryScanStatus={pantryScanStatus}
+ setPantryScanStatus={setPantryScanStatus}
+ setPantryScannerOpen={setPantryScannerOpen}
+ toast={toast}
+ generateShoppingList={generateShoppingList}
+ addCheckedItemsToPantry={addCheckedItemsToPantry}
+ />
)}
{activePage === "log" && (
-
- {
- log.setAddMealPhotoResult(null);
- log.setAddMealSheetOpen(true);
- }}
- onAddMealFromSearch={(meal) => {
- const id = `meal_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;
- log.handleAddMeal({ ...meal, id });
- }}
- onRemoveMeal={(date, meal) => {
- if (!meal?.id) return;
- log.handleRemoveMeal(date, meal);
- showUndoToast(toast, {
- msg: "Запис видалено",
- onUndo: () => log.handleRestoreMeal(date, meal),
- });
- }}
- onEditMeal={(date, meal) => {
- setEditingMeal({ date, ...meal });
- log.setAddMealPhotoResult(null);
- log.setAddMealSheetOpen(true);
- }}
- onDuplicateYesterday={log.duplicateYesterday}
- onTrimLog={log.trimLogToLastDays}
- />
-
+
)}
{activePage === "menu" && (
-
- <>
- setMenuSubTab(id as MenuSubTab)}
- tabs={[
- { id: "plan", label: "План на день" },
- { id: "recipes", label: "Рецепти" },
- ]}
- />
- {menuSubTab === "plan" ? (
-
- {() => (
- fetchDayPlan(null)}
- regenMeal={(mealType) => fetchDayPlan(mealType)}
- addMealToLog={addMealFromPlan}
- weekPlan={weekPlan}
- weekPlanRaw={weekPlanRaw}
- weekPlanBusy={weekPlanBusy}
- fetchWeekPlan={fetchWeekPlan}
- firstRunHint={firstRunNutritionActive}
- onDismissFirstRunHint={() => {
- markNutritionSeen();
- setFirstRunNutritionSurface(false);
- }}
- />
- )}
-
- ) : (
-
- )}
- >
-
+ setMenuSubTab(id as MenuSubTab)}
+ pantry={pantry}
+ prefs={prefs}
+ setPrefs={setPrefs}
+ busy={busy}
+ err={err}
+ dayPlan={dayPlan}
+ dayPlanBusy={dayPlanBusy}
+ dayPlanQuery={dayPlanQuery}
+ dayPlanLoadingSkeleton={dayPlanLoadingSkeleton}
+ fetchDayPlan={fetchDayPlan}
+ addMealFromPlan={addMealFromPlan}
+ weekPlan={weekPlan}
+ weekPlanRaw={weekPlanRaw}
+ weekPlanBusy={weekPlanBusy}
+ fetchWeekPlan={fetchWeekPlan}
+ firstRunHint={firstRunNutritionActive}
+ onDismissFirstRunHint={() => {
+ markNutritionSeen();
+ setFirstRunNutritionSurface(false);
+ }}
+ recommendRecipes={recommendRecipes}
+ recipes={recipes}
+ recipesTried={recipesTried}
+ recipesRaw={recipesRaw}
+ recipeCacheEntry={recipeCacheEntry}
+ wrappedSaveMeal={wrappedSaveMeal}
+ selectedDate={log.selectedDate}
+ />
)}
diff --git a/apps/web/src/modules/nutrition/hooks/useNutritionPrefsState.ts b/apps/web/src/modules/nutrition/hooks/useNutritionPrefsState.ts
new file mode 100644
index 000000000..dfb743695
--- /dev/null
+++ b/apps/web/src/modules/nutrition/hooks/useNutritionPrefsState.ts
@@ -0,0 +1,40 @@
+import { useEffect, useState, type Dispatch, type SetStateAction } from "react";
+import type { NutritionPrefs } from "@sergeant/nutrition-domain";
+import {
+ loadNutritionPrefs,
+ persistNutritionPrefs,
+} from "../lib/nutritionStorage";
+import { getCachedNutritionSqliteState } from "../lib/sqliteReader";
+
+interface UseNutritionPrefsStateResult {
+ prefs: NutritionPrefs;
+ setPrefs: Dispatch