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

[WIP] 🐛 (mobile) fix missing navigation back when updating transactions #2964

Closed
wants to merge 6 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ const TransactionEditInner = memo(function TransactionEditInner({
}

props.onSave(transactionsToSave);
navigate(`/accounts/${account.id}`, { replace: true });
navigate(`/accounts/${account.id}`);
};

if (unserializedTransaction.reconciled) {
Expand Down
42 changes: 1 addition & 41 deletions packages/desktop-client/src/hooks/useNavigate.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,8 @@
import { useCallback } from 'react';
import {
type Location,
type NavigateFunction,
type NavigateOptions,
type To,
useLocation,
useNavigate as useNavigateReactRouter,
} from 'react-router-dom';

export 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,
},
};

const { previousLocation, ...previousOriginalState } =
location.state || {};

if (
previousLocation == null ||
!isSamePath(to, previousLocation) ||
JSON.stringify(options?.state || {}) !==
JSON.stringify(previousOriginalState)
) {
navigate(to, optionsWithPrevLocation);
}
}
},
[navigate, location],
);
}

function isSamePath(to: To, location: Location) {
return to === location.pathname + location.search + location.hash;
return useNavigateReactRouter();
}
6 changes: 6 additions & 0 deletions upcoming-release-notes/2964.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Bugfix
authors: [MatissJanis]
---

Fix: updating transactions in mobile has no feedback (missing navigation back after button click).
Loading