forked from actualbudget/actual
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Custom useNavigate which tracks previous location (actualbudget#1808)
* Custom useNavigate which tracks previous location * Release notes * Fix lint errors
- Loading branch information
1 parent
041a7af
commit 158e670
Showing
21 changed files
with
86 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/desktop-client/src/components/accounts/MobileAccounts.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/desktop-client/src/components/manager/ConfigServer.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/desktop-client/src/components/manager/subscribe/ChangePassword.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
packages/desktop-client/src/components/manager/subscribe/Error.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
packages/desktop-client/src/components/manager/subscribe/common.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/desktop-client/src/components/modals/CreateLocalAccount.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/desktop-client/src/components/payees/ManagePayeesPage.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { useCallback } from 'react'; | ||
import { | ||
type Location, | ||
type NavigateFunction, | ||
type NavigateOptions, | ||
type To, | ||
useLocation, | ||
useNavigate as useNavigateReactRouter, | ||
} from 'react-router-dom'; | ||
|
||
export default function useNavigate(): NavigateFunction { | ||
const location = useLocation(); | ||
const navigate = useNavigateReactRouter(); | ||
return useCallback( | ||
(to: To | number, options: NavigateOptions = {}) => { | ||
if (typeof to === 'number') { | ||
navigate(to); | ||
} else { | ||
const optionsWithPrevLocation: NavigateOptions = { | ||
replace: | ||
options.replace || isSamePath(to, location) ? true : undefined, | ||
...options, | ||
state: { | ||
...options?.state, | ||
previousLocation: location, | ||
}, | ||
}; | ||
|
||
let { previousLocation, ...previousOriginalState } = | ||
location.state || {}; | ||
|
||
if ( | ||
previousLocation == null || | ||
!isSamePath(to, previousLocation) || | ||
JSON.stringify(options?.state || {}) !== | ||
JSON.stringify(previousOriginalState) | ||
) { | ||
navigate(to, optionsWithPrevLocation); | ||
} else { | ||
// `to` is the same as the previous location. Just go back. | ||
navigate(-1); | ||
} | ||
} | ||
}, | ||
[navigate, location], | ||
); | ||
} | ||
|
||
function isSamePath(to: To, location: Location) { | ||
return to === location.pathname + location.search + location.hash; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
category: Bugfix | ||
authors: [joel-jeremy] | ||
--- | ||
|
||
Fix flaky mobile back button on account transactions. |