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] appSlice #4018

Merged
merged 26 commits into from
Jan 18, 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
3 changes: 1 addition & 2 deletions packages/desktop-client/src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ import {
closeBudget,
loadBudget,
loadGlobalPrefs,
setAppState,
signOut,
sync,
} from 'loot-core/client/actions';
import { setAppState, sync } from 'loot-core/client/app/appSlice';
import { SpreadsheetProvider } from 'loot-core/client/SpreadsheetProvider';
import * as Platform from 'loot-core/src/client/platform';
import {
Expand Down
2 changes: 1 addition & 1 deletion packages/desktop-client/src/components/FatalError.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ export function FatalError({ error }: FatalErrorProps) {
)}

<Paragraph>
<Button onPress={() => window.Actual?.relaunch()}>
<Button onPress={() => window.Actual.relaunch()}>
<Trans>Restart app</Trans>
</Button>
</Paragraph>
Expand Down
3 changes: 2 additions & 1 deletion packages/desktop-client/src/components/FinancesApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {
useHref,
} from 'react-router-dom';

import { addNotification, sync } from 'loot-core/client/actions';
import { addNotification } from 'loot-core/client/actions';
import { sync } from 'loot-core/client/app/appSlice';
import * as undo from 'loot-core/src/platform/client/undo';

import { ProtectedRoute } from '../auth/ProtectedRoute';
Expand Down
27 changes: 25 additions & 2 deletions packages/desktop-client/src/components/HelpMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { useLocation } from 'react-router-dom';

import { useToggle } from 'usehooks-ts';

import { openDocsForCurrentPage } from 'loot-core/client/actions';
import { pushModal } from 'loot-core/client/actions/modals';

import { useFeatureFlag } from '../hooks/useFeatureFlag';
Expand All @@ -17,6 +16,30 @@ import { Menu } from './common/Menu';
import { Popover } from './common/Popover';
import { SpaceBetween } from './common/SpaceBetween';

const getPageDocs = (page: string) => {
switch (page) {
case '/budget':
return 'https://actualbudget.org/docs/getting-started/envelope-budgeting';
case '/reports':
return 'https://actualbudget.org/docs/reports/';
case '/schedules':
return 'https://actualbudget.org/docs/schedules';
case '/payees':
return 'https://actualbudget.org/docs/transactions/payees';
case '/rules':
return 'https://actualbudget.org/docs/budgeting/rules';
case '/settings':
return 'https://actualbudget.org/docs/settings';
default:
// All pages under /accounts, plus any missing pages
return 'https://actualbudget.org/docs';
}
};

function openDocsForCurrentPage() {
window.Actual.openURLInBrowser(getPageDocs(window.location.pathname));
}

type HelpMenuItem = 'docs' | 'keyboard-shortcuts' | 'goal-templates';

type HelpButtonProps = {
Expand Down Expand Up @@ -58,7 +81,7 @@ export const HelpMenu = () => {
const handleItemSelect = (item: HelpMenuItem) => {
switch (item) {
case 'docs':
dispatch(openDocsForCurrentPage());
openDocsForCurrentPage();
Copy link
Contributor Author

@joel-jeremy joel-jeremy Jan 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

openDocsForCurrentPage action just calls window.Actual.openURLInBrowser so just call it directly here instead of going through redux dispatch since it doesn't really affect the redux state

break;
case 'keyboard-shortcuts':
dispatch(pushModal('keyboard-shortcuts'));
Expand Down
2 changes: 1 addition & 1 deletion packages/desktop-client/src/components/Titlebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Routes, Route, useLocation } from 'react-router-dom';

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

import { sync } from 'loot-core/client/actions';
import { sync } from 'loot-core/client/app/appSlice';
import * as Platform from 'loot-core/src/client/platform';
import * as queries from 'loot-core/src/client/queries';
import { listen } from 'loot-core/src/platform/client/fetch';
Expand Down
4 changes: 2 additions & 2 deletions packages/desktop-client/src/components/UpdateNotification.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { useTranslation } from 'react-i18next';

import { setAppState, updateApp } from 'loot-core/client/actions';
import { setAppState, updateApp } from 'loot-core/client/app/appSlice';

import { SvgClose } from '../icons/v1';
import { useSelector, useDispatch } from '../redux';
Expand Down Expand Up @@ -69,7 +69,7 @@ export function UpdateNotification() {
textDecoration: 'underline',
}}
onClick={() =>
window.Actual?.openURLInBrowser(
window.Actual.openURLInBrowser(
'https://actualbudget.org/docs/releases',
)
}
Expand Down
8 changes: 4 additions & 4 deletions packages/desktop-client/src/components/accounts/Account.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import {
openAccountCloseModal,
pushModal,
replaceModal,
syncAndDownload,
} from 'loot-core/client/actions';
import { syncAndDownload } from 'loot-core/client/app/appSlice';
import {
createPayee,
initiallyLoadPayees,
Expand Down Expand Up @@ -624,7 +624,7 @@ class AccountInternal extends PureComponent<
const account = this.props.accounts.find(acct => acct.id === accountId);

await this.props.dispatch(
syncAndDownload(account ? account.id : undefined),
syncAndDownload({ accountId: account ? account.id : undefined }),
);
};

Expand All @@ -633,7 +633,7 @@ class AccountInternal extends PureComponent<
const account = this.props.accounts.find(acct => acct.id === accountId);

if (account) {
const res = await window.Actual?.openFileDialog({
const res = await window.Actual.openFileDialog({
filters: [
{
name: t('Financial Files'),
Expand Down Expand Up @@ -668,7 +668,7 @@ class AccountInternal extends PureComponent<
accountName && accountName.replace(/[()]/g, '').replace(/\s+/g, '-');
const filename = `${normalizedName || 'transactions'}.csv`;

window.Actual?.saveFile(
window.Actual.saveFile(
exportedTransactions,
filename,
t('Export Transactions'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export function ConfigServer() {
}

async function onSelectSelfSignedCertificate() {
const selfSignedCertificateLocation = await window.Actual?.openFileDialog({
const selfSignedCertificateLocation = await window.Actual.openFileDialog({
properties: ['openFile'],
filters: [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React, { useEffect } from 'react';
import { Navigate, Route, Routes } from 'react-router-dom';

import { loggedIn, setAppState } from 'loot-core/client/actions';
import { loggedIn } from 'loot-core/client/actions';
import { setAppState } from 'loot-core/client/app/appSlice';

import { ProtectedRoute } from '../../auth/ProtectedRoute';
import { Permissions } from '../../auth/types';
Expand Down Expand Up @@ -51,7 +52,7 @@ function Version() {
},
}}
>
{`App: v${window.Actual?.ACTUAL_VERSION} | Server: ${version}`}
{`App: v${window.Actual.ACTUAL_VERSION} | Server: ${version}`}
</Text>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import {
collapseModals,
openAccountCloseModal,
pushModal,
syncAndDownload,
} from 'loot-core/client/actions';
import { syncAndDownload } from 'loot-core/client/app/appSlice';
import {
accountSchedulesQuery,
SchedulesProvider,
Expand Down Expand Up @@ -258,7 +258,7 @@ function TransactionListWithPreviews({

const onRefresh = useCallback(() => {
if (accountId) {
dispatch(syncAndDownload(accountId));
dispatch(syncAndDownload({ accountId }));
}
}, [accountId, dispatch]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { useTranslation } from 'react-i18next';

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

import { replaceModal, syncAndDownload } from 'loot-core/src/client/actions';
import { syncAndDownload } from 'loot-core/client/app/appSlice';
import { replaceModal } from 'loot-core/src/client/actions';
import * as queries from 'loot-core/src/client/queries';
import { type AccountEntity } from 'loot-core/types/models';

Expand Down Expand Up @@ -323,7 +324,7 @@ export function Accounts() {
}, [dispatch]);

const onSync = useCallback(async () => {
dispatch(syncAndDownload());
dispatch(syncAndDownload({}));
}, [dispatch]);

return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// @ts-strict-ignore
import React, { useCallback, useEffect, useState } from 'react';

import { collapseModals, pushModal, sync } from 'loot-core/client/actions';
import { collapseModals, pushModal } from 'loot-core/client/actions';
import { sync } from 'loot-core/client/app/appSlice';
import {
applyBudgetAction,
createCategory,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { useTranslation, Trans } from 'react-i18next';

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

import { loadAllFiles, loadGlobalPrefs, sync } from 'loot-core/client/actions';
import { loadAllFiles, loadGlobalPrefs } from 'loot-core/client/actions';
import { sync } from 'loot-core/client/app/appSlice';
import { send } from 'loot-core/src/platform/client/fetch';
import { getCreateKeyError } from 'loot-core/src/shared/errors';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ export function ImportTransactionsModal({ options }) {
}

async function onNewFile() {
const res = await window.Actual?.openFileDialog({
const res = await window.Actual.openFileDialog({
filters: [
{
name: 'Financial Files',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export function ConfirmChangeDocumentDirModal({
const dispatch = useDispatch();

const restartElectronServer = useCallback(() => {
globalThis.window.Actual?.restartElectronServer();
globalThis.window.Actual.restartElectronServer();
}, []);

const [_documentDir, setDocumentDirPref] = useGlobalPref(
Expand All @@ -64,7 +64,7 @@ export function ConfirmChangeDocumentDirModal({
setLoading(true);
try {
if (moveFiles) {
await globalThis.window.Actual?.moveBudgetDirectory(
await globalThis.window.Actual.moveBudgetDirectory(
currentBudgetDirectory,
newDirectory,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function FileLocationSettings() {
const dispatch = useDispatch();

async function onChooseDocumentDir() {
const chosenDirectory = await window.Actual?.openFileDialog({
const chosenDirectory = await window.Actual.openFileDialog({
properties: ['openDirectory'],
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function ImportActualModal() {
const [importing, setImporting] = useState(false);

async function onImport() {
const res = await window.Actual?.openFileDialog({
const res = await window.Actual.openFileDialog({
properties: ['openFile'],
filters: [{ name: 'actual', extensions: ['zip', 'blob'] }],
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function ImportYNAB4Modal() {
const [importing, setImporting] = useState(false);

async function onImport() {
const res = await window.Actual?.openFileDialog({
const res = await window.Actual.openFileDialog({
properties: ['openFile'],
filters: [{ name: 'ynab', extensions: ['zip'] }],
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function ImportYNAB5Modal() {
const [importing, setImporting] = useState(false);

async function onImport() {
const res = await window.Actual?.openFileDialog({
const res = await window.Actual.openFileDialog({
properties: ['openFile'],
filters: [{ name: 'ynab', extensions: ['json'] }],
});
Expand Down
4 changes: 2 additions & 2 deletions packages/desktop-client/src/components/reports/Overview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -211,14 +211,14 @@ export function Overview() {
}),
} satisfies ExportImportDashboard;

window.Actual?.saveFile(
window.Actual.saveFile(
JSON.stringify(data, null, 2),
'dashboard.json',
'Export Dashboard',
);
};
const onImport = async () => {
const openFileDialog = window.Actual?.openFileDialog;
const openFileDialog = window.Actual.openFileDialog;

if (!openFileDialog) {
dispatch(
Expand Down
2 changes: 1 addition & 1 deletion packages/desktop-client/src/components/settings/Export.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function ExportBudget() {
return;
}

window.Actual?.saveFile(
window.Actual.saveFile(
response.data,
`${format(new Date(), 'yyyy-MM-dd')}-${budgetName}.zip`,
t('Export budget'),
Expand Down
2 changes: 1 addition & 1 deletion packages/desktop-client/src/components/settings/Reset.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState } from 'react';
import { Trans } from 'react-i18next';

import { resetSync } from 'loot-core/client/actions';
import { resetSync } from 'loot-core/client/app/appSlice';
import { send } from 'loot-core/src/platform/client/fetch';

import { useMetadataPref } from '../../hooks/useMetadataPref';
Expand Down
5 changes: 2 additions & 3 deletions packages/desktop-client/src/global-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import {
closeModal,
loadPrefs,
pushModal,
reloadApp,
replaceModal,
setAppState,
} from 'loot-core/client/actions';
import { setAppState } from 'loot-core/client/app/appSlice';
import {
getAccounts,
getCategories,
Expand Down Expand Up @@ -163,6 +162,6 @@ export function handleGlobalEvents(store: AppStore) {
});

listen('api-fetch-redirected', () => {
store.dispatch(reloadApp());
window.Actual.reload();
Copy link
Contributor Author

@joel-jeremy joel-jeremy Jan 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reloadApp just calls window.Actual.reload() so just call it directly instead of going through redux dispatch since it doesn't really affect the redux state

});
}
2 changes: 1 addition & 1 deletion packages/desktop-client/src/gocardless.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function _authorize(

if ('error' in resp) return resp;
const { link, requisitionId } = resp;
window.Actual?.openURLInBrowser(link);
window.Actual.openURLInBrowser(link);

return send('gocardless-poll-web-token', {
upgradingAccountId,
Expand Down
Loading
Loading