Skip to content

Commit

Permalink
♻️ (synced-prefs) moving budgetType pref back to MetadataPrefs (#3410)
Browse files Browse the repository at this point in the history
* ♻️ (synced-prefs) moving budgetType pref back to MetadataPrefs (temporary)

* Release notes
  • Loading branch information
MatissJanis authored Sep 10, 2024
1 parent 8c8c248 commit b2d7b65
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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'
Expand Down
4 changes: 2 additions & 2 deletions packages/desktop-client/src/components/budget/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions packages/desktop-client/src/components/budget/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -141,7 +141,7 @@ export function getScrollbarWidth() {
}

export async function prewarmMonth(
budgetType: SyncedPrefs['budgetType'],
budgetType: MetadataPrefs['budgetType'],
spreadsheet: ReturnType<typeof useSpreadsheet>,
month: string,
) {
Expand All @@ -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,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 (
Expand Down
10 changes: 4 additions & 6 deletions packages/loot-core/src/server/prefs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -87,7 +85,7 @@ export function unloadPrefs(): void {
prefs = null;
}

export function getPrefs(): LocalPrefs {
export function getPrefs(): MetadataPrefs {
return prefs;
}

Expand Down
3 changes: 2 additions & 1 deletion packages/loot-core/src/types/prefs.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
>
Expand All @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/3410.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Maintenance
authors: [MatissJanis]
---

SyncedPrefs: move `budgetType` back to metadata prefs.

0 comments on commit b2d7b65

Please sign in to comment.