Skip to content

A local-first personal finance app

Restore undo-url-saving behavior (#1234)

Jed Fox3b3770d6b984
diff --git a/packages/desktop-client/src/components/FinancesApp.js b/packages/desktop-client/src/components/FinancesApp.js
index 3de4d8aed4..84d2be1a2f 100644
--- a/packages/desktop-client/src/components/FinancesApp.js
+++ b/packages/desktop-client/src/components/FinancesApp.js
@@ -14,6 +14,8 @@ import {
NavLink,
useNavigate,
BrowserRouter,
+ useLocation,
+ useHref,
} from 'react-router-dom';
import hotkeys from 'hotkeys-js';
@@ -23,6 +25,7 @@ import { AccountsProvider } from 'loot-core/src/client/data-hooks/accounts';
import { PayeesProvider } from 'loot-core/src/client/data-hooks/payees';
import { SpreadsheetProvider } from 'loot-core/src/client/SpreadsheetProvider';
import checkForUpdateNotification from 'loot-core/src/client/update-notification';
+import * as undo from 'loot-core/src/platform/client/undo';
import Cog from '../icons/v1/Cog';
import PiggyBank from '../icons/v1/PiggyBank';
@@ -204,7 +207,7 @@ function MobileNavTabs() {
);
}
-function Redirector({ getAccounts }) {
+function RouterBehaviors({ getAccounts }) {
let navigate = useNavigate();
useEffect(() => {
// Get the accounts and check if any exist. If there are no
@@ -216,6 +219,12 @@ function Redirector({ getAccounts }) {
}
});
}, []);
+
+ let location = useLocation();
+ let href = useHref(location);
+ useEffect(() => {
+ undo.setUndoState('url', href);
+ }, [href]);
}
function FinancesApp(props) {
@@ -240,7 +249,7 @@ function FinancesApp(props) {
return (
<BrowserRouter>
- <Redirector getAccounts={props.getAccounts} />
+ <RouterBehaviors getAccounts={props.getAccounts} />
<ExposeNavigate />
<View style={{ height: '100%', backgroundColor: colors.n10 }}>
diff --git a/packages/desktop-client/src/global-events.js b/packages/desktop-client/src/global-events.js
index 0597454403..7b3427153c 100644
--- a/packages/desktop-client/src/global-events.js
+++ b/packages/desktop-client/src/global-events.js
@@ -112,8 +112,11 @@ export function handleGlobalEvents(actions, store) {
} else {
actions.closeModal();
- if (window.location.href !== tagged.url) {
- window.location.href = tagged.url;
+ if (
+ window.location.href.replace(window.location.origin, '') !==
+ tagged.url
+ ) {
+ window.__navigate(tagged.url);
// This stops propagation of the undo event, which is
// important because if we are changing URLs any existing
// undo listeners on the current page don't need to be run
diff --git a/packages/loot-core/typings/window.d.ts b/packages/loot-core/typings/window.d.ts
index 3eea72bc6d..989f2ac5ff 100644
--- a/packages/loot-core/typings/window.d.ts
+++ b/packages/loot-core/typings/window.d.ts
@@ -8,6 +8,6 @@ declare global {
openURLInBrowser: (url: string) => void;
};
- __navigate?: ReturnType<import('react-router')['useNavigate']>;
+ __navigate?: import('react-router').NavigateFunction;
}
}
diff --git a/upcoming-release-notes/1234.md b/upcoming-release-notes/1234.md
new file mode 100644
index 0000000000..128c15a662
--- /dev/null
+++ b/upcoming-release-notes/1234.md
@@ -0,0 +1,6 @@
+---
+category: Bugfix
+authors: [j-f1]
+---
+
+Stop page from refreshing when undoing