Skip to content
Snippets Groups Projects
Unverified Commit 3b3770d6 authored by Jed Fox's avatar Jed Fox Committed by GitHub
Browse files

Restore undo-url-saving behavior (#1234)

parent e6d93172
No related branches found
No related tags found
No related merge requests found
...@@ -14,6 +14,8 @@ import { ...@@ -14,6 +14,8 @@ import {
NavLink, NavLink,
useNavigate, useNavigate,
BrowserRouter, BrowserRouter,
useLocation,
useHref,
} from 'react-router-dom'; } from 'react-router-dom';
import hotkeys from 'hotkeys-js'; import hotkeys from 'hotkeys-js';
...@@ -23,6 +25,7 @@ import { AccountsProvider } from 'loot-core/src/client/data-hooks/accounts'; ...@@ -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 { PayeesProvider } from 'loot-core/src/client/data-hooks/payees';
import { SpreadsheetProvider } from 'loot-core/src/client/SpreadsheetProvider'; import { SpreadsheetProvider } from 'loot-core/src/client/SpreadsheetProvider';
import checkForUpdateNotification from 'loot-core/src/client/update-notification'; 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 Cog from '../icons/v1/Cog';
import PiggyBank from '../icons/v1/PiggyBank'; import PiggyBank from '../icons/v1/PiggyBank';
...@@ -204,7 +207,7 @@ function MobileNavTabs() { ...@@ -204,7 +207,7 @@ function MobileNavTabs() {
); );
} }
function Redirector({ getAccounts }) { function RouterBehaviors({ getAccounts }) {
let navigate = useNavigate(); let navigate = useNavigate();
useEffect(() => { useEffect(() => {
// Get the accounts and check if any exist. If there are no // Get the accounts and check if any exist. If there are no
...@@ -216,6 +219,12 @@ function Redirector({ getAccounts }) { ...@@ -216,6 +219,12 @@ function Redirector({ getAccounts }) {
} }
}); });
}, []); }, []);
let location = useLocation();
let href = useHref(location);
useEffect(() => {
undo.setUndoState('url', href);
}, [href]);
} }
function FinancesApp(props) { function FinancesApp(props) {
...@@ -240,7 +249,7 @@ function FinancesApp(props) { ...@@ -240,7 +249,7 @@ function FinancesApp(props) {
return ( return (
<BrowserRouter> <BrowserRouter>
<Redirector getAccounts={props.getAccounts} /> <RouterBehaviors getAccounts={props.getAccounts} />
<ExposeNavigate /> <ExposeNavigate />
<View style={{ height: '100%', backgroundColor: colors.n10 }}> <View style={{ height: '100%', backgroundColor: colors.n10 }}>
......
...@@ -112,8 +112,11 @@ export function handleGlobalEvents(actions, store) { ...@@ -112,8 +112,11 @@ export function handleGlobalEvents(actions, store) {
} else { } else {
actions.closeModal(); actions.closeModal();
if (window.location.href !== tagged.url) { if (
window.location.href = tagged.url; window.location.href.replace(window.location.origin, '') !==
tagged.url
) {
window.__navigate(tagged.url);
// This stops propagation of the undo event, which is // This stops propagation of the undo event, which is
// important because if we are changing URLs any existing // important because if we are changing URLs any existing
// undo listeners on the current page don't need to be run // undo listeners on the current page don't need to be run
......
...@@ -8,6 +8,6 @@ declare global { ...@@ -8,6 +8,6 @@ declare global {
openURLInBrowser: (url: string) => void; openURLInBrowser: (url: string) => void;
}; };
__navigate?: ReturnType<import('react-router')['useNavigate']>; __navigate?: import('react-router').NavigateFunction;
} }
} }
---
category: Bugfix
authors: [j-f1]
---
Stop page from refreshing when undoing
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment