Skip to content

A local-first personal finance app

:recycle: (synced-prefs) moving budgetType pref back to MetadataPrefs (#3410)

Matiss Janis Aboltinsb2d7b65ce9ac
diff --git a/packages/desktop-client/src/components/autocomplete/CategoryAutocomplete.tsx b/packages/desktop-client/src/components/autocomplete/CategoryAutocomplete.tsx
index c5d0a2462b..c8733e8179 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 9fecac8728..1f2e299952 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 44f5471d73..239a5ba15b 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 2961520b0e..bcef3cfa2a 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 cf1fc310b3..65eb9543fd 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 ad5c3e746f..7bc50ec013 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 fa6da21cf8..58ccc41d79 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 1df9f03416..e18d107d3c 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 fe88076afa..132fde3a99 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 0000000000..aff78c9812
--- /dev/null
+++ b/upcoming-release-notes/3410.md
@@ -0,0 +1,6 @@
+---
+category: Maintenance
+authors: [MatissJanis]
+---
+
+SyncedPrefs: move `budgetType` back to metadata prefs.