diff --git a/packages/api/index.ts b/packages/api/index.ts index dfdadf2728d..be3f92d8bff 100644 --- a/packages/api/index.ts +++ b/packages/api/index.ts @@ -8,7 +8,7 @@ import type { import type { InitConfig } from 'loot-core/server/main'; // @ts-ignore: bundle not available until we build it -// eslint-disable-next-line import/extensions, import/no-unresolved +// eslint-disable-next-line import/extensions import * as bundle from './app/bundle.api.js'; import * as injected from './injected'; import { validateNodeVersion } from './validateNodeVersion'; diff --git a/packages/desktop-client/src/components/App.tsx b/packages/desktop-client/src/components/App.tsx index 72aa0150316..19312e1b938 100644 --- a/packages/desktop-client/src/components/App.tsx +++ b/packages/desktop-client/src/components/App.tsx @@ -18,6 +18,7 @@ import { sync, } from 'loot-core/client/actions'; import { setAppState } from 'loot-core/client/app/appSlice'; +import { closeBudget, loadBudget } from 'loot-core/client/budgets/budgetsSlice'; import { SpreadsheetProvider } from 'loot-core/client/SpreadsheetProvider'; import * as Platform from 'loot-core/src/client/platform'; import { @@ -42,7 +43,6 @@ import { Modals } from './Modals'; import { ResponsiveProvider } from './responsive/ResponsiveProvider'; import { SidebarProvider } from './sidebar/SidebarProvider'; import { UpdateNotification } from './UpdateNotification'; -import { closeBudget, loadBudget } from 'loot-core/client/budgets/budgetsSlice'; function AppInner() { const [budgetId] = useMetadataPref('id'); diff --git a/packages/desktop-client/src/components/LoggedInUser.tsx b/packages/desktop-client/src/components/LoggedInUser.tsx index 67a333b601d..acf30a77d38 100644 --- a/packages/desktop-client/src/components/LoggedInUser.tsx +++ b/packages/desktop-client/src/components/LoggedInUser.tsx @@ -3,6 +3,7 @@ import { Trans, useTranslation } from 'react-i18next'; import { useLocation } from 'react-router-dom'; import { getUserData, signOut } from 'loot-core/client/actions'; +import { closeBudget } from 'loot-core/client/budgets/budgetsSlice'; import { type RemoteFile, type SyncedLocalFile } from 'loot-core/types/file'; import { type TransObjectLiteral } from 'loot-core/types/util'; @@ -20,7 +21,6 @@ import { Text } from './common/Text'; import { View } from './common/View'; import { PrivacyFilter } from './PrivacyFilter'; import { useMultiuserEnabled, useServerURL } from './ServerContext'; -import { closeBudget } from 'loot-core/client/budgets/budgetsSlice'; type LoggedInUserProps = { hideIfNoServer?: boolean; diff --git a/packages/desktop-client/src/components/manager/BudgetList.tsx b/packages/desktop-client/src/components/manager/BudgetList.tsx index 5997611ad58..ecd5842b012 100644 --- a/packages/desktop-client/src/components/manager/BudgetList.tsx +++ b/packages/desktop-client/src/components/manager/BudgetList.tsx @@ -7,10 +7,15 @@ import React, { } from 'react'; import { Trans, useTranslation } from 'react-i18next'; +import { getUserData, pushModal } from 'loot-core/client/actions'; import { - getUserData, - pushModal, -} from 'loot-core/client/actions'; + closeAndDownloadBudget, + closeAndLoadBudget, + createBudget, + downloadBudget, + loadAllFiles, + loadBudget, +} from 'loot-core/client/budgets/budgetsSlice'; import { isElectron, isNonProductionEnvironment, @@ -47,7 +52,6 @@ import { Tooltip } from '../common/Tooltip'; import { View } from '../common/View'; import { useResponsive } from '../responsive/ResponsiveProvider'; import { useMultiuserEnabled } from '../ServerContext'; -import { closeAndDownloadBudget, closeAndLoadBudget, createBudget, downloadBudget, loadAllFiles, loadBudget } from 'loot-core/client/budgets/budgetsSlice'; function getFileDescription(file: File, t: (key: string) => string) { if (file.state === 'unknown') { diff --git a/packages/desktop-client/src/components/manager/ConfigServer.tsx b/packages/desktop-client/src/components/manager/ConfigServer.tsx index ed8f9b92f0f..d85ce82b0b7 100644 --- a/packages/desktop-client/src/components/manager/ConfigServer.tsx +++ b/packages/desktop-client/src/components/manager/ConfigServer.tsx @@ -3,6 +3,7 @@ import React, { useState, useEffect, useCallback } from 'react'; import { Trans, useTranslation } from 'react-i18next'; import { loggedIn, signOut } from 'loot-core/client/actions'; +import { createBudget } from 'loot-core/client/budgets/budgetsSlice'; import { isNonProductionEnvironment, isElectron, @@ -20,7 +21,6 @@ import { View } from '../common/View'; import { useServerURL, useSetServerURL } from '../ServerContext'; import { Title } from './subscribe/common'; -import { createBudget } from 'loot-core/client/budgets/budgetsSlice'; export function ConfigServer() { const { t } = useTranslation(); diff --git a/packages/desktop-client/src/components/manager/WelcomeScreen.tsx b/packages/desktop-client/src/components/manager/WelcomeScreen.tsx index 31499c75de2..3a90296f032 100644 --- a/packages/desktop-client/src/components/manager/WelcomeScreen.tsx +++ b/packages/desktop-client/src/components/manager/WelcomeScreen.tsx @@ -2,6 +2,7 @@ import React from 'react'; import { Trans, useTranslation } from 'react-i18next'; import { pushModal } from 'loot-core/client/actions'; +import { createBudget } from 'loot-core/client/budgets/budgetsSlice'; import { useAppDispatch } from '../../redux'; import { styles, theme } from '../../style'; @@ -10,7 +11,6 @@ import { Link } from '../common/Link'; import { Paragraph } from '../common/Paragraph'; import { Text } from '../common/Text'; import { View } from '../common/View'; -import { createBudget } from 'loot-core/client/budgets/budgetsSlice'; export function WelcomeScreen() { const { t } = useTranslation(); diff --git a/packages/desktop-client/src/components/manager/subscribe/Bootstrap.tsx b/packages/desktop-client/src/components/manager/subscribe/Bootstrap.tsx index 2e6179d2ba7..2570fa19dd2 100644 --- a/packages/desktop-client/src/components/manager/subscribe/Bootstrap.tsx +++ b/packages/desktop-client/src/components/manager/subscribe/Bootstrap.tsx @@ -2,6 +2,7 @@ import React, { useState } from 'react'; import { Trans, useTranslation } from 'react-i18next'; +import { createBudget } from 'loot-core/client/budgets/budgetsSlice'; import { send } from 'loot-core/src/platform/client/fetch'; import { useNavigate } from '../../../hooks/useNavigate'; @@ -16,7 +17,6 @@ import { useRefreshLoginMethods } from '../../ServerContext'; import { useBootstrapped, Title } from './common'; import { ConfirmPasswordForm } from './ConfirmPasswordForm'; -import { createBudget } from 'loot-core/client/budgets/budgetsSlice'; export function Bootstrap() { const { t } = useTranslation(); diff --git a/packages/desktop-client/src/components/modals/CreateEncryptionKeyModal.tsx b/packages/desktop-client/src/components/modals/CreateEncryptionKeyModal.tsx index d3f42e8eafc..71579902b3f 100644 --- a/packages/desktop-client/src/components/modals/CreateEncryptionKeyModal.tsx +++ b/packages/desktop-client/src/components/modals/CreateEncryptionKeyModal.tsx @@ -6,6 +6,7 @@ import { useTranslation, Trans } from 'react-i18next'; import { css } from '@emotion/css'; import { loadGlobalPrefs, sync } from 'loot-core/client/actions'; +import { loadAllFiles } from 'loot-core/client/budgets/budgetsSlice'; import { send } from 'loot-core/src/platform/client/fetch'; import { getCreateKeyError } from 'loot-core/src/shared/errors'; @@ -25,7 +26,6 @@ import { Paragraph } from '../common/Paragraph'; import { Text } from '../common/Text'; import { View } from '../common/View'; import { useResponsive } from '../responsive/ResponsiveProvider'; -import { loadAllFiles } from 'loot-core/client/budgets/budgetsSlice'; type CreateEncryptionKeyModalProps = { options: { diff --git a/packages/desktop-client/src/components/modals/OpenIDEnableModal.tsx b/packages/desktop-client/src/components/modals/OpenIDEnableModal.tsx index 75870615ee5..6cd361693b4 100644 --- a/packages/desktop-client/src/components/modals/OpenIDEnableModal.tsx +++ b/packages/desktop-client/src/components/modals/OpenIDEnableModal.tsx @@ -2,6 +2,7 @@ import { useState } from 'react'; import { Trans, useTranslation } from 'react-i18next'; import { popModal } from 'loot-core/client/actions'; +import { closeBudget } from 'loot-core/client/budgets/budgetsSlice'; import { send } from 'loot-core/platform/client/fetch'; import * as asyncStorage from 'loot-core/platform/server/asyncStorage'; import { getOpenIdErrors } from 'loot-core/shared/errors'; @@ -16,7 +17,6 @@ import { Modal, ModalCloseButton, ModalHeader } from '../common/Modal'; import { View } from '../common/View'; import { OpenIdForm } from '../manager/subscribe/OpenIdForm'; import { useRefreshLoginMethods } from '../ServerContext'; -import { closeBudget } from 'loot-core/client/budgets/budgetsSlice'; type OpenIDEnableModalProps = { onSave?: () => void; diff --git a/packages/desktop-client/src/components/modals/OutOfSyncMigrationsModal.tsx b/packages/desktop-client/src/components/modals/OutOfSyncMigrationsModal.tsx index d2c38af6f19..cd4b8e28693 100644 --- a/packages/desktop-client/src/components/modals/OutOfSyncMigrationsModal.tsx +++ b/packages/desktop-client/src/components/modals/OutOfSyncMigrationsModal.tsx @@ -1,6 +1,8 @@ import React from 'react'; import { Trans, useTranslation } from 'react-i18next'; +import { closeBudget } from 'loot-core/client/budgets/budgetsSlice'; + import { useAppDispatch } from '../../redux'; import { Button } from '../common/Button2'; import { Link } from '../common/Link'; @@ -8,7 +10,6 @@ import { Modal, ModalHeader, ModalTitle } from '../common/Modal'; import { Paragraph } from '../common/Paragraph'; import { Text } from '../common/Text'; import { View } from '../common/View'; -import { closeBudget } from 'loot-core/client/budgets/budgetsSlice'; export function OutOfSyncMigrationsModal() { const dispatch = useAppDispatch(); diff --git a/packages/desktop-client/src/components/modals/PasswordEnableModal.tsx b/packages/desktop-client/src/components/modals/PasswordEnableModal.tsx index 91a1ee32ed9..db249826d82 100644 --- a/packages/desktop-client/src/components/modals/PasswordEnableModal.tsx +++ b/packages/desktop-client/src/components/modals/PasswordEnableModal.tsx @@ -2,6 +2,7 @@ import { useState } from 'react'; import { Trans, useTranslation } from 'react-i18next'; import { popModal } from 'loot-core/client/actions'; +import { closeBudget } from 'loot-core/client/budgets/budgetsSlice'; import { send } from 'loot-core/platform/client/fetch'; import * as asyncStorage from 'loot-core/src/platform/server/asyncStorage'; @@ -22,7 +23,6 @@ import { useMultiuserEnabled, useRefreshLoginMethods, } from '../ServerContext'; -import { closeBudget } from 'loot-core/client/budgets/budgetsSlice'; type PasswordEnableModalProps = { onSave?: () => void; diff --git a/packages/desktop-client/src/components/modals/TransferOwnership.tsx b/packages/desktop-client/src/components/modals/TransferOwnership.tsx index 97915bac8f1..1dd999c65ed 100644 --- a/packages/desktop-client/src/components/modals/TransferOwnership.tsx +++ b/packages/desktop-client/src/components/modals/TransferOwnership.tsx @@ -1,10 +1,8 @@ import { useEffect, useState } from 'react'; import { Trans, useTranslation } from 'react-i18next'; -import { - addNotification, - popModal, -} from 'loot-core/client/actions'; +import { addNotification, popModal } from 'loot-core/client/actions'; +import { closeAndLoadBudget } from 'loot-core/client/budgets/budgetsSlice'; import { send } from 'loot-core/platform/client/fetch'; import { getUserAccessErrors } from 'loot-core/shared/errors'; import { type Budget } from 'loot-core/types/budget'; @@ -21,7 +19,6 @@ import { Stack } from '../common/Stack'; import { Text } from '../common/Text'; import { View } from '../common/View'; import { FormField, FormLabel } from '../forms'; -import { closeAndLoadBudget } from 'loot-core/client/budgets/budgetsSlice'; type TransferOwnershipProps = { onSave?: () => void; diff --git a/packages/desktop-client/src/components/modals/manager/DeleteFileModal.tsx b/packages/desktop-client/src/components/modals/manager/DeleteFileModal.tsx index 5b1d3204961..1305a0016a7 100644 --- a/packages/desktop-client/src/components/modals/manager/DeleteFileModal.tsx +++ b/packages/desktop-client/src/components/modals/manager/DeleteFileModal.tsx @@ -1,6 +1,7 @@ import React, { useState } from 'react'; import { Trans, useTranslation } from 'react-i18next'; +import { deleteBudget } from 'loot-core/client/budgets/budgetsSlice'; import { type File } from 'loot-core/src/types/file'; import { useAppDispatch } from '../../../redux'; @@ -9,7 +10,6 @@ import { ButtonWithLoading } from '../../common/Button2'; import { Modal, ModalCloseButton, ModalHeader } from '../../common/Modal'; import { Text } from '../../common/Text'; import { View } from '../../common/View'; -import { deleteBudget } from 'loot-core/client/budgets/budgetsSlice'; type DeleteFileProps = { file: File; @@ -73,7 +73,7 @@ export function DeleteFileModal({ file }: DeleteFileProps) { deleteBudget({ id: 'id' in file ? file.id : undefined, cloudFileId: file.cloudFileId, - }), + }), ); setLoadingState(null); diff --git a/packages/desktop-client/src/components/modals/manager/DuplicateFileModal.tsx b/packages/desktop-client/src/components/modals/manager/DuplicateFileModal.tsx index 977aca2d551..5623de26462 100644 --- a/packages/desktop-client/src/components/modals/manager/DuplicateFileModal.tsx +++ b/packages/desktop-client/src/components/modals/manager/DuplicateFileModal.tsx @@ -2,6 +2,8 @@ import React, { useEffect, useState } from 'react'; import { Trans, useTranslation } from 'react-i18next'; import { addNotification } from 'loot-core/client/actions'; +import { duplicateBudget } from 'loot-core/client/budgets/budgetsSlice'; +import { send } from 'loot-core/platform/client/fetch'; import { type File } from 'loot-core/src/types/file'; import { useAppDispatch } from '../../../redux'; @@ -19,8 +21,6 @@ import { } from '../../common/Modal'; import { Text } from '../../common/Text'; import { View } from '../../common/View'; -import { send } from 'loot-core/platform/client/fetch'; -import { duplicateBudget } from 'loot-core/client/budgets/budgetsSlice'; type DuplicateFileProps = { file: File; @@ -248,4 +248,4 @@ function validateBudgetName(name: string): { function uniqueBudgetName(name: string): string { return send('unique-budget-name', { name }); -} \ No newline at end of file +} diff --git a/packages/desktop-client/src/components/modals/manager/FilesSettingsModal.tsx b/packages/desktop-client/src/components/modals/manager/FilesSettingsModal.tsx index da1c2edb1a3..a12e70ff97c 100644 --- a/packages/desktop-client/src/components/modals/manager/FilesSettingsModal.tsx +++ b/packages/desktop-client/src/components/modals/manager/FilesSettingsModal.tsx @@ -2,6 +2,7 @@ import React, { useState } from 'react'; import { Trans, useTranslation } from 'react-i18next'; import { pushModal } from 'loot-core/client/actions'; +import { loadAllFiles } from 'loot-core/client/budgets/budgetsSlice'; import { useGlobalPref } from '../../../hooks/useGlobalPref'; import { SvgPencil1 } from '../../../icons/v2'; @@ -11,7 +12,6 @@ import { Button } from '../../common/Button2'; import { Modal, ModalCloseButton, ModalHeader } from '../../common/Modal'; import { Text } from '../../common/Text'; import { View } from '../../common/View'; -import { loadAllFiles } from 'loot-core/client/budgets/budgetsSlice'; function FileLocationSettings() { const [documentDir, _setDocumentDirPref] = useGlobalPref('documentDir'); diff --git a/packages/desktop-client/src/components/modals/manager/ImportActualModal.tsx b/packages/desktop-client/src/components/modals/manager/ImportActualModal.tsx index 0281af403c5..93da2be726a 100644 --- a/packages/desktop-client/src/components/modals/manager/ImportActualModal.tsx +++ b/packages/desktop-client/src/components/modals/manager/ImportActualModal.tsx @@ -2,6 +2,8 @@ import React, { useState } from 'react'; import { Trans, useTranslation } from 'react-i18next'; +import { importBudget } from 'loot-core/client/budgets/budgetsSlice'; + import { useNavigate } from '../../../hooks/useNavigate'; import { useAppDispatch } from '../../../redux'; import { styles, theme } from '../../../style'; @@ -10,7 +12,6 @@ import { ButtonWithLoading } from '../../common/Button2'; import { Modal, ModalCloseButton, ModalHeader } from '../../common/Modal'; import { Paragraph } from '../../common/Paragraph'; import { View } from '../../common/View'; -import { importBudget } from 'loot-core/client/budgets/budgetsSlice'; function getErrorMessage(error: string): string { switch (error) { diff --git a/packages/desktop-client/src/components/modals/manager/ImportYNAB4Modal.tsx b/packages/desktop-client/src/components/modals/manager/ImportYNAB4Modal.tsx index df504c9ac23..efb2a9f48dc 100644 --- a/packages/desktop-client/src/components/modals/manager/ImportYNAB4Modal.tsx +++ b/packages/desktop-client/src/components/modals/manager/ImportYNAB4Modal.tsx @@ -2,6 +2,8 @@ import React, { useState } from 'react'; import { Trans, useTranslation } from 'react-i18next'; +import { importBudget } from 'loot-core/client/budgets/budgetsSlice'; + import { useNavigate } from '../../../hooks/useNavigate'; import { useAppDispatch } from '../../../redux'; import { styles, theme } from '../../../style'; @@ -10,7 +12,6 @@ import { ButtonWithLoading } from '../../common/Button2'; import { Modal, ModalCloseButton, ModalHeader } from '../../common/Modal'; import { Paragraph } from '../../common/Paragraph'; import { View } from '../../common/View'; -import { importBudget } from 'loot-core/client/budgets/budgetsSlice'; function getErrorMessage(error: string): string { switch (error) { diff --git a/packages/desktop-client/src/components/modals/manager/ImportYNAB5Modal.tsx b/packages/desktop-client/src/components/modals/manager/ImportYNAB5Modal.tsx index 3a0ec9ebd8b..67b19cd7a36 100644 --- a/packages/desktop-client/src/components/modals/manager/ImportYNAB5Modal.tsx +++ b/packages/desktop-client/src/components/modals/manager/ImportYNAB5Modal.tsx @@ -2,6 +2,8 @@ import React, { useState } from 'react'; import { Trans, useTranslation } from 'react-i18next'; +import { importBudget } from 'loot-core/client/budgets/budgetsSlice'; + import { useNavigate } from '../../../hooks/useNavigate'; import { useAppDispatch } from '../../../redux'; import { styles, theme } from '../../../style'; @@ -11,7 +13,6 @@ import { Link } from '../../common/Link'; import { Modal, ModalCloseButton, ModalHeader } from '../../common/Modal'; import { Paragraph } from '../../common/Paragraph'; import { View } from '../../common/View'; -import { importBudget } from 'loot-core/client/budgets/budgetsSlice'; function getErrorMessage(error: string): string { switch (error) { diff --git a/packages/desktop-client/src/components/settings/index.tsx b/packages/desktop-client/src/components/settings/index.tsx index f75933bfee6..c25c1cdaea8 100644 --- a/packages/desktop-client/src/components/settings/index.tsx +++ b/packages/desktop-client/src/components/settings/index.tsx @@ -4,6 +4,7 @@ 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 { isElectron } from 'loot-core/shared/environment'; import { listen } from 'loot-core/src/platform/client/fetch'; @@ -35,7 +36,6 @@ import { FormatSettings } from './Format'; import { ResetCache, ResetSync } from './Reset'; import { ThemeSettings } from './Themes'; import { AdvancedToggle, Setting } from './UI'; -import { closeBudget } from 'loot-core/client/budgets/budgetsSlice'; function About() { const version = useServerVersion(); diff --git a/packages/desktop-client/src/components/sidebar/BudgetName.tsx b/packages/desktop-client/src/components/sidebar/BudgetName.tsx index ad770e07620..e32889489fd 100644 --- a/packages/desktop-client/src/components/sidebar/BudgetName.tsx +++ b/packages/desktop-client/src/components/sidebar/BudgetName.tsx @@ -1,6 +1,7 @@ import React, { type ReactNode, useRef, useState } from 'react'; import { useTranslation } from 'react-i18next'; +import { closeBudget } from 'loot-core/client/budgets/budgetsSlice'; import * as Platform from 'loot-core/src/client/platform'; import { useContextMenu } from '../../hooks/useContextMenu'; @@ -16,7 +17,6 @@ import { Menu } from '../common/Menu'; import { Popover } from '../common/Popover'; import { Text } from '../common/Text'; import { View } from '../common/View'; -import { closeBudget } from 'loot-core/client/budgets/budgetsSlice'; type BudgetNameProps = { children?: ReactNode; diff --git a/packages/loot-core/src/client/budgets/budgetsSlice.ts b/packages/loot-core/src/client/budgets/budgetsSlice.ts index 805d6a2221f..a9c5b936d17 100644 --- a/packages/loot-core/src/client/budgets/budgetsSlice.ts +++ b/packages/loot-core/src/client/budgets/budgetsSlice.ts @@ -1,30 +1,22 @@ -import { createAsyncThunk, createSlice, PayloadAction } from '@reduxjs/toolkit'; - -import { type AppDispatch, type RootState } from '../store'; -import { Budget } from 'loot-core/types/budget'; -import { File } from 'loot-core/types/file'; -import { RemoteFile } from 'loot-core/server/cloud-storage'; -import { send } from 'loot-core/platform/client/fetch'; -import { setAppState } from '../app/appSlice'; +import { createSlice, type PayloadAction } from '@reduxjs/toolkit'; import { t } from 'i18next'; -import { getDownloadError, getSyncError } from 'loot-core/shared/errors'; + +import { send } from '../../platform/client/fetch'; +import { type RemoteFile } from '../../server/cloud-storage'; +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 { closeModal, loadGlobalPrefs, loadPrefs, pushModal } from '../actions'; +import { setAppState } from '../app/appSlice'; import * as constants from '../constants'; -import { Handlers } from 'loot-core/types/handlers'; +import { createAppAsyncThunk } from '../store'; const sliceName = 'budgets'; -const createAppAsyncThunk = createAsyncThunk.withTypes<{ - state: RootState; - dispatch: AppDispatch; -}>(); - export const loadBudgets = createAppAsyncThunk( `${sliceName}/loadBudgets`, - async ( - _, - { dispatch }, - ) => { + async (_, { dispatch }) => { const budgets = await send('get-budgets'); await dispatch(setBudgets({ budgets })); @@ -33,10 +25,7 @@ export const loadBudgets = createAppAsyncThunk( export const loadRemoteFiles = createAppAsyncThunk( `${sliceName}/loadRemoteFiles`, - async ( - _, - { dispatch }, - ) => { + async (_, { dispatch }) => { const files = await send('get-remote-files'); await dispatch(setRemoteFiles({ remoteFiles: files })); @@ -45,10 +34,7 @@ export const loadRemoteFiles = createAppAsyncThunk( export const loadAllFiles = createAppAsyncThunk( `${sliceName}/loadAllFiles`, - async ( - _, - { dispatch, getState }, - ) => { + async (_, { dispatch, getState }) => { const budgets = await send('get-budgets'); const files = await send('get-remote-files'); @@ -62,14 +48,11 @@ type LoadBudgetPayload = { id: string; // TODO: Is this still needed? options?: Record; -} +}; export const loadBudget = createAppAsyncThunk( `${sliceName}/loadBudget`, - async ( - { id, options = {} }: LoadBudgetPayload, - { dispatch }, - ) => { + async ({ id, options = {} }: LoadBudgetPayload, { dispatch }) => { await dispatch(setAppState({ loadingText: t('Loading...') })); // Loading a budget may fail @@ -110,10 +93,7 @@ export const loadBudget = createAppAsyncThunk( export const closeBudget = createAppAsyncThunk( `${sliceName}/closeBudget`, - async ( - _, - { dispatch, getState }, - ) => { + async (_, { dispatch, getState }) => { const prefs = getState().prefs.local; if (prefs && prefs.id) { // This clears out all the app state so the user starts fresh @@ -132,10 +112,7 @@ export const closeBudget = createAppAsyncThunk( export const closeBudgetUI = createAppAsyncThunk( `${sliceName}/closeBudgetUI`, - async ( - _, - { dispatch, getState }, - ) => { + async (_, { dispatch, getState }) => { const prefs = getState().prefs.local; if (prefs && prefs.id) { // TODO: Change to use an action once CLOSE_BUDGET is migrated to redux toolkit. @@ -151,10 +128,7 @@ type DeleteBudgetPayload = { export const deleteBudget = createAppAsyncThunk( `${sliceName}/deleteBudget`, - async ( - { id, cloudFileId }: DeleteBudgetPayload, - { dispatch }, - ) => { + async ({ id, cloudFileId }: DeleteBudgetPayload, { dispatch }) => { await send('delete-budget', { id, cloudFileId }); await dispatch(loadAllFiles()); }, @@ -258,16 +232,13 @@ export const duplicateBudget = createAppAsyncThunk( ); type ImportBudgetPayload = { - filepath: string, - type: Parameters[0]['type'], + filepath: string; + type: Parameters[0]['type']; }; export const importBudget = createAppAsyncThunk( `${sliceName}/importBudget`, - async ( - { filepath, type }: ImportBudgetPayload, - { dispatch }, - ) => { + async ({ filepath, type }: ImportBudgetPayload, { dispatch }) => { const { error } = await send('import-budget', { filepath, type }); if (error) { throw new Error(error); @@ -284,10 +255,7 @@ type UploadBudgetPayload = { export const uploadBudget = createAppAsyncThunk( `${sliceName}/uploadBudget`, - async ( - { id }: UploadBudgetPayload, - { dispatch }, - ) => { + async ({ id }: UploadBudgetPayload, { dispatch }) => { const { error } = await send('upload-budget', { id }); if (error) { return { error }; @@ -300,10 +268,7 @@ export const uploadBudget = createAppAsyncThunk( export const closeAndLoadBudget = createAppAsyncThunk( `${sliceName}/closeAndLoadBudget`, - async ( - { fileId }: { fileId: string }, - { dispatch }, - ) => { + async ({ fileId }: { fileId: string }, { dispatch }) => { await dispatch(closeBudget()); await dispatch(loadBudget({ id: fileId })); }, @@ -315,10 +280,7 @@ type CloseAndDownloadBudgetPayload = { export const closeAndDownloadBudget = createAppAsyncThunk( `${sliceName}/closeAndDownloadBudget`, - async ( - { cloudFileId }: CloseAndDownloadBudgetPayload, - { dispatch }, - ) => { + async ({ cloudFileId }: CloseAndDownloadBudgetPayload, { dispatch }) => { await dispatch(closeBudget()); await dispatch(downloadBudget({ cloudFileId, replace: true })); }, @@ -371,7 +333,9 @@ export const downloadBudget = createAppAsyncThunk( ), ); - return await dispatch(downloadBudget({ cloudFileId, replace: true })).unwrap(); + return await dispatch( + downloadBudget({ cloudFileId, replace: true }), + ).unwrap(); } else { await dispatch(setAppState({ loadingText: null })); alert(getDownloadError(error)); @@ -404,16 +368,16 @@ const initialState: BudgetsState = { type SetBudgetsPayload = { budgets: Budget[]; -} +}; type SetRemoteFilesPayload = { remoteFiles: RemoteFile[]; -} +}; type SetAllFilesPayload = { budgets: Budget[]; remoteFiles: RemoteFile[]; -} +}; const budgetsSlice = createSlice({ name: 'budgets', @@ -421,16 +385,25 @@ const budgetsSlice = createSlice({ reducers: { setBudgets(state, action: PayloadAction) { state.budgets = action.payload.budgets; - state.allFiles = reconcileFiles(action.payload.budgets, state.remoteFiles); + state.allFiles = reconcileFiles( + action.payload.budgets, + state.remoteFiles, + ); }, setRemoteFiles(state, action: PayloadAction) { state.remoteFiles = action.payload.remoteFiles; - state.allFiles = reconcileFiles(state.budgets, action.payload.remoteFiles); + state.allFiles = reconcileFiles( + state.budgets, + action.payload.remoteFiles, + ); }, setAllFiles(state, action: PayloadAction) { state.budgets = action.payload.budgets; state.remoteFiles = action.payload.remoteFiles; - state.allFiles = reconcileFiles(action.payload.budgets, action.payload.remoteFiles); + state.allFiles = reconcileFiles( + action.payload.budgets, + action.payload.remoteFiles, + ); }, signOut(state) { state.allFiles = null; diff --git a/packages/loot-core/src/client/reducers/modals.ts b/packages/loot-core/src/client/reducers/modals.ts index 4dadc8b2024..6f0dac1ec01 100644 --- a/packages/loot-core/src/client/reducers/modals.ts +++ b/packages/loot-core/src/client/reducers/modals.ts @@ -11,13 +11,13 @@ type ModalsAction = | Action // TODO. Temporary until we migrate to redux toolkit. | { - type: 'app/setAppState'; - payload: { loadingText: string | null }; - } + type: 'app/setAppState'; + payload: { loadingText: string | null }; + } // TODO: Temporary until we migrate to redux toolkit. | { - type: 'budgets/signOut'; - }; + type: 'budgets/signOut'; + }; export function update( state = initialState, diff --git a/packages/loot-core/src/client/shared-listeners.ts b/packages/loot-core/src/client/shared-listeners.ts index e6d9c74850d..fd6a7dccc24 100644 --- a/packages/loot-core/src/client/shared-listeners.ts +++ b/packages/loot-core/src/client/shared-listeners.ts @@ -11,10 +11,10 @@ import { signOut, sync, } from './actions'; +import { closeAndDownloadBudget, uploadBudget } from './budgets/budgetsSlice'; import { getAccounts, getCategories, getPayees } from './queries/queriesSlice'; import type { Notification } from './state-types/notifications'; import { type AppStore } from './store'; -import { closeAndDownloadBudget, uploadBudget } from './budgets/budgetsSlice'; export function listenForSyncEvent(store: AppStore) { let attemptedSyncRepair = false; @@ -225,7 +225,7 @@ export function listenForSyncEvent(store: AppStore) { button: { title: t('Revert'), action: () => { - store.dispatch(closeAndDownloadBudget({ cloudFileId })) + store.dispatch(closeAndDownloadBudget({ cloudFileId })); }, }, }; diff --git a/packages/loot-core/src/client/store/index.ts b/packages/loot-core/src/client/store/index.ts index 96e49f8765a..4987fab82d4 100644 --- a/packages/loot-core/src/client/store/index.ts +++ b/packages/loot-core/src/client/store/index.ts @@ -14,12 +14,12 @@ import { reducer as appSliceReducer, getInitialState as getInitialAppState, } from '../app/appSlice'; -import * as constants from '../constants'; import { name as budgetsSliceName, reducer as budgetsSliceReducer, getInitialState as getInitialBudgetsState, } from '../budgets/budgetsSlice'; +import * as constants from '../constants'; import { name as queriesSliceName, reducer as queriesSliceReducer,