Fix mobile page "back" behaviors (#1648)

* Fix mobile page "back" behaviors

* Release notes
This commit is contained in:
Joel Jeremy Marquez
2023-09-04 23:17:03 -07:00
committed by GitHub
parent 15ab80a475
commit cb00826f51
3 changed files with 28 additions and 18 deletions

View File

@@ -109,7 +109,7 @@ export default function AccountDetails({
}} }}
> >
<Link <Link
to="/accounts" to={-1}
style={{ style={{
color: theme.formLabelText, color: theme.formLabelText,
alignItems: 'center', alignItems: 'center',

View File

@@ -226,6 +226,7 @@ class TransactionEditInner extends PureComponent {
if (transactions.find(t => t.account == null)) { if (transactions.find(t => t.account == null)) {
// Ignore transactions if any of them don't have an account // Ignore transactions if any of them don't have an account
// TODO: Should we display validation error?
return; return;
} }
@@ -243,7 +244,7 @@ class TransactionEditInner extends PureComponent {
} }
this.props.onSave(transactions); this.props.onSave(transactions);
this.props.navigation(`/accounts/${account.id}`); this.props.navigate(`/accounts/${account.id}`, { replace: true });
}; };
onSaveChild = childTransaction => { onSaveChild = childTransaction => {
@@ -293,16 +294,22 @@ class TransactionEditInner extends PureComponent {
}); });
}; };
onDelete = () => {
this.props.onDelete();
const { transactions } = this.state;
const [transaction, ..._childTransactions] = transactions;
const { account: accountId } = transaction;
if (accountId) {
this.props.navigate(`/accounts/${accountId}`, { replace: true });
} else {
this.props.navigate(-1);
}
};
render() { render() {
const { const { adding, categories, accounts, payees, renderChildEdit, navigate } =
adding, this.props;
categories,
accounts,
payees,
renderChildEdit,
navigation,
onDelete,
} = this.props;
const { editingChild } = this.state; const { editingChild } = this.state;
const transactions = this.serializeTransactions( const transactions = this.serializeTransactions(
this.state.transactions || [], this.state.transactions || [],
@@ -374,7 +381,7 @@ class TransactionEditInner extends PureComponent {
}} }}
> >
<Link <Link
to={account ? `/accounts/${account.id}` : '/budget'} to={-1}
style={{ style={{
alignItems: 'center', alignItems: 'center',
display: 'flex', display: 'flex',
@@ -583,7 +590,7 @@ class TransactionEditInner extends PureComponent {
{!adding && ( {!adding && (
<View style={{ alignItems: 'center' }}> <View style={{ alignItems: 'center' }}>
<Button <Button
onClick={() => onDelete()} onClick={() => this.onDelete()}
style={{ style={{
borderWidth: 0, borderWidth: 0,
paddingVertical: 5, paddingVertical: 5,
@@ -662,7 +669,7 @@ class TransactionEditInner extends PureComponent {
editingChild && transactions.find(t => t.id === editingChild), editingChild && transactions.find(t => t.id === editingChild),
amountSign: forcedSign, amountSign: forcedSign,
getCategoryName: id => (id ? lookupName(categories, id) : null), getCategoryName: id => (id ? lookupName(categories, id) : null),
navigation: navigation, navigate: navigate,
onEdit: this.onEdit, onEdit: this.onEdit,
onStartClose: this.onSaveChild, onStartClose: this.onSaveChild,
})} })}
@@ -804,9 +811,6 @@ function TransactionEditUnconnected(props) {
}; };
const onDelete = async () => { const onDelete = async () => {
// Eagerly go back
navigate(`/accounts/${accountId}`);
if (adding) { if (adding) {
// Adding a new transactions, this disables saving when the component unmounts // Adding a new transactions, this disables saving when the component unmounts
deleted = true; deleted = true;
@@ -833,7 +837,7 @@ function TransactionEditUnconnected(props) {
accounts={accounts} accounts={accounts}
payees={payees} payees={payees}
pushModal={props.pushModal} pushModal={props.pushModal}
navigation={navigate} navigate={navigate}
// TODO: ChildEdit is complicated and heavily relies on RN // TODO: ChildEdit is complicated and heavily relies on RN
// renderChildEdit={props => <ChildEdit {...props} />} // renderChildEdit={props => <ChildEdit {...props} />}
renderChildEdit={props => {}} renderChildEdit={props => {}}

View File

@@ -0,0 +1,6 @@
---
category: Enhancements
authors: [joel-jeremy]
---
Fix mobile pages "back" behaviors.