Skip to content

A local-first personal finance app

:recycle: (prefs) initial type implementation for synced/local/metadata prefs (#3236)

Matiss Janis Aboltins81df2ce7fd41
diff --git a/packages/desktop-client/src/components/App.tsx b/packages/desktop-client/src/components/App.tsx
index 18ee27bf25..94bedf83be 100644
--- a/packages/desktop-client/src/components/App.tsx
+++ b/packages/desktop-client/src/components/App.tsx
@@ -23,7 +23,7 @@ import {
send,
} from 'loot-core/src/platform/client/fetch';
-import { useLocalPref } from '../hooks/useLocalPref';
+import { useMetadataPref } from '../hooks/useMetadataPref';
import { installPolyfills } from '../polyfills';
import { ResponsiveProvider } from '../ResponsiveProvider';
import { styles, hasHiddenScrollbars, ThemeStyle } from '../style';
@@ -141,8 +141,8 @@ function ErrorFallback({ error }: FallbackProps) {
}
export function App() {
- const [budgetId] = useLocalPref('id');
- const [cloudFileId] = useLocalPref('cloudFileId');
+ const [budgetId] = useMetadataPref('id');
+ const [cloudFileId] = useMetadataPref('cloudFileId');
const [hiddenScrollbars, setHiddenScrollbars] = useState(
hasHiddenScrollbars(),
);
diff --git a/packages/desktop-client/src/components/Titlebar.tsx b/packages/desktop-client/src/components/Titlebar.tsx
index 9c25bbd10d..f7eba43e8e 100644
--- a/packages/desktop-client/src/components/Titlebar.tsx
+++ b/packages/desktop-client/src/components/Titlebar.tsx
@@ -9,8 +9,9 @@ import { isDevelopmentEnvironment } from 'loot-core/src/shared/environment';
import { useActions } from '../hooks/useActions';
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 { SvgArrowLeft } from '../icons/v1';
import {
SvgAlertTriangle,
@@ -60,7 +61,7 @@ type PrivacyButtonProps = {
function PrivacyButton({ style }: PrivacyButtonProps) {
const [isPrivacyEnabled, setPrivacyEnabledPref] =
- useLocalPref('isPrivacyEnabled');
+ useSyncedPref('isPrivacyEnabled');
const privacyIconStyle = { width: 15, height: 15 };
@@ -97,7 +98,7 @@ type SyncButtonProps = {
isMobile?: boolean;
};
function SyncButton({ style, isMobile = false }: SyncButtonProps) {
- const [cloudFileId] = useLocalPref('cloudFileId');
+ const [cloudFileId] = useMetadataPref('cloudFileId');
const { sync } = useActions();
const [syncing, setSyncing] = useState(false);
diff --git a/packages/desktop-client/src/components/accounts/Account.jsx b/packages/desktop-client/src/components/accounts/Account.jsx
index 3f62365ade..dba17d9f67 100644
--- a/packages/desktop-client/src/components/accounts/Account.jsx
+++ b/packages/desktop-client/src/components/accounts/Account.jsx
@@ -34,7 +34,6 @@ import { useActions } from '../../hooks/useActions';
import { useCategories } from '../../hooks/useCategories';
import { useDateFormat } from '../../hooks/useDateFormat';
import { useFailedAccounts } from '../../hooks/useFailedAccounts';
-import { useLocalPref } from '../../hooks/useLocalPref';
import { usePayees } from '../../hooks/usePayees';
import { usePreviewTransactions } from '../../hooks/usePreviewTransactions';
import { SelectedProviderWithItems } from '../../hooks/useSelected';
@@ -42,6 +41,7 @@ import {
SplitsExpandedProvider,
useSplitsExpanded,
} from '../../hooks/useSplitsExpanded';
+import { useSyncedPref } from '../../hooks/useSyncedPref';
import { styles, theme } from '../../style';
import { Button } from '../common/Button2';
import { Text } from '../common/Text';
@@ -1824,12 +1824,12 @@ export function Account() {
const payees = usePayees();
const failedAccounts = useFailedAccounts();
const dateFormat = useDateFormat() || 'MM/dd/yyyy';
- const [hideFraction = false] = useLocalPref('hideFraction');
- const [expandSplits] = useLocalPref('expand-splits');
- const [showBalances] = useLocalPref(`show-balances-${params.id}`);
- const [hideCleared] = useLocalPref(`hide-cleared-${params.id}`);
- const [hideReconciled] = useLocalPref(`hide-reconciled-${params.id}`);
- const [showExtraBalances] = useLocalPref(
+ const [hideFraction = false] = useSyncedPref('hideFraction');
+ const [expandSplits] = useSyncedPref('expand-splits');
+ const [showBalances] = useSyncedPref(`show-balances-${params.id}`);
+ const [hideCleared] = useSyncedPref(`hide-cleared-${params.id}`);
+ const [hideReconciled] = useSyncedPref(`hide-reconciled-${params.id}`);
+ const [showExtraBalances] = useSyncedPref(
`show-extra-balances-${params.id || 'all-accounts'}`,
);
const modalShowing = useSelector(state => state.modals.modalStack.length > 0);
diff --git a/packages/desktop-client/src/components/autocomplete/CategoryAutocomplete.tsx b/packages/desktop-client/src/components/autocomplete/CategoryAutocomplete.tsx
index 067bf43eeb..cd38afd5dc 100644
--- a/packages/desktop-client/src/components/autocomplete/CategoryAutocomplete.tsx
+++ b/packages/desktop-client/src/components/autocomplete/CategoryAutocomplete.tsx
@@ -21,7 +21,7 @@ import {
} from 'loot-core/src/types/models';
import { useCategories } from '../../hooks/useCategories';
-import { useLocalPref } from '../../hooks/useLocalPref';
+import { useSyncedPref } from '../../hooks/useSyncedPref';
import { SvgSplit } from '../../icons/v0';
import { useResponsive } from '../../ResponsiveProvider';
import { type CSSProperties, theme, styles } from '../../style';
@@ -375,7 +375,7 @@ function CategoryItem({
borderTop: `1px solid ${theme.pillBorder}`,
}
: {};
- const [budgetType = 'rollover'] = useLocalPref('budgetType');
+ const [budgetType = 'rollover'] = useSyncedPref('budgetType');
const balance = useSheetValue(
budgetType === 'rollover'
diff --git a/packages/desktop-client/src/components/budget/index.tsx b/packages/desktop-client/src/components/budget/index.tsx
index 9f41747400..9fecac8728 100644
--- a/packages/desktop-client/src/components/budget/index.tsx
+++ b/packages/desktop-client/src/components/budget/index.tsx
@@ -24,6 +24,7 @@ import { useCategories } from '../../hooks/useCategories';
import { useGlobalPref } from '../../hooks/useGlobalPref';
import { useLocalPref } from '../../hooks/useLocalPref';
import { useNavigate } from '../../hooks/useNavigate';
+import { useSyncedPref } from '../../hooks/useSyncedPref';
import { styles } from '../../style';
import { View } from '../common/View';
import { NamespaceContext } from '../spreadsheet/NamespaceContext';
@@ -75,7 +76,7 @@ function BudgetInner(props: BudgetInnerProps) {
start: startMonth,
end: startMonth,
});
- const [budgetType = 'rollover'] = useLocalPref('budgetType');
+ const [budgetType = 'rollover'] = useSyncedPref('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 a3658651ef..44f5471d73 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 LocalPrefs } from 'loot-core/src/types/prefs';
+import { type SyncedPrefs } 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: LocalPrefs['budgetType'],
+ budgetType: SyncedPrefs['budgetType'],
spreadsheet: ReturnType<typeof useSpreadsheet>,
month: string,
) {
@@ -156,7 +156,7 @@ export async function prewarmMonth(
}
export async function prewarmAllMonths(
- budgetType: LocalPrefs['budgetType'],
+ budgetType: SyncedPrefs['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: LocalPrefs['budgetType'],
+ newBudgetType: SyncedPrefs['budgetType'],
spreadsheet: ReturnType<typeof useSpreadsheet>,
bounds: { start: string; end: string },
startMonth: string,
diff --git a/packages/desktop-client/src/components/manager/BudgetList.tsx b/packages/desktop-client/src/components/manager/BudgetList.tsx
index 2686697f0e..8e5e5dcf68 100644
--- a/packages/desktop-client/src/components/manager/BudgetList.tsx
+++ b/packages/desktop-client/src/components/manager/BudgetList.tsx
@@ -21,7 +21,7 @@ import {
} from 'loot-core/types/file';
import { useInitialMount } from '../../hooks/useInitialMount';
-import { useLocalPref } from '../../hooks/useLocalPref';
+import { useMetadataPref } from '../../hooks/useMetadataPref';
import { AnimatedLoading } from '../../icons/AnimatedLoading';
import {
SvgCloudCheck,
@@ -354,7 +354,7 @@ function BudgetListHeader({
export function BudgetList({ showHeader = true, quickSwitchMode = false }) {
const dispatch = useDispatch();
const allFiles = useSelector(state => state.budgets.allFiles || []);
- const [id] = useLocalPref('id');
+ const [id] = useMetadataPref('id');
// Remote files do not have the 'id' field
function isNonRemoteFile(
diff --git a/packages/desktop-client/src/components/mobile/accounts/Account.jsx b/packages/desktop-client/src/components/mobile/accounts/Account.jsx
index 20ad5bc9bb..5073870bd8 100644
--- a/packages/desktop-client/src/components/mobile/accounts/Account.jsx
+++ b/packages/desktop-client/src/components/mobile/accounts/Account.jsx
@@ -4,9 +4,9 @@ import { useParams } from 'react-router-dom';
import { useAccount } from '../../../hooks/useAccount';
import { useFailedAccounts } from '../../../hooks/useFailedAccounts';
-import { useLocalPref } from '../../../hooks/useLocalPref';
import { useNavigate } from '../../../hooks/useNavigate';
import { useSetThemeColor } from '../../../hooks/useSetThemeColor';
+import { useSyncedPref } from '../../../hooks/useSyncedPref';
import { theme, styles } from '../../../style';
import { Button } from '../../common/Button';
import { Text } from '../../common/Text';
@@ -20,9 +20,9 @@ export function Account() {
const navigate = useNavigate();
- const [_numberFormat] = useLocalPref('numberFormat');
+ const [_numberFormat] = useSyncedPref('numberFormat');
const numberFormat = _numberFormat || 'comma-dot';
- const [hideFraction = false] = useLocalPref('hideFraction');
+ const [hideFraction = false] = useSyncedPref('hideFraction');
const { id: accountId } = useParams();
diff --git a/packages/desktop-client/src/components/mobile/accounts/AccountTransactions.jsx b/packages/desktop-client/src/components/mobile/accounts/AccountTransactions.jsx
index c4c3208321..b75882faeb 100644
--- a/packages/desktop-client/src/components/mobile/accounts/AccountTransactions.jsx
+++ b/packages/desktop-client/src/components/mobile/accounts/AccountTransactions.jsx
@@ -29,9 +29,9 @@ import { listen, send } from 'loot-core/platform/client/fetch';
import { isPreviewId } from 'loot-core/shared/transactions';
import { useDateFormat } from '../../../hooks/useDateFormat';
-import { useLocalPref } from '../../../hooks/useLocalPref';
import { useNavigate } from '../../../hooks/useNavigate';
import { usePreviewTransactions } from '../../../hooks/usePreviewTransactions';
+import { useSyncedPref } from '../../../hooks/useSyncedPref';
import { styles, theme } from '../../../style';
import { Text } from '../../common/Text';
import { View } from '../../common/View';
@@ -149,7 +149,7 @@ function TransactionListWithPreviews({ account }) {
);
const dateFormat = useDateFormat() || 'MM/dd/yyyy';
- const [_numberFormat] = useLocalPref('numberFormat');
+ const [_numberFormat] = useSyncedPref('numberFormat');
const dispatch = useDispatch();
const navigate = useNavigate();
diff --git a/packages/desktop-client/src/components/mobile/accounts/Accounts.jsx b/packages/desktop-client/src/components/mobile/accounts/Accounts.jsx
index 72b1221023..86a0c5cefb 100644
--- a/packages/desktop-client/src/components/mobile/accounts/Accounts.jsx
+++ b/packages/desktop-client/src/components/mobile/accounts/Accounts.jsx
@@ -6,9 +6,9 @@ import * as queries from 'loot-core/src/client/queries';
import { useAccounts } from '../../../hooks/useAccounts';
import { useFailedAccounts } from '../../../hooks/useFailedAccounts';
-import { useLocalPref } from '../../../hooks/useLocalPref';
import { useNavigate } from '../../../hooks/useNavigate';
import { useSetThemeColor } from '../../../hooks/useSetThemeColor';
+import { useSyncedPref } from '../../../hooks/useSyncedPref';
import { SvgAdd } from '../../../icons/v1';
import { theme, styles } from '../../../style';
import { makeAmountFullStyle } from '../../budget/util';
@@ -249,9 +249,9 @@ export function Accounts() {
const dispatch = useDispatch();
const accounts = useAccounts();
const updatedAccounts = useSelector(state => state.queries.updatedAccounts);
- const [_numberFormat] = useLocalPref('numberFormat');
+ const [_numberFormat] = useSyncedPref('numberFormat');
const numberFormat = _numberFormat || 'comma-dot';
- const [hideFraction = false] = useLocalPref('hideFraction');
+ const [hideFraction = false] = useSyncedPref('hideFraction');
const navigate = useNavigate();
diff --git a/packages/desktop-client/src/components/mobile/budget/BudgetTable.jsx b/packages/desktop-client/src/components/mobile/budget/BudgetTable.jsx
index 3e8d031f9a..a8782b83fc 100644
--- a/packages/desktop-client/src/components/mobile/budget/BudgetTable.jsx
+++ b/packages/desktop-client/src/components/mobile/budget/BudgetTable.jsx
@@ -11,6 +11,7 @@ import * as monthUtils from 'loot-core/src/shared/months';
import { useFeatureFlag } from '../../../hooks/useFeatureFlag';
import { useLocalPref } from '../../../hooks/useLocalPref';
import { useNavigate } from '../../../hooks/useNavigate';
+import { useSyncedPref } from '../../../hooks/useSyncedPref';
import { SvgLogo } from '../../../icons/logo';
import { SvgExpandArrow } from '../../../icons/v0';
import {
@@ -219,7 +220,7 @@ function BudgetCell({
...props
}) {
const dispatch = useDispatch();
- const [budgetType = 'rollover'] = useLocalPref('budgetType');
+ const [budgetType = 'rollover'] = useSyncedPref('budgetType');
const categoryBudgetMenuModal = `${budgetType}-budget-menu`;
@@ -341,7 +342,7 @@ const ExpenseCategory = memo(function ExpenseCategory({
const goalTemp = useSheetValue(goal);
const goalValue = isGoalTemplatesEnabled ? goalTemp : null;
- const [budgetType = 'rollover'] = useLocalPref('budgetType');
+ const [budgetType = 'rollover'] = useSyncedPref('budgetType');
const dispatch = useDispatch();
const onCarryover = carryover => {
diff --git a/packages/desktop-client/src/components/mobile/budget/Category.tsx b/packages/desktop-client/src/components/mobile/budget/Category.tsx
index da31db63e3..0fc742e956 100644
--- a/packages/desktop-client/src/components/mobile/budget/Category.tsx
+++ b/packages/desktop-client/src/components/mobile/budget/Category.tsx
@@ -4,17 +4,17 @@ import { useParams, useSearchParams } from 'react-router-dom';
import * as monthUtils from 'loot-core/src/shared/months';
import { useCategories } from '../../../hooks/useCategories';
-import { useLocalPref } from '../../../hooks/useLocalPref';
import { useSetThemeColor } from '../../../hooks/useSetThemeColor';
+import { useSyncedPref } from '../../../hooks/useSyncedPref';
import { theme } from '../../../style';
import { CategoryTransactions } from './CategoryTransactions';
export function Category() {
useSetThemeColor(theme.mobileViewTheme);
- const [_numberFormat] = useLocalPref('numberFormat');
+ const [_numberFormat] = useSyncedPref('numberFormat');
const numberFormat = _numberFormat || 'comma-dot';
- const [hideFraction = false] = useLocalPref('hideFraction');
+ const [hideFraction = false] = useSyncedPref('hideFraction');
const { id: categoryId } = useParams();
const [searchParams] = useSearchParams();
diff --git a/packages/desktop-client/src/components/mobile/budget/CategoryTransactions.jsx b/packages/desktop-client/src/components/mobile/budget/CategoryTransactions.jsx
index a25c86895d..1b9ddee52e 100644
--- a/packages/desktop-client/src/components/mobile/budget/CategoryTransactions.jsx
+++ b/packages/desktop-client/src/components/mobile/budget/CategoryTransactions.jsx
@@ -12,8 +12,8 @@ import { q } from 'loot-core/shared/query';
import { isPreviewId } from 'loot-core/shared/transactions';
import { useDateFormat } from '../../../hooks/useDateFormat';
-import { useLocalPref } from '../../../hooks/useLocalPref';
import { useNavigate } from '../../../hooks/useNavigate';
+import { useSyncedPref } from '../../../hooks/useSyncedPref';
import { TextOneLine } from '../../common/TextOneLine';
import { View } from '../../common/View';
import { MobilePageHeader, Page } from '../../Page';
@@ -29,7 +29,7 @@ export function CategoryTransactions({ category, month }) {
const [transactions, setTransactions] = useState([]);
const dateFormat = useDateFormat() || 'MM/dd/yyyy';
- const [_numberFormat] = useLocalPref('numberFormat');
+ const [_numberFormat] = useSyncedPref('numberFormat');
const makeRootQuery = useCallback(
() =>
diff --git a/packages/desktop-client/src/components/mobile/budget/index.tsx b/packages/desktop-client/src/components/mobile/budget/index.tsx
index 3fa93d7c40..47ce76e565 100644
--- a/packages/desktop-client/src/components/mobile/budget/index.tsx
+++ b/packages/desktop-client/src/components/mobile/budget/index.tsx
@@ -28,6 +28,7 @@ import {
import { useCategories } from '../../../hooks/useCategories';
import { useLocalPref } from '../../../hooks/useLocalPref';
import { useSetThemeColor } from '../../../hooks/useSetThemeColor';
+import { useSyncedPref } from '../../../hooks/useSyncedPref';
import { AnimatedLoading } from '../../../icons/AnimatedLoading';
import { theme } from '../../../style';
import { prewarmMonth } from '../../budget/util';
@@ -57,9 +58,9 @@ function BudgetInner(props: BudgetInnerProps) {
const [initialized, setInitialized] = useState(false);
// const [editMode, setEditMode] = useState(false);
- const [_numberFormat] = useLocalPref('numberFormat');
+ const [_numberFormat] = useSyncedPref('numberFormat');
const numberFormat = _numberFormat || 'comma-dot';
- const [hideFraction = false] = useLocalPref('hideFraction');
+ const [hideFraction = false] = useSyncedPref('hideFraction');
const dispatch = useDispatch();
useEffect(() => {
@@ -461,7 +462,7 @@ function BudgetInner(props: BudgetInnerProps) {
export function Budget() {
const { list: categories, grouped: categoryGroups } = useCategories();
- const [budgetType = 'rollover'] = useLocalPref('budgetType');
+ const [budgetType = 'rollover'] = useSyncedPref('budgetType');
const spreadsheet = useSpreadsheet();
useSetThemeColor(theme.mobileViewTheme);
return (
diff --git a/packages/desktop-client/src/components/mobile/transactions/FocusableAmountInput.tsx b/packages/desktop-client/src/components/mobile/transactions/FocusableAmountInput.tsx
index b2caac449f..9284c0f4b3 100644
--- a/packages/desktop-client/src/components/mobile/transactions/FocusableAmountInput.tsx
+++ b/packages/desktop-client/src/components/mobile/transactions/FocusableAmountInput.tsx
@@ -14,8 +14,8 @@ import {
currencyToAmount,
} from 'loot-core/src/shared/util';
-import { useLocalPref } from '../../../hooks/useLocalPref';
import { useMergedRefs } from '../../../hooks/useMergedRefs';
+import { useSyncedPref } from '../../../hooks/useSyncedPref';
import { type CSSProperties, theme } from '../../../style';
import { makeAmountFullStyle } from '../../budget/util';
import { Button } from '../../common/Button';
@@ -46,7 +46,7 @@ const AmountInput = memo(function AmountInput({
const [text, setText] = useState('');
const [value, setValue] = useState(0);
const inputRef = useRef<HTMLInputElement>();
- const [hideFraction = false] = useLocalPref('hideFraction');
+ const [hideFraction = false] = useSyncedPref('hideFraction');
const mergedInputRef = useMergedRefs<HTMLInputElement>(
props.inputRef,
diff --git a/packages/desktop-client/src/components/modals/BudgetListModal.tsx b/packages/desktop-client/src/components/modals/BudgetListModal.tsx
index af44d7960c..64e7b5eb54 100644
--- a/packages/desktop-client/src/components/modals/BudgetListModal.tsx
+++ b/packages/desktop-client/src/components/modals/BudgetListModal.tsx
@@ -1,14 +1,14 @@
import React from 'react';
import { useSelector } from 'react-redux';
-import { useLocalPref } from '../../hooks/useLocalPref';
+import { useMetadataPref } from '../../hooks/useMetadataPref';
import { Modal, ModalHeader, ModalCloseButton } from '../common/Modal2';
import { Text } from '../common/Text';
import { View } from '../common/View';
import { BudgetList } from '../manager/BudgetList';
export function BudgetListModal() {
- const [id] = useLocalPref('id');
+ const [id] = useMetadataPref('id');
const currentFile = useSelector(state =>
state.budgets.allFiles?.find(f => 'id' in f && f.id === id),
);
diff --git a/packages/desktop-client/src/components/modals/LoadBackup.jsx b/packages/desktop-client/src/components/modals/LoadBackup.jsx
index 21d750d076..2417552d58 100644
--- a/packages/desktop-client/src/components/modals/LoadBackup.jsx
+++ b/packages/desktop-client/src/components/modals/LoadBackup.jsx
@@ -4,7 +4,7 @@ import { useDispatch } from 'react-redux';
import { loadBackup, makeBackup } from 'loot-core/client/actions';
import { send, listen, unlisten } from 'loot-core/src/platform/client/fetch';
-import { useLocalPref } from '../../hooks/useLocalPref';
+import { useMetadataPref } from '../../hooks/useMetadataPref';
import { theme } from '../../style';
import { Block } from '../common/Block';
import { Button } from '../common/Button2';
@@ -53,7 +53,7 @@ class BackupTable extends Component {
export function LoadBackup({ budgetId, watchUpdates, backupDisabled }) {
const dispatch = useDispatch();
const [backups, setBackups] = useState([]);
- const [prefsBudgetId] = useLocalPref('id');
+ const [prefsBudgetId] = useMetadataPref('id');
const budgetIdToLoad = budgetId || prefsBudgetId;
useEffect(() => {
diff --git a/packages/desktop-client/src/components/reports/ReportSidebar.tsx b/packages/desktop-client/src/components/reports/ReportSidebar.tsx
index 6f73e4defd..5745827c34 100644
--- a/packages/desktop-client/src/components/reports/ReportSidebar.tsx
+++ b/packages/desktop-client/src/components/reports/ReportSidebar.tsx
@@ -4,7 +4,7 @@ import * as monthUtils from 'loot-core/src/shared/months';
import { type CategoryEntity } from 'loot-core/types/models/category';
import { type CategoryGroupEntity } from 'loot-core/types/models/category-group';
import { type CustomReportEntity } from 'loot-core/types/models/reports';
-import { type LocalPrefs } from 'loot-core/types/prefs';
+import { type SyncedPrefs } from 'loot-core/types/prefs';
import { styles } from '../../style/styles';
import { theme } from '../../style/theme';
@@ -56,7 +56,7 @@ type ReportSidebarProps = {
defaultItems: (item: string) => void;
defaultModeItems: (graph: string, item: string) => void;
earliestTransaction: string;
- firstDayOfWeekIdx: LocalPrefs['firstDayOfWeekIdx'];
+ firstDayOfWeekIdx: SyncedPrefs['firstDayOfWeekIdx'];
isComplexCategoryCondition?: boolean;
};
diff --git a/packages/desktop-client/src/components/reports/getLiveRange.ts b/packages/desktop-client/src/components/reports/getLiveRange.ts
index fffed8e228..22b2eef435 100644
--- a/packages/desktop-client/src/components/reports/getLiveRange.ts
+++ b/packages/desktop-client/src/components/reports/getLiveRange.ts
@@ -1,5 +1,5 @@
import * as monthUtils from 'loot-core/src/shared/months';
-import { type LocalPrefs } from 'loot-core/types/prefs';
+import { type SyncedPrefs } from 'loot-core/types/prefs';
import { ReportOptions } from './ReportOptions';
import { getSpecificRange, validateRange } from './reportRanges';
@@ -8,7 +8,7 @@ export function getLiveRange(
cond: string,
earliestTransaction: string,
includeCurrentInterval: boolean,
- firstDayOfWeekIdx?: LocalPrefs['firstDayOfWeekIdx'],
+ firstDayOfWeekIdx?: SyncedPrefs['firstDayOfWeekIdx'],
): [string, string] {
let dateStart = earliestTransaction;
let dateEnd = monthUtils.currentDay();
diff --git a/packages/desktop-client/src/components/reports/reportRanges.ts b/packages/desktop-client/src/components/reports/reportRanges.ts
index 4e0ee2d29a..15ca0e3420 100644
--- a/packages/desktop-client/src/components/reports/reportRanges.ts
+++ b/packages/desktop-client/src/components/reports/reportRanges.ts
@@ -1,12 +1,12 @@
import * as monthUtils from 'loot-core/src/shared/months';
-import { type LocalPrefs } from 'loot-core/types/prefs';
+import { type SyncedPrefs } from 'loot-core/types/prefs';
export function validateStart(
earliest: string,
start: string,
end: string,
interval?: string,
- firstDayOfWeekIdx?: LocalPrefs['firstDayOfWeekIdx'],
+ firstDayOfWeekIdx?: SyncedPrefs['firstDayOfWeekIdx'],
): [string, string] {
let addDays;
let dateStart;
@@ -46,7 +46,7 @@ export function validateEnd(
start: string,
end: string,
interval?: string,
- firstDayOfWeekIdx?: LocalPrefs['firstDayOfWeekIdx'],
+ firstDayOfWeekIdx?: SyncedPrefs['firstDayOfWeekIdx'],
): [string, string] {
let subDays;
let dateEnd;
@@ -97,7 +97,7 @@ function boundedRange(
start: string,
end: string,
interval?: string,
- firstDayOfWeekIdx?: LocalPrefs['firstDayOfWeekIdx'],
+ firstDayOfWeekIdx?: SyncedPrefs['firstDayOfWeekIdx'],
): [string, string] {
let latest;
switch (interval) {
@@ -131,7 +131,7 @@ export function getSpecificRange(
offset: number,
addNumber: number | null,
type?: string,
- firstDayOfWeekIdx?: LocalPrefs['firstDayOfWeekIdx'],
+ firstDayOfWeekIdx?: SyncedPrefs['firstDayOfWeekIdx'],
) {
const currentDay = monthUtils.currentDay();
const currentWeek = monthUtils.currentWeek(firstDayOfWeekIdx);
diff --git a/packages/desktop-client/src/components/reports/reports/CustomReport.tsx b/packages/desktop-client/src/components/reports/reports/CustomReport.tsx
index 12fec89e31..f2869b3e44 100644
--- a/packages/desktop-client/src/components/reports/reports/CustomReport.tsx
+++ b/packages/desktop-client/src/components/reports/reports/CustomReport.tsx
@@ -20,6 +20,7 @@ import { useFilters } from '../../../hooks/useFilters';
import { useLocalPref } from '../../../hooks/useLocalPref';
import { useNavigate } from '../../../hooks/useNavigate';
import { usePayees } from '../../../hooks/usePayees';
+import { useSyncedPref } from '../../../hooks/useSyncedPref';
import { useResponsive } from '../../../ResponsiveProvider';
import { theme, styles } from '../../../style';
import { AlignedText } from '../../common/AlignedText';
@@ -101,7 +102,7 @@ function useSelectedCategories(
export function CustomReport() {
const categories = useCategories();
const { isNarrowWidth } = useResponsive();
- const [_firstDayOfWeekIdx] = useLocalPref('firstDayOfWeekIdx');
+ const [_firstDayOfWeekIdx] = useSyncedPref('firstDayOfWeekIdx');
const firstDayOfWeekIdx = _firstDayOfWeekIdx || '0';
const [viewLegend = false, setViewLegendPref] =
diff --git a/packages/desktop-client/src/components/reports/reports/CustomReportListCards.tsx b/packages/desktop-client/src/components/reports/reports/CustomReportListCards.tsx
index bfc998b208..73edcca315 100644
--- a/packages/desktop-client/src/components/reports/reports/CustomReportListCards.tsx
+++ b/packages/desktop-client/src/components/reports/reports/CustomReportListCards.tsx
@@ -6,8 +6,8 @@ import { type CustomReportEntity } from 'loot-core/types/models/reports';
import { useAccounts } from '../../../hooks/useAccounts';
import { useCategories } from '../../../hooks/useCategories';
-import { useLocalPref } from '../../../hooks/useLocalPref';
import { usePayees } from '../../../hooks/usePayees';
+import { useSyncedPref } from '../../../hooks/useSyncedPref';
import { useResponsive } from '../../../ResponsiveProvider';
import { styles } from '../../../style/index';
import { theme } from '../../../style/theme';
@@ -47,7 +47,7 @@ export function CustomReportListCards({
const payees = usePayees();
const accounts = useAccounts();
const categories = useCategories();
- const [_firstDayOfWeekIdx] = useLocalPref('firstDayOfWeekIdx');
+ const [_firstDayOfWeekIdx] = useSyncedPref('firstDayOfWeekIdx');
const firstDayOfWeekIdx = _firstDayOfWeekIdx || '0';
const { isNarrowWidth } = useResponsive();
diff --git a/packages/desktop-client/src/components/reports/reports/GetCardData.tsx b/packages/desktop-client/src/components/reports/reports/GetCardData.tsx
index a18cb5a5bd..1221ee8d9a 100644
--- a/packages/desktop-client/src/components/reports/reports/GetCardData.tsx
+++ b/packages/desktop-client/src/components/reports/reports/GetCardData.tsx
@@ -7,7 +7,7 @@ import { type CategoryEntity } from 'loot-core/types/models/category';
import { type CategoryGroupEntity } from 'loot-core/types/models/category-group';
import { type PayeeEntity } from 'loot-core/types/models/payee';
import { type CustomReportEntity } from 'loot-core/types/models/reports';
-import { type LocalPrefs } from 'loot-core/types/prefs';
+import { type SyncedPrefs } from 'loot-core/types/prefs';
import { useResponsive } from '../../../ResponsiveProvider';
import { styles } from '../../../style/styles';
@@ -74,7 +74,7 @@ export function GetCardData({
accounts: AccountEntity[];
categories: { list: CategoryEntity[]; grouped: CategoryGroupEntity[] };
earliestTransaction: string;
- firstDayOfWeekIdx?: LocalPrefs['firstDayOfWeekIdx'];
+ firstDayOfWeekIdx?: SyncedPrefs['firstDayOfWeekIdx'];
showTooltip?: boolean;
}) {
const { isNarrowWidth } = useResponsive();
diff --git a/packages/desktop-client/src/components/reports/spreadsheets/custom-spreadsheet.ts b/packages/desktop-client/src/components/reports/spreadsheets/custom-spreadsheet.ts
index 194a3fd3ee..1afe00b3a4 100644
--- a/packages/desktop-client/src/components/reports/spreadsheets/custom-spreadsheet.ts
+++ b/packages/desktop-client/src/components/reports/spreadsheets/custom-spreadsheet.ts
@@ -18,7 +18,7 @@ import {
type GroupedEntity,
type IntervalEntity,
} from 'loot-core/src/types/models/reports';
-import { type LocalPrefs } from 'loot-core/types/prefs';
+import { type SyncedPrefs } from 'loot-core/types/prefs';
import {
categoryLists,
@@ -50,7 +50,7 @@ export type createCustomSpreadsheetProps = {
payees?: PayeeEntity[];
accounts?: AccountEntity[];
graphType?: string;
- firstDayOfWeekIdx?: LocalPrefs['firstDayOfWeekIdx'];
+ firstDayOfWeekIdx?: SyncedPrefs['firstDayOfWeekIdx'];
setDataCheck?: (value: boolean) => void;
};
diff --git a/packages/desktop-client/src/components/select/DateSelect.tsx b/packages/desktop-client/src/components/select/DateSelect.tsx
index badd799fa0..ce5bc0c40f 100644
--- a/packages/desktop-client/src/components/select/DateSelect.tsx
+++ b/packages/desktop-client/src/components/select/DateSelect.tsx
@@ -26,7 +26,7 @@ import {
} from 'loot-core/src/shared/months';
import { stringToInteger } from 'loot-core/src/shared/util';
-import { useLocalPref } from '../../hooks/useLocalPref';
+import { useSyncedPref } from '../../hooks/useSyncedPref';
import { theme } from '../../style';
import { Input } from '../common/Input';
import { Popover } from '../common/Popover';
@@ -232,7 +232,7 @@ export function DateSelect({
const [selectedValue, setSelectedValue] = useState(value);
const userSelectedValue = useRef(selectedValue);
- const [_firstDayOfWeekIdx] = useLocalPref('firstDayOfWeekIdx');
+ const [_firstDayOfWeekIdx] = useSyncedPref('firstDayOfWeekIdx');
const firstDayOfWeekIdx = _firstDayOfWeekIdx || '0';
useEffect(() => {
diff --git a/packages/desktop-client/src/components/settings/BudgetTypeSettings.tsx b/packages/desktop-client/src/components/settings/BudgetTypeSettings.tsx
index 9fbb26da28..ad5c3e746f 100644
--- a/packages/desktop-client/src/components/settings/BudgetTypeSettings.tsx
+++ b/packages/desktop-client/src/components/settings/BudgetTypeSettings.tsx
@@ -6,6 +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 { switchBudgetType } from '../budget/util';
import { ButtonWithLoading } from '../common/Button2';
import { Link } from '../common/Link';
@@ -15,7 +16,7 @@ import { Setting } from './UI';
export function BudgetTypeSettings() {
const dispatch = useDispatch();
- const [budgetType = 'rollover'] = useLocalPref('budgetType');
+ const [budgetType = 'rollover'] = useSyncedPref('budgetType');
const [loading, setLoading] = useState(false);
const currentMonth = monthUtils.currentMonth();
diff --git a/packages/desktop-client/src/components/settings/Encryption.tsx b/packages/desktop-client/src/components/settings/Encryption.tsx
index 1328af761c..941c9f4c19 100644
--- a/packages/desktop-client/src/components/settings/Encryption.tsx
+++ b/packages/desktop-client/src/components/settings/Encryption.tsx
@@ -4,7 +4,7 @@ import { useDispatch } from 'react-redux';
import { pushModal } from 'loot-core/client/actions';
-import { useLocalPref } from '../../hooks/useLocalPref';
+import { useMetadataPref } from '../../hooks/useMetadataPref';
import { theme } from '../../style';
import { Button } from '../common/Button2';
import { Link } from '../common/Link';
@@ -16,7 +16,7 @@ import { Setting } from './UI';
export function EncryptionSettings() {
const dispatch = useDispatch();
const serverURL = useServerURL();
- const [encryptKeyId] = useLocalPref('encryptKeyId');
+ const [encryptKeyId] = useMetadataPref('encryptKeyId');
const missingCryptoAPI = !(window.crypto && crypto.subtle);
diff --git a/packages/desktop-client/src/components/settings/Experimental.tsx b/packages/desktop-client/src/components/settings/Experimental.tsx
index f26f418326..fec5f04cab 100644
--- a/packages/desktop-client/src/components/settings/Experimental.tsx
+++ b/packages/desktop-client/src/components/settings/Experimental.tsx
@@ -3,7 +3,7 @@ import { type ReactNode, useState } from 'react';
import type { FeatureFlag } from 'loot-core/src/types/prefs';
import { useFeatureFlag } from '../../hooks/useFeatureFlag';
-import { useLocalPref } from '../../hooks/useLocalPref';
+import { useSyncedPref } from '../../hooks/useSyncedPref';
import { theme } from '../../style';
import { Link } from '../common/Link';
import { Text } from '../common/Text';
@@ -26,7 +26,7 @@ function FeatureToggle({
children,
}: FeatureToggleProps) {
const enabled = useFeatureFlag(flagName);
- const [_, setFlagPref] = useLocalPref(`flags.${flagName}`);
+ const [_, setFlagPref] = useSyncedPref(`flags.${flagName}`);
return (
<label style={{ display: 'flex' }}>
@@ -57,7 +57,7 @@ function FeatureToggle({
}
function ReportBudgetFeature() {
- const [budgetType = 'rollover'] = useLocalPref('budgetType');
+ const [budgetType = 'rollover'] = useSyncedPref('budgetType');
const enabled = useFeatureFlag('reportBudget');
const blockToggleOff = budgetType === 'report' && enabled;
return (
diff --git a/packages/desktop-client/src/components/settings/Export.tsx b/packages/desktop-client/src/components/settings/Export.tsx
index 7a9179becf..9b3b8ba30b 100644
--- a/packages/desktop-client/src/components/settings/Export.tsx
+++ b/packages/desktop-client/src/components/settings/Export.tsx
@@ -4,7 +4,7 @@ import { format } from 'date-fns';
import { send } from 'loot-core/src/platform/client/fetch';
-import { useLocalPref } from '../../hooks/useLocalPref';
+import { useMetadataPref } from '../../hooks/useMetadataPref';
import { theme } from '../../style';
import { Block } from '../common/Block';
import { ButtonWithLoading } from '../common/Button2';
@@ -15,8 +15,8 @@ import { Setting } from './UI';
export function ExportBudget() {
const [isLoading, setIsLoading] = useState(false);
const [error, setError] = useState<string | null>(null);
- const [budgetName] = useLocalPref('budgetName');
- const [encryptKeyId] = useLocalPref('encryptKeyId');
+ const [budgetName] = useMetadataPref('budgetName');
+ const [encryptKeyId] = useMetadataPref('encryptKeyId');
async function onExport() {
setIsLoading(true);
diff --git a/packages/desktop-client/src/components/settings/Format.tsx b/packages/desktop-client/src/components/settings/Format.tsx
index b4d4e7bdd3..ebde12163c 100644
--- a/packages/desktop-client/src/components/settings/Format.tsx
+++ b/packages/desktop-client/src/components/settings/Format.tsx
@@ -2,10 +2,10 @@
import React, { type ReactNode } from 'react';
import { numberFormats } from 'loot-core/src/shared/util';
-import { type LocalPrefs } from 'loot-core/src/types/prefs';
+import { type SyncedPrefs } from 'loot-core/src/types/prefs';
import { useDateFormat } from '../../hooks/useDateFormat';
-import { useLocalPref } from '../../hooks/useLocalPref';
+import { useSyncedPref } from '../../hooks/useSyncedPref';
import { type CSSProperties, theme } from '../../style';
import { tokens } from '../../tokens';
import { Select } from '../common/Select';
@@ -18,7 +18,7 @@ import { Setting } from './UI';
// Follows Pikaday 'firstDay' numbering
// https://github.com/Pikaday/Pikaday
-const daysOfWeek: { value: LocalPrefs['firstDayOfWeekIdx']; label: string }[] =
+const daysOfWeek: { value: SyncedPrefs['firstDayOfWeekIdx']; label: string }[] =
[
{ value: '0', label: 'Sunday' },
{ value: '1', label: 'Monday' },
@@ -29,7 +29,7 @@ const daysOfWeek: { value: LocalPrefs['firstDayOfWeekIdx']; label: string }[] =
{ value: '6', label: 'Saturday' },
];
-const dateFormats: { value: LocalPrefs['dateFormat']; label: string }[] = [
+const dateFormats: { value: SyncedPrefs['dateFormat']; label: string }[] = [
{ value: 'MM/dd/yyyy', label: 'MM/DD/YYYY' },
{ value: 'dd/MM/yyyy', label: 'DD/MM/YYYY' },
{ value: 'yyyy-MM-dd', label: 'YYYY-MM-DD' },
@@ -56,14 +56,14 @@ function Column({ title, children }: { title: string; children: ReactNode }) {
export function FormatSettings() {
const sidebar = useSidebar();
const [_firstDayOfWeekIdx, setFirstDayOfWeekIdxPref] =
- useLocalPref('firstDayOfWeekIdx'); // Sunday;
+ useSyncedPref('firstDayOfWeekIdx'); // Sunday;
const firstDayOfWeekIdx = _firstDayOfWeekIdx || '0';
const dateFormat = useDateFormat() || 'MM/dd/yyyy';
- const [, setDateFormatPref] = useLocalPref('dateFormat');
- const [_numberFormat, setNumberFormatPref] = useLocalPref('numberFormat');
+ const [, setDateFormatPref] = useSyncedPref('dateFormat');
+ const [_numberFormat, setNumberFormatPref] = useSyncedPref('numberFormat');
const numberFormat = _numberFormat || 'comma-dot';
const [hideFraction = false, setHideFractionPref] =
- useLocalPref('hideFraction');
+ useSyncedPref('hideFraction');
const selectButtonStyle: CSSProperties = {
':hover': {
diff --git a/packages/desktop-client/src/components/settings/Reset.tsx b/packages/desktop-client/src/components/settings/Reset.tsx
index 9ceb5883a7..7df45afd1b 100644
--- a/packages/desktop-client/src/components/settings/Reset.tsx
+++ b/packages/desktop-client/src/components/settings/Reset.tsx
@@ -3,7 +3,7 @@ import React, { useState } from 'react';
import { send } from 'loot-core/src/platform/client/fetch';
import { useActions } from '../../hooks/useActions';
-import { useLocalPref } from '../../hooks/useLocalPref';
+import { useMetadataPref } from '../../hooks/useMetadataPref';
import { ButtonWithLoading } from '../common/Button2';
import { Text } from '../common/Text';
@@ -38,7 +38,7 @@ export function ResetCache() {
}
export function ResetSync() {
- const [groupId] = useLocalPref('groupId');
+ const [groupId] = useMetadataPref('groupId');
const isEnabled = !!groupId;
const { resetSync } = useActions();
diff --git a/packages/desktop-client/src/components/settings/index.tsx b/packages/desktop-client/src/components/settings/index.tsx
index f9419332ee..61c1b19145 100644
--- a/packages/desktop-client/src/components/settings/index.tsx
+++ b/packages/desktop-client/src/components/settings/index.tsx
@@ -9,7 +9,7 @@ import { useActions } from '../../hooks/useActions';
import { useFeatureFlag } from '../../hooks/useFeatureFlag';
import { useGlobalPref } from '../../hooks/useGlobalPref';
import { useLatestVersion, useIsOutdated } from '../../hooks/useLatestVersion';
-import { useLocalPref } from '../../hooks/useLocalPref';
+import { useMetadataPref } from '../../hooks/useMetadataPref';
import { useSetThemeColor } from '../../hooks/useSetThemeColor';
import { useResponsive } from '../../ResponsiveProvider';
import { theme } from '../../style';
@@ -94,8 +94,8 @@ function IDName({ children }: { children: ReactNode }) {
}
function AdvancedAbout() {
- const [budgetId] = useLocalPref('id');
- const [groupId] = useLocalPref('groupId');
+ const [budgetId] = useMetadataPref('id');
+ const [groupId] = useMetadataPref('groupId');
return (
<Setting>
@@ -124,7 +124,7 @@ function AdvancedAbout() {
export function Settings() {
const [floatingSidebar] = useGlobalPref('floatingSidebar');
- const [budgetName] = useLocalPref('budgetName');
+ const [budgetName] = useMetadataPref('budgetName');
const { loadPrefs, closeBudget } = useActions();
diff --git a/packages/desktop-client/src/components/sidebar/Sidebar.tsx b/packages/desktop-client/src/components/sidebar/Sidebar.tsx
index 4f76a71ea7..687410eeef 100644
--- a/packages/desktop-client/src/components/sidebar/Sidebar.tsx
+++ b/packages/desktop-client/src/components/sidebar/Sidebar.tsx
@@ -13,6 +13,7 @@ import * as Platform from 'loot-core/src/client/platform';
import { useAccounts } from '../../hooks/useAccounts';
import { useGlobalPref } from '../../hooks/useGlobalPref';
import { useLocalPref } from '../../hooks/useLocalPref';
+import { useMetadataPref } from '../../hooks/useMetadataPref';
import { useNavigate } from '../../hooks/useNavigate';
import { useResizeObserver } from '../../hooks/useResizeObserver';
import { SvgExpandArrow } from '../../icons/v0';
@@ -178,7 +179,7 @@ export function Sidebar() {
function EditableBudgetName() {
const dispatch = useDispatch();
const navigate = useNavigate();
- const [budgetName, setBudgetNamePref] = useLocalPref('budgetName');
+ const [budgetName, setBudgetNamePref] = useMetadataPref('budgetName');
const [editing, setEditing] = useState(false);
const [menuOpen, setMenuOpen] = useState(false);
const triggerRef = useRef(null);
diff --git a/packages/desktop-client/src/components/util/AmountInput.tsx b/packages/desktop-client/src/components/util/AmountInput.tsx
index af947f6229..b3f18b17ea 100644
--- a/packages/desktop-client/src/components/util/AmountInput.tsx
+++ b/packages/desktop-client/src/components/util/AmountInput.tsx
@@ -11,8 +11,8 @@ import React, {
import { evalArithmetic } from 'loot-core/src/shared/arithmetic';
import { amountToInteger, appendDecimals } from 'loot-core/src/shared/util';
-import { useLocalPref } from '../../hooks/useLocalPref';
import { useMergedRefs } from '../../hooks/useMergedRefs';
+import { useSyncedPref } from '../../hooks/useSyncedPref';
import { SvgAdd, SvgSubtract } from '../../icons/v1';
import { type CSSProperties, theme } from '../../style';
import { Button } from '../common/Button2';
@@ -63,7 +63,7 @@ export function AmountInput({
const buttonRef = useRef();
const ref = useRef<HTMLInputElement>(null);
const mergedRef = useMergedRefs<HTMLInputElement>(inputRef, ref);
- const [hideFraction = false] = useLocalPref('hideFraction');
+ const [hideFraction = false] = useSyncedPref('hideFraction');
useEffect(() => {
if (focused) {
diff --git a/packages/desktop-client/src/hooks/useMetadataPref.ts b/packages/desktop-client/src/hooks/useMetadataPref.ts
new file mode 100644
index 0000000000..32265fee18
--- /dev/null
+++ b/packages/desktop-client/src/hooks/useMetadataPref.ts
@@ -0,0 +1,15 @@
+import { type MetadataPrefs } from 'loot-core/src/types/prefs';
+
+import { useLocalPref } from './useLocalPref';
+
+type SetMetadataPrefAction<K extends keyof MetadataPrefs> = (
+ value: MetadataPrefs[K],
+) => void;
+
+export function useMetadataPref<K extends keyof MetadataPrefs>(
+ prefName: K,
+): [MetadataPrefs[K], SetMetadataPrefAction<K>] {
+ // TODO: implement logic for fetching the pref exclusively from the
+ // metadata.json file (in follow-up PR)
+ return useLocalPref(prefName);
+}
diff --git a/packages/desktop-client/src/hooks/useSyncedPref.ts b/packages/desktop-client/src/hooks/useSyncedPref.ts
new file mode 100644
index 0000000000..e9e8572300
--- /dev/null
+++ b/packages/desktop-client/src/hooks/useSyncedPref.ts
@@ -0,0 +1,15 @@
+import { type SyncedPrefs } from 'loot-core/src/types/prefs';
+
+import { useLocalPref } from './useLocalPref';
+
+type SetSyncedPrefAction<K extends keyof SyncedPrefs> = (
+ value: SyncedPrefs[K],
+) => void;
+
+export function useSyncedPref<K extends keyof SyncedPrefs>(
+ prefName: K,
+): [SyncedPrefs[K], SetSyncedPrefAction<K>] {
+ // TODO: implement logic for fetching the pref exclusively from the
+ // database (in follow-up PR)
+ return useLocalPref(prefName);
+}
diff --git a/packages/loot-core/src/client/queries.ts b/packages/loot-core/src/client/queries.ts
index ac37e57dea..fef175374e 100644
--- a/packages/loot-core/src/client/queries.ts
+++ b/packages/loot-core/src/client/queries.ts
@@ -17,7 +17,7 @@ import {
import { q, type Query } from '../shared/query';
import { currencyToAmount, amountToInteger } from '../shared/util';
import { type CategoryEntity, type AccountEntity } from '../types/models';
-import { type LocalPrefs } from '../types/prefs';
+import { type SyncedPrefs } from '../types/prefs';
type BudgetType<SheetName extends SheetNames> = Record<
string,
@@ -77,7 +77,7 @@ export function makeTransactionsQuery(accountId: string) {
export function makeTransactionSearchQuery(
currentQuery: Query,
search: string,
- dateFormat: LocalPrefs['dateFormat'],
+ dateFormat: SyncedPrefs['dateFormat'],
) {
const amount = currencyToAmount(search);
diff --git a/packages/loot-core/src/client/state-types/prefs.d.ts b/packages/loot-core/src/client/state-types/prefs.d.ts
index dd2e8b4e4f..275ee55322 100644
--- a/packages/loot-core/src/client/state-types/prefs.d.ts
+++ b/packages/loot-core/src/client/state-types/prefs.d.ts
@@ -1,20 +1,25 @@
-import type { LocalPrefs, GlobalPrefs } from '../../types/prefs';
+import type {
+ GlobalPrefs,
+ LocalPrefs,
+ MetadataPrefs,
+ SyncedPrefs,
+} from '../../types/prefs';
import type * as constants from '../constants';
export type PrefsState = {
- local: LocalPrefs;
+ local: LocalPrefs & MetadataPrefs & SyncedPrefs;
global: GlobalPrefs;
};
export type SetPrefsAction = {
type: typeof constants.SET_PREFS;
- prefs: LocalPrefs;
+ prefs: LocalPrefs & MetadataPrefs & SyncedPrefs;
globalPrefs: GlobalPrefs;
};
export type MergeLocalPrefsAction = {
type: typeof constants.MERGE_LOCAL_PREFS;
- prefs: LocalPrefs;
+ prefs: LocalPrefs & MetadataPrefs & SyncedPrefs;
};
export type MergeGlobalPrefsAction = {
diff --git a/packages/loot-core/src/server/prefs.ts b/packages/loot-core/src/server/prefs.ts
index c275040924..1df9f03416 100644
--- a/packages/loot-core/src/server/prefs.ts
+++ b/packages/loot-core/src/server/prefs.ts
@@ -2,14 +2,16 @@
import { Timestamp } from '@actual-app/crdt';
import * as fs from '../platform/server/fs';
-import type { LocalPrefs } from '../types/prefs';
+import type { MetadataPrefs, SyncedPrefs } 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: LocalPrefs = null;
+let prefs: MetadataPrefs = null;
export async function loadPrefs(id?: string): Promise<LocalPrefs> {
if (process.env.NODE_ENV === 'test' && !id) {
@@ -89,6 +91,6 @@ export function getPrefs(): LocalPrefs {
return prefs;
}
-export function getDefaultPrefs(id: string, budgetName: string): LocalPrefs {
+export function getDefaultPrefs(id: string, budgetName: string) {
return { id, budgetName };
}
diff --git a/packages/loot-core/src/shared/months.ts b/packages/loot-core/src/shared/months.ts
index 1ebbb97599..0c0f5793f8 100644
--- a/packages/loot-core/src/shared/months.ts
+++ b/packages/loot-core/src/shared/months.ts
@@ -3,7 +3,7 @@ import * as d from 'date-fns';
import memoizeOne from 'memoize-one';
import * as Platform from '../client/platform';
-import { type LocalPrefs } from '../types/prefs';
+import { type SyncedPrefs } from '../types/prefs';
type DateLike = string | Date;
type Day = 0 | 1 | 2 | 3 | 4 | 5 | 6;
@@ -91,7 +91,7 @@ export function monthFromDate(date: DateLike): string {
export function weekFromDate(
date: DateLike,
- firstDayOfWeekIdx: LocalPrefs['firstDayOfWeekIdx'],
+ firstDayOfWeekIdx: SyncedPrefs['firstDayOfWeekIdx'],
): string {
const converted = parseInt(firstDayOfWeekIdx || '0') as Day;
return d.format(
@@ -113,7 +113,7 @@ export function currentMonth(): string {
}
export function currentWeek(
- firstDayOfWeekIdx?: LocalPrefs['firstDayOfWeekIdx'],
+ firstDayOfWeekIdx?: SyncedPrefs['firstDayOfWeekIdx'],
): string {
if (global.IS_TESTING || Platform.isPlaywright) {
return global.currentWeek || '2017-01-01';
@@ -257,7 +257,7 @@ export function _weekRange(
start: DateLike,
end: DateLike,
inclusive = false,
- firstDayOfWeekIdx?: LocalPrefs['firstDayOfWeekIdx'],
+ firstDayOfWeekIdx?: SyncedPrefs['firstDayOfWeekIdx'],
): string[] {
const weeks: string[] = [];
let week = weekFromDate(start, firstDayOfWeekIdx);
@@ -277,7 +277,7 @@ export function _weekRange(
export function weekRangeInclusive(
start: DateLike,
end: DateLike,
- firstDayOfWeekIdx?: LocalPrefs['firstDayOfWeekIdx'],
+ firstDayOfWeekIdx?: SyncedPrefs['firstDayOfWeekIdx'],
): string[] {
return _weekRange(start, end, true, firstDayOfWeekIdx);
}
@@ -364,7 +364,7 @@ export function getMonthEnd(day: string): string {
export function getWeekEnd(
date: DateLike,
- firstDayOfWeekIdx?: LocalPrefs['firstDayOfWeekIdx'],
+ firstDayOfWeekIdx?: SyncedPrefs['firstDayOfWeekIdx'],
): string {
const converted = parseInt(firstDayOfWeekIdx || '0') as Day;
return d.format(
diff --git a/packages/loot-core/src/types/prefs.d.ts b/packages/loot-core/src/types/prefs.d.ts
index 2a578a845b..ee5aa40ec6 100644
--- a/packages/loot-core/src/types/prefs.d.ts
+++ b/packages/loot-core/src/types/prefs.d.ts
@@ -9,7 +9,10 @@ export type FeatureFlag =
| 'simpleFinSync'
| 'iterableTopologicalSort';
-export type LocalPrefs = Partial<
+/**
+ * Cross-device preferences. These sync across devices when they are changed.
+ */
+export type SyncedPrefs = Partial<
{
firstDayOfWeekIdx: `${0 | 1 | 2 | 3 | 4 | 5 | 6}`;
dateFormat:
@@ -21,16 +24,9 @@ export type LocalPrefs = Partial<
numberFormat: (typeof numberFormats)[number]['value'];
hideFraction: boolean;
isPrivacyEnabled: boolean;
- budgetName: string;
- 'ui.showClosedAccounts': boolean;
- 'expand-splits': boolean;
[key: `show-extra-balances-${string}`]: boolean;
[key: `hide-cleared-${string}`]: boolean;
[key: `hide-reconciled-${string}`]: boolean;
- 'budget.collapsed': string[];
- 'budget.summaryCollapsed': boolean;
- 'budget.showHiddenCategories': boolean;
- 'budget.startMonth': string;
// TODO: pull from src/components/modals/ImportTransactions.js
[key: `parse-date-${string}-${'csv' | 'qif'}`]: string;
[key: `csv-mappings-${string}`]: string;
@@ -38,17 +34,42 @@ export type LocalPrefs = Partial<
[key: `csv-has-header-${string}`]: boolean;
[key: `ofx-fallback-missing-payee-${string}`]: boolean;
[key: `flip-amount-${string}-${'csv' | 'qif'}`]: boolean;
- 'flags.updateNotificationShownForVersion': string;
- id: string;
- lastUploaded: string;
- cloudFileId: string;
- groupId: string;
budgetType: 'report' | 'rollover';
- encryptKeyId: string;
- lastSyncedTimestamp: string;
- userId: string;
- resetClock: boolean;
- lastScheduleRun: string;
+ } & Record<`flags.${FeatureFlag}`, boolean>
+>;
+
+/**
+ * Preferences that are stored in the `metadata.json` file along with the
+ * core database.
+ */
+export type MetadataPrefs = Partial<{
+ budgetName: string;
+ id: string;
+ lastUploaded: string;
+ cloudFileId: string;
+ groupId: string;
+ encryptKeyId: string;
+ lastSyncedTimestamp: string;
+ resetClock: boolean;
+ lastScheduleRun: string;
+ userId: string; // TODO: delete this (unused)
+}>;
+
+/**
+ * Local preferences applicable to a single device. Stored in local storage.
+ * TODO: eventually `LocalPrefs` type should not use `SyncedPrefs` or `MetadataPrefs`;
+ * this is only a stop-gap solution.
+ */
+export type LocalPrefs = SyncedPrefs &
+ MetadataPrefs &
+ Partial<{
+ 'ui.showClosedAccounts': boolean;
+ 'expand-splits': boolean;
+ 'budget.collapsed': string[];
+ 'budget.summaryCollapsed': boolean;
+ 'budget.showHiddenCategories': boolean;
+ 'budget.startMonth': string;
+ 'flags.updateNotificationShownForVersion': string;
reportsViewLegend: boolean;
reportsViewSummary: boolean;
reportsViewLabel: boolean;
@@ -57,8 +78,7 @@ export type LocalPrefs = Partial<
spendingReportCompare: spendingReportTimeType;
sidebarWidth: number;
'mobile.showSpentColumn': boolean;
- } & Record<`flags.${FeatureFlag}`, boolean>
->;
+ }>;
export type Theme = 'light' | 'dark' | 'auto' | 'midnight' | 'development';
export type GlobalPrefs = Partial<{
diff --git a/upcoming-release-notes/3219.md b/upcoming-release-notes/3219.md
index 4c73e3a5fc..89d32e4f35 100644
--- a/upcoming-release-notes/3219.md
+++ b/upcoming-release-notes/3219.md
@@ -3,4 +3,4 @@ category: Maintenance
authors: [MikesGlitch]
---
-Makinig Server logs visible in devtools on Electron
+Making Server logs visible in devtools on Electron
diff --git a/upcoming-release-notes/3236.md b/upcoming-release-notes/3236.md
new file mode 100644
index 0000000000..4df9a67999
--- /dev/null
+++ b/upcoming-release-notes/3236.md
@@ -0,0 +1,6 @@
+---
+category: Maintenance
+authors: [Matissjanis]
+---
+
+Separate `LocalPrefs` interface out into `LocalPrefs` (eventually using local storage), `SyncedPrefs` (eventually using the cross-device database) and `MetadataPrefs` (eventually using the `metadata.json` file).