Skip to content

Commit

Permalink
Prefs slice
Browse files Browse the repository at this point in the history
  • Loading branch information
joel-jeremy committed Jan 17, 2025
1 parent b58a227 commit ece4d30
Show file tree
Hide file tree
Showing 19 changed files with 204 additions and 168 deletions.
3 changes: 2 additions & 1 deletion packages/desktop-client/src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ import { HotkeysProvider } from 'react-hotkeys-hook';
import { useTranslation } from 'react-i18next';
import { BrowserRouter } from 'react-router-dom';

import { loadGlobalPrefs, signOut } from 'loot-core/client/actions';
import { signOut } from 'loot-core/client/actions';
import { setAppState, sync } from 'loot-core/client/app/appSlice';
import { closeBudget, loadBudget } from 'loot-core/client/budgets/budgetsSlice';
import { addNotification } from 'loot-core/client/notifications/notificationsSlice';
import { loadGlobalPrefs } from 'loot-core/client/prefs/prefsSlice';
import { SpreadsheetProvider } from 'loot-core/client/SpreadsheetProvider';
import * as Platform from 'loot-core/src/client/platform';
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import { useTranslation, Trans } from 'react-i18next';

import { css } from '@emotion/css';

import { loadGlobalPrefs } from 'loot-core/client/actions';
import { sync } from 'loot-core/client/app/appSlice';
import { loadAllFiles } from 'loot-core/client/budgets/budgetsSlice';
import { type Modal as ModalType } from 'loot-core/client/modals/modalsSlice';
import { loadGlobalPrefs } from 'loot-core/client/prefs/prefsSlice';
import { send } from 'loot-core/src/platform/client/fetch';
import { getCreateKeyError } from 'loot-core/src/shared/errors';

Expand Down
2 changes: 1 addition & 1 deletion packages/desktop-client/src/components/settings/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { useTranslation, Trans } from 'react-i18next';

import { css } from '@emotion/css';

import { loadPrefs } from 'loot-core/client/actions';
import { closeBudget } from 'loot-core/client/budgets/budgetsSlice';
import { loadPrefs } from 'loot-core/client/prefs/prefsSlice';
import { isElectron } from 'loot-core/shared/environment';
import { listen } from 'loot-core/src/platform/client/fetch';

Expand Down
2 changes: 1 addition & 1 deletion packages/desktop-client/src/global-events.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// @ts-strict-ignore
import { loadPrefs } from 'loot-core/client/actions';
import { setAppState } from 'loot-core/client/app/appSlice';
import { closeBudgetUI } from 'loot-core/client/budgets/budgetsSlice';
import {
Expand All @@ -11,6 +10,7 @@ import {
addGenericErrorNotification,
addNotification,
} from 'loot-core/client/notifications/notificationsSlice';
import { loadPrefs } from 'loot-core/client/prefs/prefsSlice';
import {
getAccounts,
getCategories,
Expand Down
10 changes: 5 additions & 5 deletions packages/desktop-client/src/hooks/useGlobalPref.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useCallback } from 'react';

import { saveGlobalPrefs } from 'loot-core/src/client/actions';
import { saveGlobalPrefs } from 'loot-core/client/prefs/prefsSlice';
import { type GlobalPrefs } from 'loot-core/src/types/prefs';

import { useSelector, useDispatch } from '../redux';
Expand All @@ -17,12 +17,12 @@ export function useGlobalPref<K extends keyof GlobalPrefs>(
const setGlobalPref = useCallback<SetGlobalPrefAction<K>>(
value => {
dispatch(
saveGlobalPrefs(
{
saveGlobalPrefs({
prefs: {
[prefName]: value,
} as GlobalPrefs,
},
onSaveGlobalPrefs,
),
}),
);
},
[prefName, dispatch, onSaveGlobalPrefs],
Expand Down
4 changes: 2 additions & 2 deletions packages/desktop-client/src/hooks/useMetadataPref.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useCallback } from 'react';

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

import { useSelector, useDispatch } from '../redux';
Expand All @@ -15,7 +15,7 @@ export function useMetadataPref<K extends keyof MetadataPrefs>(
const dispatch = useDispatch();
const setLocalPref = useCallback<SetMetadataPrefAction<K>>(
value => {
dispatch(savePrefs({ [prefName]: value }));
dispatch(savePrefs({ prefs: { [prefName]: value } }));
},
[prefName, dispatch],
);
Expand Down
4 changes: 2 additions & 2 deletions packages/desktop-client/src/hooks/useSyncedPref.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useCallback } from 'react';

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

import { useSelector, useDispatch } from '../redux';
Expand All @@ -15,7 +15,7 @@ export function useSyncedPref<K extends keyof SyncedPrefs>(
const dispatch = useDispatch();
const setPref = useCallback<SetSyncedPrefAction<K>>(
value => {
dispatch(saveSyncedPrefs({ [prefName]: value }));
dispatch(saveSyncedPrefs({ prefs: { [prefName]: value } }));
},
[prefName, dispatch],
);
Expand Down
4 changes: 2 additions & 2 deletions packages/desktop-client/src/hooks/useSyncedPrefs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useCallback } from 'react';

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

import { useSelector, useDispatch } from '../redux';
Expand All @@ -12,7 +12,7 @@ export function useSyncedPrefs(): [SyncedPrefs, SetSyncedPrefsAction] {
const dispatch = useDispatch();
const setPrefs = useCallback<SetSyncedPrefsAction>(
newValue => {
dispatch(saveSyncedPrefs(newValue));
dispatch(saveSyncedPrefs({ prefs: newValue }));
},
[dispatch],
);
Expand Down
2 changes: 2 additions & 0 deletions packages/desktop-client/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import * as appSlice from 'loot-core/src/client/app/appSlice';
import * as budgetsSlice from 'loot-core/src/client/budgets/budgetsSlice';
import * as modalsSlice from 'loot-core/src/client/modals/modalsSlice';
import * as notificationsSlice from 'loot-core/src/client/notifications/notificationsSlice';
import * as prefsSlice from 'loot-core/src/client/prefs/prefsSlice';
import * as queriesSlice from 'loot-core/src/client/queries/queriesSlice';
import { runQuery } from 'loot-core/src/client/query-helpers';
import { store } from 'loot-core/src/client/store';
Expand All @@ -43,6 +44,7 @@ const boundActions = bindActionCreators(
...budgetsSlice.actions,
...modalsSlice.actions,
...notificationsSlice.actions,
...prefsSlice.actions,
...queriesSlice.actions,
},
store.dispatch,
Expand Down
1 change: 0 additions & 1 deletion packages/loot-core/src/client/actions/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export * from './prefs';
export * from './user';
103 changes: 0 additions & 103 deletions packages/loot-core/src/client/actions/prefs.ts

This file was deleted.

3 changes: 1 addition & 2 deletions packages/loot-core/src/client/actions/user.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { send } from '../../platform/client/fetch';
import { closeBudget, loadAllFiles } from '../budgets/budgetsSlice';
import * as constants from '../constants';
import { loadGlobalPrefs } from '../prefs/prefsSlice';
import { type AppDispatch } from '../store';

import { loadGlobalPrefs } from './prefs';

export function getUserData() {
return async (dispatch: AppDispatch) => {
const data = await send('subscribe-get-user');
Expand Down
2 changes: 1 addition & 1 deletion packages/loot-core/src/client/budgets/budgetsSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import { getDownloadError, getSyncError } from '../../shared/errors';
import { type Budget } from '../../types/budget';
import { type File } from '../../types/file';
import { type Handlers } from '../../types/handlers';
import { loadGlobalPrefs, loadPrefs } from '../actions';
import { setAppState } from '../app/appSlice';
import * as constants from '../constants';
import { closeModal, pushModal } from '../modals/modalsSlice';
import { loadGlobalPrefs, loadPrefs } from '../prefs/prefsSlice';
import { createAppAsyncThunk } from '../redux';

const sliceName = 'budgets';
Expand Down
Loading

0 comments on commit ece4d30

Please sign in to comment.