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

Merged
merged 21 commits into from
Mar 1, 2025
Merged
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 @@ -16,12 +16,11 @@ import { View } from '@actual-app/components/view';

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 * as Platform from 'loot-core/client/platform';
import { SpreadsheetProvider } from 'loot-core/client/SpreadsheetProvider';
import { init as initConnection, send } from 'loot-core/platform/client/fetch';
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 @@ -9,7 +9,8 @@ import { styles } from '@actual-app/components/styles';
import { Text } from '@actual-app/components/text';
import { View } from '@actual-app/components/view';

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/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 @@ -15,16 +15,15 @@ import { Text } from '@actual-app/components/text';
import { Tooltip } from '@actual-app/components/tooltip';
import { View } from '@actual-app/components/view';

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 @@ -561,14 +560,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 @@ -6,7 +6,8 @@ import { Button, ButtonWithLoading } from '@actual-app/components/button';
import { Text } from '@actual-app/components/text';
import { View } from '@actual-app/components/view';

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
Expand Up @@ -7,7 +7,8 @@ import { styles } from '@actual-app/components/styles';
import { Text } from '@actual-app/components/text';
import { View } from '@actual-app/components/view';

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 { theme } from '../../style';
Expand Down Expand Up @@ -97,7 +98,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 @@ -7,7 +7,7 @@ import { Paragraph } from '@actual-app/components/paragraph';
import { Text } from '@actual-app/components/text';
import { View } from '@actual-app/components/view';

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

import { useNavigate } from '../../../hooks/useNavigate';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import { Text } from '@actual-app/components/text';
import { View } from '@actual-app/components/view';
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/platform/client/fetch';
import { getCreateKeyError } from 'loot-core/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
Expand Up @@ -7,7 +7,7 @@ import { Text } from '@actual-app/components/text';
import { theme } from '@actual-app/components/theme';
import { View } from '@actual-app/components/view';

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

Expand Down Expand Up @@ -107,7 +107,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 @@ -142,7 +147,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
Expand Up @@ -6,7 +6,8 @@ import { Label } from '@actual-app/components/label';
import { styles } from '@actual-app/components/styles';
import { View } from '@actual-app/components/view';

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
Expand Up @@ -6,7 +6,7 @@ import { Paragraph } from '@actual-app/components/paragraph';
import { Text } from '@actual-app/components/text';
import { View } from '@actual-app/components/view';

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

import { useDispatch } from '../../redux';
import { Link } from '../common/Link';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { Label } from '@actual-app/components/label';
import { styles } from '@actual-app/components/styles';
import { View } from '@actual-app/components/view';

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';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@ import { styles } from '@actual-app/components/styles';
import { Text } from '@actual-app/components/text';
import { View } from '@actual-app/components/view';

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 @@ -188,7 +185,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
Expand Up @@ -5,7 +5,7 @@ import { ButtonWithLoading } from '@actual-app/components/button';
import { Text } from '@actual-app/components/text';
import { View } from '@actual-app/components/view';

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

import { useDispatch } from '../../../redux';
Expand Down Expand Up @@ -71,10 +71,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 @@ -137,7 +137,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
Expand Up @@ -8,12 +8,9 @@ import { InlineField } from '@actual-app/components/inline-field';
import { Text } from '@actual-app/components/text';
import { View } from '@actual-app/components/view';

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/types/file';

import { useDispatch } from '../../../redux';
Expand Down Expand Up @@ -242,3 +239,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
Expand Up @@ -6,7 +6,8 @@ import { styles } from '@actual-app/components/styles';
import { Text } from '@actual-app/components/text';
import { View } from '@actual-app/components/view';

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 @@ -9,7 +9,7 @@ import { styles } from '@actual-app/components/styles';
import { theme } from '@actual-app/components/theme';
import { View } from '@actual-app/components/view';

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

import { useNavigate } from '../../../hooks/useNavigate';
import { useDispatch } from '../../../redux';
Expand Down Expand Up @@ -48,7 +48,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 @@ -9,7 +9,7 @@ import { styles } from '@actual-app/components/styles';
import { theme } from '@actual-app/components/theme';
import { View } from '@actual-app/components/view';

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

import { useNavigate } from '../../../hooks/useNavigate';
import { useDispatch } from '../../../redux';
Expand Down Expand Up @@ -40,7 +40,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 @@ -9,7 +9,7 @@ import { styles } from '@actual-app/components/styles';
import { theme } from '@actual-app/components/theme';
import { View } from '@actual-app/components/view';

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

import { useNavigate } from '../../../hooks/useNavigate';
import { useDispatch } from '../../../redux';
Expand Down Expand Up @@ -43,7 +43,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 @@ -6,7 +6,8 @@ import { Text } from '@actual-app/components/text';
import { View } from '@actual-app/components/view';
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 { listen } from 'loot-core/platform/client/fetch';
import { isElectron } from 'loot-core/shared/environment';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Popover } from '@actual-app/components/popover';
import { Text } from '@actual-app/components/text';
import { View } from '@actual-app/components/view';

import { closeBudget } from 'loot-core/client/actions';
import { closeBudget } from 'loot-core/client/budgets/budgetsSlice';
import * as Platform from 'loot-core/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/client/accounts/accountsSlice';
import * as actions from 'loot-core/client/actions';
import * as appSlice from 'loot-core/client/app/appSlice';
import * as budgetsSlice from 'loot-core/client/budgets/budgetsSlice';
import * as queriesSlice from 'loot-core/client/queries/queriesSlice';
import { runQuery } from 'loot-core/client/query-helpers';
import { store } from 'loot-core/client/store';
Expand All @@ -36,6 +37,7 @@ const boundActions = bindActionCreators(
...actions,
...accountsSlice.actions,
...appSlice.actions,
...budgetsSlice.actions,
...queriesSlice.actions,
},
store.dispatch,
Expand Down
Loading
Loading