A local-first personal finance app
Move loot-core/client/store and loot-core/client/redux code over to desktop-client package (#4827)
Joel Jeremy Marquezc389c6c637b8
diff --git a/packages/desktop-client/src/accounts/accountsSlice.ts b/packages/desktop-client/src/accounts/accountsSlice.tsindex a76fd9309b..178770d0a7 100644--- a/packages/desktop-client/src/accounts/accountsSlice.ts+++ b/packages/desktop-client/src/accounts/accountsSlice.ts@@ -1,7 +1,5 @@import { createSlice, type PayloadAction } from '@reduxjs/toolkit';-import { createAppAsyncThunk } from 'loot-core/client/redux';-import { type AppDispatch } from 'loot-core/client/store';import { send } from 'loot-core/platform/client/fetch';import { type SyncResponseWithErrors } from 'loot-core/server/accounts/app';import {@@ -19,6 +17,8 @@ import {getPayees,setNewTransactions,} from '../queries/queriesSlice';+import { createAppAsyncThunk } from '../redux';+import { type AppDispatch } from '../redux/store';const sliceName = 'account';diff --git a/packages/desktop-client/src/app/appSlice.ts b/packages/desktop-client/src/app/appSlice.tsindex 39a7cc98b6..c3dd3311f0 100644--- a/packages/desktop-client/src/app/appSlice.ts+++ b/packages/desktop-client/src/app/appSlice.ts@@ -4,7 +4,6 @@ import {type PayloadAction,} from '@reduxjs/toolkit';-import { createAppAsyncThunk } from 'loot-core/client/redux';import { send } from 'loot-core/platform/client/fetch';import { getUploadError } from 'loot-core/shared/errors';import { type AccountEntity } from 'loot-core/types/models';@@ -13,6 +12,7 @@ import { type AtLeastOne } from 'loot-core/types/util';import { syncAccounts } from '../accounts/accountsSlice';import { pushModal } from '../modals/modalsSlice';import { loadPrefs } from '../prefs/prefsSlice';+import { createAppAsyncThunk } from '../redux';const sliceName = 'app';diff --git a/packages/desktop-client/src/budgets/budgetsSlice.ts b/packages/desktop-client/src/budgets/budgetsSlice.tsindex 7a2846e152..e89e3b3f11 100644--- a/packages/desktop-client/src/budgets/budgetsSlice.ts+++ b/packages/desktop-client/src/budgets/budgetsSlice.ts@@ -1,7 +1,6 @@import { createSlice, type PayloadAction } from '@reduxjs/toolkit';import { t } from 'i18next';-import { createAppAsyncThunk } from 'loot-core/client/redux';import { send } from 'loot-core/platform/client/fetch';import { type RemoteFile } from 'loot-core/server/cloud-storage';import { getDownloadError, getSyncError } from 'loot-core/shared/errors';@@ -12,6 +11,7 @@ import { type Handlers } from 'loot-core/types/handlers';import { resetApp, setAppState } from '../app/appSlice';import { closeModal, pushModal } from '../modals/modalsSlice';import { loadGlobalPrefs, loadPrefs } from '../prefs/prefsSlice';+import { createAppAsyncThunk } from '../redux';import { signOut } from '../users/usersSlice';const sliceName = 'budgets';diff --git a/packages/desktop-client/src/components/accounts/Account.tsx b/packages/desktop-client/src/components/accounts/Account.tsxindex 62d215c406..c55f6ac18d 100644--- a/packages/desktop-client/src/components/accounts/Account.tsx+++ b/packages/desktop-client/src/components/accounts/Account.tsx@@ -27,7 +27,6 @@ import {pagedQuery,type PagedQuery,} from 'loot-core/client/query-helpers';-import { type AppDispatch } from 'loot-core/client/store';import { send, listen } from 'loot-core/platform/client/fetch';import * as undo from 'loot-core/platform/client/undo';import { type UndoState } from 'loot-core/server/undo';@@ -68,6 +67,7 @@ import {updateNewTransactions,} from '../../queries/queriesSlice';import { useSelector, useDispatch } from '../../redux';+import { type AppDispatch } from '../../redux/store';import { type SavedFilter } from '../filters/SavedFilterMenuButton';import { TransactionList } from '../transactions/TransactionList';import { validateAccountName } from '../util/accountValidation';diff --git a/packages/desktop-client/src/global-events.ts b/packages/desktop-client/src/global-events.tsindex b1040f155f..7dcc2a7033 100644--- a/packages/desktop-client/src/global-events.ts+++ b/packages/desktop-client/src/global-events.ts@@ -1,6 +1,5 @@// @ts-strict-ignoreimport * as sharedListeners from 'loot-core/client/shared-listeners';-import { type AppStore } from 'loot-core/client/store';import { listen } from 'loot-core/platform/client/fetch';import * as undo from 'loot-core/platform/client/undo';@@ -13,6 +12,7 @@ import {} from './notifications/notificationsSlice';import { loadPrefs } from './prefs/prefsSlice';import { getAccounts, getCategories, getPayees } from './queries/queriesSlice';+import { type AppStore } from './redux/store';export function handleGlobalEvents(store: AppStore) {const unlistenServerError = listen('server-error', () => {diff --git a/packages/desktop-client/src/gocardless.ts b/packages/desktop-client/src/gocardless.tsindex f334cb5464..24382e80c4 100644--- a/packages/desktop-client/src/gocardless.ts+++ b/packages/desktop-client/src/gocardless.ts@@ -1,8 +1,8 @@-import { type AppDispatch } from 'loot-core/client/store';import { send } from 'loot-core/platform/client/fetch';import { type GoCardlessToken } from 'loot-core/types/models';import { pushModal } from './modals/modalsSlice';+import { type AppDispatch } from './redux/store';function _authorize(dispatch: AppDispatch,diff --git a/packages/desktop-client/src/index.tsx b/packages/desktop-client/src/index.tsxindex fbdda60746..4087309db0 100644--- a/packages/desktop-client/src/index.tsx+++ b/packages/desktop-client/src/index.tsx@@ -14,7 +14,6 @@ import { bindActionCreators } from '@reduxjs/toolkit';import { createRoot } from 'react-dom/client';import { aqlQuery } from 'loot-core/client/query-helpers';-import { store } from 'loot-core/client/store';import { redo, undo } from 'loot-core/client/undo';import { send } from 'loot-core/platform/client/fetch';import { q } from 'loot-core/shared/query';@@ -32,6 +31,7 @@ import * as modalsSlice from './modals/modalsSlice';import * as notificationsSlice from './notifications/notificationsSlice';import * as prefsSlice from './prefs/prefsSlice';import * as queriesSlice from './queries/queriesSlice';+import { store } from './redux/store';import * as usersSlice from './users/usersSlice';const boundActions = bindActionCreators(diff --git a/packages/desktop-client/src/modals/modalsSlice.ts b/packages/desktop-client/src/modals/modalsSlice.tsindex 5cb2930d7f..4a5bf06ec8 100644--- a/packages/desktop-client/src/modals/modalsSlice.ts+++ b/packages/desktop-client/src/modals/modalsSlice.ts@@ -1,6 +1,5 @@import { createSlice, type PayloadAction } from '@reduxjs/toolkit';-import { createAppAsyncThunk } from 'loot-core/client/redux';import { send } from 'loot-core/platform/client/fetch';import { type File } from 'loot-core/types/file';import {@@ -20,6 +19,7 @@ import {} from 'loot-core/types/models';import { resetApp, setAppState } from '../app/appSlice';+import { createAppAsyncThunk } from '../redux';import { signOut } from '../users/usersSlice';const sliceName = 'modals';diff --git a/packages/desktop-client/src/prefs/prefsSlice.ts b/packages/desktop-client/src/prefs/prefsSlice.tsindex ac3199d60e..9fbb6687f3 100644--- a/packages/desktop-client/src/prefs/prefsSlice.ts+++ b/packages/desktop-client/src/prefs/prefsSlice.ts@@ -1,6 +1,5 @@import { createSlice, type PayloadAction } from '@reduxjs/toolkit';-import { createAppAsyncThunk } from 'loot-core/client/redux';import { send } from 'loot-core/platform/client/fetch';import { parseNumberFormat, setNumberFormat } from 'loot-core/shared/util';import {@@ -12,6 +11,7 @@ import {import { resetApp } from '../app/appSlice';import { setI18NextLanguage } from '../i18n';import { closeModal } from '../modals/modalsSlice';+import { createAppAsyncThunk } from '../redux';const sliceName = 'prefs';diff --git a/packages/desktop-client/src/queries/queriesSlice.ts b/packages/desktop-client/src/queries/queriesSlice.tsindex 5581e7a6cf..bd47de26ca 100644--- a/packages/desktop-client/src/queries/queriesSlice.ts+++ b/packages/desktop-client/src/queries/queriesSlice.ts@@ -3,7 +3,6 @@ import { createSlice, type PayloadAction } from '@reduxjs/toolkit';import { t } from 'i18next';import memoizeOne from 'memoize-one';-import { createAppAsyncThunk } from 'loot-core/client/redux';import { send } from 'loot-core/platform/client/fetch';import { groupById } from 'loot-core/shared/util';import {@@ -19,6 +18,7 @@ import {addGenericErrorNotification,addNotification,} from '../notifications/notificationsSlice';+import { createAppAsyncThunk } from '../redux';const sliceName = 'queries';diff --git a/packages/desktop-client/src/redux/index.ts b/packages/desktop-client/src/redux/index.tsindex 077a41e94b..d8134ed369 100644--- a/packages/desktop-client/src/redux/index.ts+++ b/packages/desktop-client/src/redux/index.ts@@ -4,11 +4,14 @@ import {useStore as useReduxStore,} from 'react-redux';-import {- type AppStore,- type AppDispatch,- type RootState,-} from 'loot-core/client/store';+import { createAsyncThunk } from '@reduxjs/toolkit';++import { type AppDispatch, type AppStore, type RootState } from './store';++export const createAppAsyncThunk = createAsyncThunk.withTypes<{+ state: RootState;+ dispatch: AppDispatch;+}>();export const useStore = useReduxStore.withTypes<AppStore>();export const useDispatch = useReduxDispatch.withTypes<AppDispatch>();diff --git a/packages/desktop-client/src/redux/mock.tsx b/packages/desktop-client/src/redux/mock.tsxindex 138259bdc2..1ea1fe7cff 100644--- a/packages/desktop-client/src/redux/mock.tsx+++ b/packages/desktop-client/src/redux/mock.tsx@@ -1,7 +1,63 @@import React, { type ReactNode } from 'react';import { Provider } from 'react-redux';-import { mockStore } from 'loot-core/client/store/mock';+import { configureStore, combineReducers } from '@reduxjs/toolkit';++import {+ name as accountsSliceName,+ reducer as accountsSliceReducer,+} from '../accounts/accountsSlice';+import {+ name as appSliceName,+ reducer as appSliceReducer,+} from '../app/appSlice';+import {+ name as budgetsSliceName,+ reducer as budgetsSliceReducer,+} from '../budgets/budgetsSlice';+import {+ name as modalsSliceName,+ reducer as modalsSliceReducer,+} from '../modals/modalsSlice';+import {+ name as notificationsSliceName,+ reducer as notificationsSliceReducer,+} from '../notifications/notificationsSlice';+import {+ name as prefsSliceName,+ reducer as prefsSliceReducer,+} from '../prefs/prefsSlice';+import {+ name as queriesSliceName,+ reducer as queriesSliceReducer,+} from '../queries/queriesSlice';+import {+ name as usersSliceName,+ reducer as usersSliceReducer,+} from '../users/usersSlice';++import { type store as realStore } from './store';++const appReducer = combineReducers({+ [accountsSliceName]: accountsSliceReducer,+ [appSliceName]: appSliceReducer,+ [budgetsSliceName]: budgetsSliceReducer,+ [modalsSliceName]: modalsSliceReducer,+ [notificationsSliceName]: notificationsSliceReducer,+ [prefsSliceName]: prefsSliceReducer,+ [queriesSliceName]: queriesSliceReducer,+ [usersSliceName]: usersSliceReducer,+});++export let mockStore: typeof realStore = configureStore({+ reducer: appReducer,+});++export function resetMockStore() {+ mockStore = configureStore({+ reducer: appReducer,+ });+}export function TestProvider({ children }: { children: ReactNode }) {return <Provider store={mockStore}>{children}</Provider>;diff --git a/packages/loot-core/src/client/store/index.ts b/packages/desktop-client/src/redux/store.tssimilarity index 78%rename from packages/loot-core/src/client/store/index.tsrename to packages/desktop-client/src/redux/store.tsindex 96b821a73e..2cb3ee3fb3 100644--- a/packages/loot-core/src/client/store/index.ts+++ b/packages/desktop-client/src/redux/store.ts@@ -1,45 +1,43 @@-// This is temporary until we move all loot-core/client over to desktop-client.-/* eslint-disable no-restricted-imports */+import {+ combineReducers,+ configureStore,+ createListenerMiddleware,+ isRejected,+} from '@reduxjs/toolkit';+import {name as accountsSliceName,reducer as accountsSliceReducer,-} from '@actual-app/web/src/accounts/accountsSlice';+} from '../accounts/accountsSlice';import {name as appSliceName,reducer as appSliceReducer,-} from '@actual-app/web/src/app/appSlice';+} from '../app/appSlice';import {name as budgetsSliceName,reducer as budgetsSliceReducer,-} from '@actual-app/web/src/budgets/budgetsSlice';+} from '../budgets/budgetsSlice';import {name as modalsSliceName,reducer as modalsSliceReducer,-} from '@actual-app/web/src/modals/modalsSlice';+} from '../modals/modalsSlice';import {name as notificationsSliceName,reducer as notificationsSliceReducer,addNotification,-} from '@actual-app/web/src/notifications/notificationsSlice';+} from '../notifications/notificationsSlice';import {name as prefsSliceName,reducer as prefsSliceReducer,-} from '@actual-app/web/src/prefs/prefsSlice';+} from '../prefs/prefsSlice';import {name as queriesSliceName,reducer as queriesSliceReducer,-} from '@actual-app/web/src/queries/queriesSlice';+} from '../queries/queriesSlice';import {name as usersSliceName,reducer as usersSliceReducer,-} from '@actual-app/web/src/users/usersSlice';-/* eslint-enable no-restricted-imports */-import {- combineReducers,- configureStore,- createListenerMiddleware,- isRejected,-} from '@reduxjs/toolkit';+} from '../users/usersSlice';const rootReducer = combineReducers({[accountsSliceName]: accountsSliceReducer,diff --git a/packages/desktop-client/src/setupTests.js b/packages/desktop-client/src/setupTests.jsindex 8c96ca3efd..b0809ccaf4 100644--- a/packages/desktop-client/src/setupTests.js+++ b/packages/desktop-client/src/setupTests.js@@ -1,6 +1,5 @@-import { resetMockStore } from 'loot-core/client/store/mock';-import { installPolyfills } from './polyfills';+import { resetMockStore } from './redux/mock';installPolyfills();diff --git a/packages/desktop-client/src/users/usersSlice.ts b/packages/desktop-client/src/users/usersSlice.tsindex 4013999f0d..3887eed243 100644--- a/packages/desktop-client/src/users/usersSlice.ts+++ b/packages/desktop-client/src/users/usersSlice.ts@@ -1,12 +1,12 @@import { createSlice, type PayloadAction } from '@reduxjs/toolkit';-import { createAppAsyncThunk } from 'loot-core/client/redux';import { send } from 'loot-core/platform/client/fetch';import { type Handlers } from 'loot-core/types/handlers';import { resetApp } from '../app/appSlice';import { closeBudget, loadAllFiles } from '../budgets/budgetsSlice';import { loadGlobalPrefs } from '../prefs/prefsSlice';+import { createAppAsyncThunk } from '../redux';const sliceName = 'user';diff --git a/packages/loot-core/src/client/redux.ts b/packages/loot-core/src/client/redux.tsdeleted file mode 100644index c78eb816f1..0000000000--- a/packages/loot-core/src/client/redux.ts+++ /dev/null@@ -1,8 +0,0 @@-import { createAsyncThunk } from '@reduxjs/toolkit';--import { type AppDispatch, type RootState } from './store';--export const createAppAsyncThunk = createAsyncThunk.withTypes<{- state: RootState;- dispatch: AppDispatch;-}>();diff --git a/packages/loot-core/src/client/redux/index.ts b/packages/loot-core/src/client/redux/index.tsdeleted file mode 100644index 53941584c1..0000000000--- a/packages/loot-core/src/client/redux/index.ts+++ /dev/null@@ -1,8 +0,0 @@-import { createAsyncThunk } from '@reduxjs/toolkit';--import { type AppDispatch, type RootState } from '../store';--export const createAppAsyncThunk = createAsyncThunk.withTypes<{- state: RootState;- dispatch: AppDispatch;-}>();diff --git a/packages/loot-core/src/client/shared-listeners.ts b/packages/loot-core/src/client/shared-listeners.tsindex a0366888d9..f9b65af7e8 100644--- a/packages/loot-core/src/client/shared-listeners.ts+++ b/packages/loot-core/src/client/shared-listeners.ts@@ -17,14 +17,13 @@ import {getCategories,getPayees,} from '@actual-app/web/src/queries/queriesSlice';+import { type AppStore } from '@actual-app/web/src/redux/store';import { signOut } from '@actual-app/web/src/users/usersSlice';/* eslint-enable no-restricted-imports */import { t } from 'i18next';import { listen, send } from '../platform/client/fetch';-import { type AppStore } from './store';-export function listenForSyncEvent(store: AppStore) {// TODO: Should this run on mobile too?const unlistenUnauthorized = listen('sync-event', async ({ type }) => {diff --git a/packages/loot-core/src/client/store/mock.ts b/packages/loot-core/src/client/store/mock.tsdeleted file mode 100644index db2db4279a..0000000000--- a/packages/loot-core/src/client/store/mock.ts+++ /dev/null@@ -1,60 +0,0 @@-// This is temporary until we move all loot-core/client over to desktop-client.-/* eslint-disable */-import {- name as accountsSliceName,- reducer as accountsSliceReducer,-} from '@actual-app/web/src/accounts/accountsSlice';-import {- name as appSliceName,- reducer as appSliceReducer,-} from '@actual-app/web/src/app/appSlice';--import {- name as budgetsSliceName,- reducer as budgetsSliceReducer,-} from '@actual-app/web/src/budgets/budgetsSlice';-import {- name as modalsSliceName,- reducer as modalsSliceReducer,-} from '@actual-app/web/src/modals/modalsSlice';-import {- name as notificationsSliceName,- reducer as notificationsSliceReducer,-} from '@actual-app/web/src/notifications/notificationsSlice';-import {- name as prefsSliceName,- reducer as prefsSliceReducer,-} from '@actual-app/web/src/prefs/prefsSlice';-import {- name as queriesSliceName,- reducer as queriesSliceReducer,-} from '@actual-app/web/src/queries/queriesSlice';-import {- name as usersSliceName,- reducer as usersSliceReducer,-} from '@actual-app/web/src/users/usersSlice';-/* eslint-enable */-import { configureStore, combineReducers } from '@reduxjs/toolkit';--import { type store as realStore } from './index';--const appReducer = combineReducers({- [accountsSliceName]: accountsSliceReducer,- [appSliceName]: appSliceReducer,- [budgetsSliceName]: budgetsSliceReducer,- [modalsSliceName]: modalsSliceReducer,- [notificationsSliceName]: notificationsSliceReducer,- [prefsSliceName]: prefsSliceReducer,- [queriesSliceName]: queriesSliceReducer,- [usersSliceName]: usersSliceReducer,-});--export let mockStore: typeof realStore = configureStore({- reducer: appReducer,-});--export function resetMockStore() {- mockStore = configureStore({- reducer: appReducer,- });-}diff --git a/upcoming-release-notes/4827.md b/upcoming-release-notes/4827.mdnew file mode 100644index 0000000000..3fa5343394--- /dev/null+++ b/upcoming-release-notes/4827.md@@ -0,0 +1,6 @@+---+category: Maintenance+authors: [joel-jeremy]+---++Move loot-core/client/store and loot-core/client/redux to desktop-client package