diff --git a/src/lib/components/diary/MacroSummary.svelte b/src/lib/components/diary/MacroSummary.svelte index f92146c..75853f3 100644 --- a/src/lib/components/diary/MacroSummary.svelte +++ b/src/lib/components/diary/MacroSummary.svelte @@ -2,6 +2,7 @@ import type { Diary } from '$lib/types/api'; import { kcal, g } from '$lib/utils/format'; import { updateDiary } from '$lib/api/diary'; + import { updateUserSettings } from '$lib/api/settings'; import { useQueryClient } from '@tanstack/svelte-query'; import Sheet from '$lib/components/ui/Sheet.svelte'; @@ -31,6 +32,8 @@ // Goal editing sheet let sheetOpen = $state(false); let saving = $state(false); + let syncSettingsOpen = $state(false); + let lastSavedForm: typeof form | null = null; let form = $state<{ calories_goal: number | null; protein_goal: number; @@ -61,11 +64,19 @@ try { await updateDiary(date, form); await queryClient.invalidateQueries({ queryKey: ['diary', date] }); + lastSavedForm = { ...form }; sheetOpen = false; + syncSettingsOpen = true; } finally { saving = false; } } + + async function handleSyncToSettings() { + if (!lastSavedForm) return; + await updateUserSettings(lastSavedForm); + syncSettingsOpen = false; + }
Override your default macro goals in user settings with these values as well?
+