Skip to content

Commit

Permalink
♻️ (synced-prefs) refactor ImportedTransactions usage of prefs (#3408)
Browse files Browse the repository at this point in the history
  • Loading branch information
MatissJanis authored Sep 9, 2024
1 parent 8498d7f commit 7231959
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {

import { useActions } from '../../hooks/useActions';
import { useDateFormat } from '../../hooks/useDateFormat';
import { useLocalPrefs } from '../../hooks/useLocalPrefs';
import { useSyncedPrefs } from '../../hooks/useSyncedPrefs';
import { SvgDownAndRightArrow } from '../../icons/v2';
import { theme, styles } from '../../style';
import { Button, ButtonWithLoading } from '../common/Button2';
Expand Down Expand Up @@ -840,13 +840,12 @@ function FieldMappings({

export function ImportTransactions({ options }) {
const dateFormat = useDateFormat() || 'MM/dd/yyyy';
const prefs = useLocalPrefs();
const [prefs, savePrefs] = useSyncedPrefs();
const {
parseTransactions,
importTransactions,
importPreviewTransactions,
getPayees,
savePrefs,
} = useActions();

const [multiplierAmount, setMultiplierAmount] = useState('');
Expand Down
22 changes: 22 additions & 0 deletions packages/desktop-client/src/hooks/useSyncedPrefs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { useCallback } from 'react';
import { useDispatch } from 'react-redux';

import { savePrefs } from 'loot-core/client/actions';
import { type SyncedPrefs } from 'loot-core/src/types/prefs';

import { useLocalPrefs } from './useLocalPrefs';

type SetSyncedPrefsAction = (value: Partial<SyncedPrefs>) => void;

export function useSyncedPrefs(): [SyncedPrefs, SetSyncedPrefsAction] {
// TODO: implement real logic (follow-up PR)
const dispatch = useDispatch();
const setPrefs = useCallback<SetSyncedPrefsAction>(
newPrefs => {
dispatch(savePrefs(newPrefs));
},
[dispatch],
);

return [useLocalPrefs(), setPrefs];
}
6 changes: 6 additions & 0 deletions upcoming-release-notes/3408.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Maintenance
authors: [MatissJanis]
---

SyncedPrefs: refactor `ImportTransactions` usage of prefs to use a common hook.

0 comments on commit 7231959

Please sign in to comment.