Restore undo-url-saving behavior (#1234)

This commit is contained in:
Jed Fox
2023-06-30 16:57:57 -04:00
committed by GitHub
parent e6d931729c
commit 3b3770d6b9
4 changed files with 23 additions and 5 deletions

View File

@@ -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 }}>

View File

@@ -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

View File

@@ -8,6 +8,6 @@ declare global {
openURLInBrowser: (url: string) => void;
};
__navigate?: ReturnType<import('react-router')['useNavigate']>;
__navigate?: import('react-router').NavigateFunction;
}
}

View File

@@ -0,0 +1,6 @@
---
category: Bugfix
authors: [j-f1]
---
Stop page from refreshing when undoing