Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Redux Toolkit Migration] budgetsSlice #4114

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions packages/desktop-client/src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ import { BrowserRouter } from 'react-router-dom';

import {
addNotification,
closeBudget,
loadBudget,
loadGlobalPrefs,
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 { SpreadsheetProvider } from 'loot-core/client/SpreadsheetProvider';
import * as Platform from 'loot-core/src/client/platform';
import {
Expand Down Expand Up @@ -95,7 +94,7 @@ function AppInner() {
);
const budgetId = await send('get-last-opened-backup');
if (budgetId) {
await dispatch(loadBudget(budgetId));
await dispatch(loadBudget({ id: budgetId }));

// Check to see if this file has been remotely deleted (but
// don't block on this in case they are offline or something)
Expand Down
3 changes: 2 additions & 1 deletion packages/desktop-client/src/components/LoggedInUser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import React, { useState, useEffect, useRef, type CSSProperties } from 'react';
import { Trans, useTranslation } from 'react-i18next';
import { useLocation } from 'react-router-dom';

import { closeBudget, getUserData, signOut } from 'loot-core/client/actions';
import { getUserData, signOut } from 'loot-core/client/actions';
import { closeBudget } from 'loot-core/client/budgets/budgetsSlice';
import { listen } from 'loot-core/src/platform/client/fetch';
import { type RemoteFile, type SyncedLocalFile } from 'loot-core/types/file';
import { type TransObjectLiteral } from 'loot-core/types/util';
Expand Down
13 changes: 6 additions & 7 deletions packages/desktop-client/src/components/manager/BudgetList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@ import React, {
} from 'react';
import { Trans, useTranslation } from 'react-i18next';

import { getUserData, pushModal } from 'loot-core/client/actions';
import {
closeAndDownloadBudget,
closeAndLoadBudget,
createBudget,
downloadBudget,
getUserData,
loadAllFiles,
loadBudget,
pushModal,
} from 'loot-core/client/actions';
} from 'loot-core/client/budgets/budgetsSlice';
import {
isElectron,
isNonProductionEnvironment,
Expand Down Expand Up @@ -559,14 +558,14 @@ export function BudgetList({ showHeader = true, quickSwitchMode = false }) {

if (!id) {
if (isRemoteFile) {
await dispatch(downloadBudget(file.cloudFileId));
await dispatch(downloadBudget({ cloudFileId: file.cloudFileId }));
} else {
await dispatch(loadBudget(file.id));
await dispatch(loadBudget({ id: file.id }));
}
} else if (!isRemoteFile && file.id !== id) {
await dispatch(closeAndLoadBudget(file.id));
await dispatch(closeAndLoadBudget({ fileId: file.id }));
} else if (isRemoteFile) {
await dispatch(closeAndDownloadBudget(file.cloudFileId));
await dispatch(closeAndDownloadBudget({ cloudFileId: file.cloudFileId }));
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import React, { useState, useEffect, useCallback } from 'react';
import { Trans, useTranslation } from 'react-i18next';

import { createBudget, loggedIn, signOut } from 'loot-core/client/actions';
import { loggedIn, signOut } from 'loot-core/client/actions';
import { createBudget } from 'loot-core/client/budgets/budgetsSlice';
import {
isNonProductionEnvironment,
isElectron,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React from 'react';
import { Trans, useTranslation } from 'react-i18next';

import { createBudget, pushModal } from 'loot-core/client/actions';
import { pushModal } from 'loot-core/client/actions';
import { createBudget } from 'loot-core/client/budgets/budgetsSlice';

import { useDispatch } from '../../redux';
import { styles, theme } from '../../style';
Expand Down Expand Up @@ -95,7 +96,7 @@ export function WelcomeScreen() {
<Button
variant="primary"
autoFocus
onPress={() => dispatch(createBudget())}
onPress={() => dispatch(createBudget({}))}
>
{t('Start fresh')}
</Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import React, { useState } from 'react';
import { Trans, useTranslation } from 'react-i18next';

import { createBudget } from 'loot-core/src/client/actions/budgets';
import { createBudget } from 'loot-core/client/budgets/budgetsSlice';
import { send } from 'loot-core/src/platform/client/fetch';

import { useNavigate } from '../../../hooks/useNavigate';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import { useTranslation, Trans } from 'react-i18next';

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

import { loadAllFiles, loadGlobalPrefs } from 'loot-core/client/actions';
import { loadGlobalPrefs } from 'loot-core/client/actions';
import { sync } from 'loot-core/client/app/appSlice';
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';

Expand Down
15 changes: 12 additions & 3 deletions packages/desktop-client/src/components/modals/LoadBackupModal.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState, useEffect } from 'react';
import { useTranslation } from 'react-i18next';

import { loadBackup, makeBackup } from 'loot-core/client/actions';
import { loadBackup, makeBackup } from 'loot-core/client/budgets/budgetsSlice';
import { type Backup } from 'loot-core/server/backups';
import { send, listen, unlisten } from 'loot-core/src/platform/client/fetch';

Expand Down Expand Up @@ -106,7 +106,12 @@ export function LoadBackupModal({
<Button
variant="primary"
onPress={() =>
dispatch(loadBackup(budgetIdToLoad, latestBackup.id))
dispatch(
loadBackup({
budgetId: budgetIdToLoad,
backupId: latestBackup.id,
}),
)
}
>
{t('Revert to original version')}
Expand Down Expand Up @@ -141,7 +146,11 @@ export function LoadBackupModal({
) : (
<BackupTable
backups={previousBackups}
onSelect={id => dispatch(loadBackup(budgetIdToLoad, id))}
onSelect={id =>
dispatch(
loadBackup({ budgetId: budgetIdToLoad, backupId: id }),
)
}
/>
)}
</View>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { useState } from 'react';
import { Trans, useTranslation } from 'react-i18next';

import { closeBudget, popModal } from 'loot-core/client/actions';
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';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { Trans, useTranslation } from 'react-i18next';

import { closeBudget } from 'loot-core/client/actions';
import { closeBudget } from 'loot-core/client/budgets/budgetsSlice';

import { useDispatch } from '../../redux';
import { Button } from '../common/Button2';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { useState } from 'react';
import { Trans, useTranslation } from 'react-i18next';

import { closeBudget, popModal } from 'loot-core/client/actions';
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';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { useEffect, useState } from 'react';
import { Trans, useTranslation } from 'react-i18next';

import {
addNotification,
closeAndLoadBudget,
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';
Expand Down Expand Up @@ -186,7 +183,7 @@ export function TransferOwnership({
try {
await onSave();
await dispatch(
closeAndLoadBudget((currentFile as Budget).id),
closeAndLoadBudget({ fileId: (currentFile as Budget).id }),
);
close();
} catch (error) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState } from 'react';
import { Trans, useTranslation } from 'react-i18next';

import { deleteBudget } from 'loot-core/client/actions';
import { deleteBudget } from 'loot-core/client/budgets/budgetsSlice';
import { type File } from 'loot-core/src/types/file';

import { useDispatch } from '../../../redux';
Expand Down Expand Up @@ -70,10 +70,10 @@ export function DeleteFileModal({ file }: DeleteFileProps) {
onPress={async () => {
setLoadingState('cloud');
await dispatch(
deleteBudget(
'id' in file ? file.id : undefined,
file.cloudFileId,
),
deleteBudget({
id: 'id' in file ? file.id : undefined,
cloudFileId: file.cloudFileId,
}),
);
setLoadingState(null);

Expand Down Expand Up @@ -136,7 +136,7 @@ export function DeleteFileModal({ file }: DeleteFileProps) {
}}
onPress={async () => {
setLoadingState('local');
await dispatch(deleteBudget(file.id));
await dispatch(deleteBudget({ id: file.id }));
setLoadingState(null);

close();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import React, { useEffect, useState } from 'react';
import { Trans, useTranslation } from 'react-i18next';

import {
addNotification,
duplicateBudget,
uniqueBudgetName,
validateBudgetName,
} from 'loot-core/client/actions';
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 { useDispatch } from '../../../redux';
Expand Down Expand Up @@ -241,3 +238,14 @@ export function DuplicateFileModal({
</Modal>
);
}

async function validateBudgetName(name: string): Promise<{
valid: boolean;
message?: string;
}> {
return send('validate-budget-name', { name });
}

async function uniqueBudgetName(name: string): Promise<string> {
return send('unique-budget-name', { name });
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React, { useState } from 'react';
import { Trans, useTranslation } from 'react-i18next';

import { loadAllFiles, pushModal } from 'loot-core/client/actions';
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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import React, { useState } from 'react';
import { Trans, useTranslation } from 'react-i18next';

import { importBudget } from 'loot-core/src/client/actions/budgets';
import { importBudget } from 'loot-core/client/budgets/budgetsSlice';

import { useNavigate } from '../../../hooks/useNavigate';
import { useDispatch } from '../../../redux';
Expand Down Expand Up @@ -46,7 +46,7 @@ export function ImportActualModal() {
setImporting(true);
setError(null);
try {
await dispatch(importBudget(res[0], 'actual'));
await dispatch(importBudget({ filepath: res[0], type: 'actual' }));
navigate('/budget');
} catch (err) {
setError(err.message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import React, { useState } from 'react';
import { Trans, useTranslation } from 'react-i18next';

import { importBudget } from 'loot-core/src/client/actions/budgets';
import { importBudget } from 'loot-core/client/budgets/budgetsSlice';

import { useNavigate } from '../../../hooks/useNavigate';
import { useDispatch } from '../../../redux';
Expand Down Expand Up @@ -38,7 +38,7 @@ export function ImportYNAB4Modal() {
setImporting(true);
setError(null);
try {
await dispatch(importBudget(res[0], 'ynab4'));
await dispatch(importBudget({ filepath: res[0], type: 'ynab4' }));
navigate('/budget');
} catch (err) {
setError(err.message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import React, { useState } from 'react';
import { Trans, useTranslation } from 'react-i18next';

import { importBudget } from 'loot-core/src/client/actions/budgets';
import { importBudget } from 'loot-core/client/budgets/budgetsSlice';

import { useNavigate } from '../../../hooks/useNavigate';
import { useDispatch } from '../../../redux';
Expand Down Expand Up @@ -41,7 +41,7 @@ export function ImportYNAB5Modal() {
setImporting(true);
setError(null);
try {
await dispatch(importBudget(res[0], 'ynab5'));
await dispatch(importBudget({ filepath: res[0], type: 'ynab5' }));
navigate('/budget');
} catch (err) {
setError(err.message);
Expand Down
3 changes: 2 additions & 1 deletion packages/desktop-client/src/components/settings/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { useTranslation, Trans } from 'react-i18next';

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

import { closeBudget, loadPrefs } from 'loot-core/client/actions';
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';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { type ReactNode, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';

import { closeBudget } from 'loot-core/src/client/actions';
import { closeBudget } from 'loot-core/client/budgets/budgetsSlice';
import * as Platform from 'loot-core/src/client/platform';

import { useContextMenu } from '../../hooks/useContextMenu';
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
Expand Up @@ -2,13 +2,13 @@
import {
addGenericErrorNotification,
addNotification,
closeBudgetUI,
closeModal,
loadPrefs,
pushModal,
replaceModal,
} from 'loot-core/client/actions';
import { setAppState } from 'loot-core/client/app/appSlice';
import { closeBudgetUI } from 'loot-core/client/budgets/budgetsSlice';
import {
getAccounts,
getCategories,
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 @@ -16,6 +16,7 @@ import { createRoot } from 'react-dom/client';
import * as accountsSlice from 'loot-core/src/client/accounts/accountsSlice';
import * as actions from 'loot-core/src/client/actions';
import * as appSlice from 'loot-core/src/client/app/appSlice';
import * as budgetsSlice from 'loot-core/src/client/budgets/budgetsSlice';
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 @@ -37,6 +38,7 @@ const boundActions = bindActionCreators(
...actions,
...accountsSlice.actions,
...appSlice.actions,
...budgetsSlice.actions,
...queriesSlice.actions,
},
store.dispatch,
Expand Down
Loading
Loading