diff --git a/packages/desktop-client/src/components/autocomplete/CategoryAutocomplete.tsx b/packages/desktop-client/src/components/autocomplete/CategoryAutocomplete.tsx index c5d0a2462b42d6fb6f1e7209c66adbb8fe2f0502..c8733e81790b546c284aac86101b30b272a89f25 100644 --- a/packages/desktop-client/src/components/autocomplete/CategoryAutocomplete.tsx +++ b/packages/desktop-client/src/components/autocomplete/CategoryAutocomplete.tsx @@ -22,7 +22,7 @@ import { } from 'loot-core/src/types/models'; import { useCategories } from '../../hooks/useCategories'; -import { useSyncedPref } from '../../hooks/useSyncedPref'; +import { useMetadataPref } from '../../hooks/useMetadataPref'; import { SvgSplit } from '../../icons/v0'; import { useResponsive } from '../../ResponsiveProvider'; import { type CSSProperties, theme, styles } from '../../style'; @@ -379,7 +379,7 @@ function CategoryItem({ borderTop: `1px solid ${theme.pillBorder}`, } : {}; - const [budgetType = 'rollover'] = useSyncedPref('budgetType'); + const [budgetType = 'rollover'] = useMetadataPref('budgetType'); const balanceBinding = budgetType === 'rollover' diff --git a/packages/desktop-client/src/components/budget/index.tsx b/packages/desktop-client/src/components/budget/index.tsx index 9fecac8728d0509731d0089a1bd6e065f3c3c583..1f2e299952ef3bf844116ad6ae5bf7651cec07b7 100644 --- a/packages/desktop-client/src/components/budget/index.tsx +++ b/packages/desktop-client/src/components/budget/index.tsx @@ -23,8 +23,8 @@ import * as monthUtils from 'loot-core/src/shared/months'; import { useCategories } from '../../hooks/useCategories'; import { useGlobalPref } from '../../hooks/useGlobalPref'; import { useLocalPref } from '../../hooks/useLocalPref'; +import { useMetadataPref } from '../../hooks/useMetadataPref'; import { useNavigate } from '../../hooks/useNavigate'; -import { useSyncedPref } from '../../hooks/useSyncedPref'; import { styles } from '../../style'; import { View } from '../common/View'; import { NamespaceContext } from '../spreadsheet/NamespaceContext'; @@ -76,7 +76,7 @@ function BudgetInner(props: BudgetInnerProps) { start: startMonth, end: startMonth, }); - const [budgetType = 'rollover'] = useSyncedPref('budgetType'); + const [budgetType = 'rollover'] = useMetadataPref('budgetType'); const [maxMonthsPref] = useGlobalPref('maxMonths'); const maxMonths = maxMonthsPref || 1; const [initialized, setInitialized] = useState(false); diff --git a/packages/desktop-client/src/components/budget/util.ts b/packages/desktop-client/src/components/budget/util.ts index 44f5471d730301f4ec55bbeddecab38adfcabcc7..239a5ba15bc30f79ad85e366b1ed53fc75941248 100644 --- a/packages/desktop-client/src/components/budget/util.ts +++ b/packages/desktop-client/src/components/budget/util.ts @@ -4,7 +4,7 @@ import { send } from 'loot-core/src/platform/client/fetch'; import * as monthUtils from 'loot-core/src/shared/months'; import { type Handlers } from 'loot-core/src/types/handlers'; import { type CategoryGroupEntity } from 'loot-core/src/types/models'; -import { type SyncedPrefs } from 'loot-core/src/types/prefs'; +import { type MetadataPrefs } from 'loot-core/src/types/prefs'; import { type CSSProperties, styles, theme } from '../../style'; import { type DropPosition } from '../sort'; @@ -141,7 +141,7 @@ export function getScrollbarWidth() { } export async function prewarmMonth( - budgetType: SyncedPrefs['budgetType'], + budgetType: MetadataPrefs['budgetType'], spreadsheet: ReturnType<typeof useSpreadsheet>, month: string, ) { @@ -156,7 +156,7 @@ export async function prewarmMonth( } export async function prewarmAllMonths( - budgetType: SyncedPrefs['budgetType'], + budgetType: MetadataPrefs['budgetType'], spreadsheet: ReturnType<typeof useSpreadsheet>, bounds: { start: string; end: string }, startMonth: string, @@ -176,7 +176,7 @@ export async function prewarmAllMonths( } export async function switchBudgetType( - newBudgetType: SyncedPrefs['budgetType'], + newBudgetType: MetadataPrefs['budgetType'], spreadsheet: ReturnType<typeof useSpreadsheet>, bounds: { start: string; end: string }, startMonth: string, diff --git a/packages/desktop-client/src/components/mobile/budget/BudgetTable.jsx b/packages/desktop-client/src/components/mobile/budget/BudgetTable.jsx index 2961520b0ef2b92dac699b9915fbb1dba3e73ce3..bcef3cfa2af1c4d0be1b58d08c457983319d9179 100644 --- a/packages/desktop-client/src/components/mobile/budget/BudgetTable.jsx +++ b/packages/desktop-client/src/components/mobile/budget/BudgetTable.jsx @@ -12,9 +12,9 @@ import * as monthUtils from 'loot-core/src/shared/months'; import { useCategories } from '../../../hooks/useCategories'; import { useFeatureFlag } from '../../../hooks/useFeatureFlag'; import { useLocalPref } from '../../../hooks/useLocalPref'; +import { useMetadataPref } from '../../../hooks/useMetadataPref'; import { useNavigate } from '../../../hooks/useNavigate'; import { useNotes } from '../../../hooks/useNotes'; -import { useSyncedPref } from '../../../hooks/useSyncedPref'; import { useUndo } from '../../../hooks/useUndo'; import { SvgLogo } from '../../../icons/logo'; import { SvgExpandArrow } from '../../../icons/v0'; @@ -225,7 +225,7 @@ function BudgetCell({ }) { const dispatch = useDispatch(); const { showUndoNotification } = useUndo(); - const [budgetType = 'rollover'] = useLocalPref('budgetType'); + const [budgetType = 'rollover'] = useMetadataPref('budgetType'); const categoryBudgetMenuModal = `${budgetType}-budget-menu`; const categoryNotes = useNotes(category.id); @@ -358,7 +358,7 @@ const ExpenseCategory = memo(function ExpenseCategory({ const goalTemp = useSheetValue(goal); const goalValue = isGoalTemplatesEnabled ? goalTemp : null; - const [budgetType = 'rollover'] = useSyncedPref('budgetType'); + const [budgetType = 'rollover'] = useMetadataPref('budgetType'); const dispatch = useDispatch(); const { showUndoNotification } = useUndo(); const { list: categories } = useCategories(); diff --git a/packages/desktop-client/src/components/mobile/budget/index.tsx b/packages/desktop-client/src/components/mobile/budget/index.tsx index cf1fc310b380f6520e83d842a6a34568258e918a..65eb9543fd66857587e0d97c21a8466363eab241 100644 --- a/packages/desktop-client/src/components/mobile/budget/index.tsx +++ b/packages/desktop-client/src/components/mobile/budget/index.tsx @@ -27,6 +27,7 @@ import { import { useCategories } from '../../../hooks/useCategories'; import { useLocalPref } from '../../../hooks/useLocalPref'; +import { useMetadataPref } from '../../../hooks/useMetadataPref'; import { useSetThemeColor } from '../../../hooks/useSetThemeColor'; import { useSyncedPref } from '../../../hooks/useSyncedPref'; import { AnimatedLoading } from '../../../icons/AnimatedLoading'; @@ -466,7 +467,7 @@ function BudgetInner(props: BudgetInnerProps) { export function Budget() { const { list: categories, grouped: categoryGroups } = useCategories(); - const [budgetType] = useSyncedPref('budgetType'); + const [budgetType] = useMetadataPref('budgetType'); const spreadsheet = useSpreadsheet(); useSetThemeColor(theme.mobileViewTheme); return ( diff --git a/packages/desktop-client/src/components/settings/BudgetTypeSettings.tsx b/packages/desktop-client/src/components/settings/BudgetTypeSettings.tsx index ad5c3e746f0cbd936d45d8932402f68d0958ca4a..7bc50ec0134c32e4f8a6e150f8e7627d39c115e4 100644 --- a/packages/desktop-client/src/components/settings/BudgetTypeSettings.tsx +++ b/packages/desktop-client/src/components/settings/BudgetTypeSettings.tsx @@ -6,7 +6,7 @@ import { useSpreadsheet } from 'loot-core/src/client/SpreadsheetProvider'; import * as monthUtils from 'loot-core/src/shared/months'; import { useLocalPref } from '../../hooks/useLocalPref'; -import { useSyncedPref } from '../../hooks/useSyncedPref'; +import { useMetadataPref } from '../../hooks/useMetadataPref'; import { switchBudgetType } from '../budget/util'; import { ButtonWithLoading } from '../common/Button2'; import { Link } from '../common/Link'; @@ -16,7 +16,7 @@ import { Setting } from './UI'; export function BudgetTypeSettings() { const dispatch = useDispatch(); - const [budgetType = 'rollover'] = useSyncedPref('budgetType'); + const [budgetType = 'rollover'] = useMetadataPref('budgetType'); const [loading, setLoading] = useState(false); const currentMonth = monthUtils.currentMonth(); diff --git a/packages/desktop-client/src/components/settings/Experimental.tsx b/packages/desktop-client/src/components/settings/Experimental.tsx index fa6da21cf849652fbd9728b8edd6f6ffc14306f4..58ccc41d79d5a812b160d29bda199553504b38b8 100644 --- a/packages/desktop-client/src/components/settings/Experimental.tsx +++ b/packages/desktop-client/src/components/settings/Experimental.tsx @@ -4,6 +4,7 @@ import { Trans, useTranslation } from 'react-i18next'; import type { FeatureFlag } from 'loot-core/src/types/prefs'; import { useFeatureFlag } from '../../hooks/useFeatureFlag'; +import { useMetadataPref } from '../../hooks/useMetadataPref'; import { useSyncedPref } from '../../hooks/useSyncedPref'; import { theme } from '../../style'; import { Link } from '../common/Link'; @@ -69,7 +70,7 @@ function FeatureToggle({ function ReportBudgetFeature() { const { t } = useTranslation(); - const [budgetType = 'rollover'] = useSyncedPref('budgetType'); + const [budgetType = 'rollover'] = useMetadataPref('budgetType'); const enabled = useFeatureFlag('reportBudget'); const blockToggleOff = budgetType === 'report' && enabled; return ( diff --git a/packages/loot-core/src/server/prefs.ts b/packages/loot-core/src/server/prefs.ts index 1df9f034163791b453cafc4fb34e3485eae27fa4..e18d107d3c4a96be96b985b76da53b2eb0e5057d 100644 --- a/packages/loot-core/src/server/prefs.ts +++ b/packages/loot-core/src/server/prefs.ts @@ -2,18 +2,16 @@ import { Timestamp } from '@actual-app/crdt'; import * as fs from '../platform/server/fs'; -import type { MetadataPrefs, SyncedPrefs } from '../types/prefs'; +import type { MetadataPrefs } from '../types/prefs'; import { Message, sendMessages } from './sync'; -type LocalPrefs = MetadataPrefs & Pick<SyncedPrefs, 'budgetType'>; - export const BUDGET_TYPES = ['report', 'rollover'] as const; export type BudgetType = (typeof BUDGET_TYPES)[number]; let prefs: MetadataPrefs = null; -export async function loadPrefs(id?: string): Promise<LocalPrefs> { +export async function loadPrefs(id?: string): Promise<MetadataPrefs> { if (process.env.NODE_ENV === 'test' && !id) { prefs = getDefaultPrefs('test', 'test_LocalPrefs'); return prefs; @@ -50,7 +48,7 @@ export async function loadPrefs(id?: string): Promise<LocalPrefs> { } export async function savePrefs( - prefsToSet: LocalPrefs, + prefsToSet: MetadataPrefs, { avoidSync = false } = {}, ): Promise<void> { Object.assign(prefs, prefsToSet); @@ -87,7 +85,7 @@ export function unloadPrefs(): void { prefs = null; } -export function getPrefs(): LocalPrefs { +export function getPrefs(): MetadataPrefs { return prefs; } diff --git a/packages/loot-core/src/types/prefs.d.ts b/packages/loot-core/src/types/prefs.d.ts index fe88076afab4fa22eaba1e8f3f75134eb2f0942b..132fde3a9944115c8b18fb3bcab4bd9f5ec7aeca 100644 --- a/packages/loot-core/src/types/prefs.d.ts +++ b/packages/loot-core/src/types/prefs.d.ts @@ -29,7 +29,6 @@ export type SyncedPrefs = Partial< | `csv-has-header-${string}` | `ofx-fallback-missing-payee-${string}` | `flip-amount-${string}-${'csv' | 'qif'}` - | 'budgetType' | `flags.${FeatureFlag}`, string > @@ -40,6 +39,8 @@ export type SyncedPrefs = Partial< * core database. */ export type MetadataPrefs = Partial<{ + // TODO: move budgetType to SyncedPrefs + budgetType: string; budgetName: string; id: string; lastUploaded: string; diff --git a/upcoming-release-notes/3410.md b/upcoming-release-notes/3410.md new file mode 100644 index 0000000000000000000000000000000000000000..aff78c9812bb23b9ab571b946d13fdf7bad30c96 --- /dev/null +++ b/upcoming-release-notes/3410.md @@ -0,0 +1,6 @@ +--- +category: Maintenance +authors: [MatissJanis] +--- + +SyncedPrefs: move `budgetType` back to metadata prefs.