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

edit message : allow cancellation of edit #3823

Closed
wants to merge 1 commit into from

Conversation

agrawal-d
Copy link
Member

@agrawal-d agrawal-d commented Jan 18, 2020

Fixes #2757

Before:
old

Now:
now

@agrawal-d agrawal-d requested a review from gnprice January 18, 2020 12:46
@agrawal-d
Copy link
Member Author

agrawal-d commented Jan 18, 2020

@gnprice @ray-kraesig please review.

Copy link
Contributor

@rk-for-zulip rk-for-zulip left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(The commit summary and message also need to be updated to refer to #2757. It does fix that bug, as the videos show.)

export const navigateBack = () => (dispatch: Dispatch, getState: GetState): NavigationAction =>
dispatch(StackActions.pop({ n: getSameRoutesCount(getState()) }));
export const navigateBack = () => (dispatch: Dispatch, getState: GetState): NavigationAction => {
dispatch(cancelEditMessage());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will call cancelEditMessage on every attempted back navigation, not just the ones where it's relevant. That's a huge hack. Calling this function should be limited to when the user is actually in the edit-message state.

Also, preferably, hitting back in that context should exit the "edit message" state, but not the current narrow.

(#2757 is pretty bad misbehavior, so I wouldn't be completely unwilling to accept such a hack, but it would need to be very well-documented – at the very least, a) here, b) at cancelEditMessage itself, and c) at any existing reducers for this dispatch. However, it's easy to check the relevant condition even from here, so that's a moot point.

Checking it here is still a hack that needs documenting, and one I expect we'll have issues with when we upgrade react-navigation; but that's going to require rethinking a number of things anyway.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!

@agrawal-d
Copy link
Member Author

eidt-message-cancel
Pushed some changes. @ray-kraesig please review.

@agrawal-d agrawal-d changed the title edit message : fix appbar title on discarding edit edit message : allow cancellation of edit Jan 21, 2020
@rk-for-zulip
Copy link
Contributor

As noted previously, both the code and the commit need documentation: the former in comments, the latter in the commit summary.

@agrawal-d
Copy link
Member Author

agrawal-d commented Jan 24, 2020

@ray-kraesig have made the requested changes. Please review, thanks.

It is not possible to cancel editing a message. Fix that to
allow message edit cancellation on back navigation attempt.

Fixes zulip#2757.
Comment on lines +22 to +25
/**
* If a message is currently being edited, cancel the edit. Otherwise,
* navigate back.
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code change below is very much a hack.

Its associated comment should thus start with HACK: , or some similar marker of grave concern, and then continue with what the right thing to do is (or is believed to be) and why this has been done here instead of that there. Similarly, some documentation of this hack's existence should be present in ComposeBox, ActionSheet, and/or some other component responsible for the edit message state.

(Also, this is function-documentation-style comment formatting [0] [1] [2], rather than ordinary comment formatting.)

@agrawal-d
Copy link
Member Author

agrawal-d commented Jan 25, 2020

@ray-kraesig, When you mentioned

what the right thing to do is (or is believed to be) and why this has been done here instead of that there.

I looked at other locations where we could dispatch cancelEditMessage().
If my suggested change is a hack, then why not make the proper change instead.

I think that the change can be instead made in the following places, to check if an edit is in progress, and cancel it, instead of navigating back:

  • In chatNavBar's onPress handler.
  • In backNavigationHandler's handleBackButtonPress().

So, should I revert changes in navActions.js and make changes in the above-mentioned files instead?
If yes, would comments explaining the code be required there too?

If not, I can not think of an answer to why this has been done here instead of that there and will heed your help in answering that. Thanks!

@rk-for-zulip
Copy link
Contributor

I think that the change can be instead made in the following places, to check if an edit is in progress, and cancel it, instead of navigating back:

  • In chatNavBar's onPress handler.
  • In backNavigationHandler's handleBackButtonPress().

This would be strictly worse. Instead of one component that shouldn't know anything about editing checking our editing state, we'd have two disconnected components that shouldn't know anything about editing checking our editing state.

The right thing to do will be some form of making editing affect our navigation state (which is designed to allow other components to affect it), rather than making navigation affect our editing state (which should be entirely local to the editing components).

However...

If not, I can not think of an answer to why this has been done here instead of that there and will heed your help in answering that. Thanks!

... in retrospect, this is not something that should be asked of a new contributor. Unfortunately, it's the most important part of a patch like this.

Closing. (I'll try to ensure this PR is referenced if we end up with a temporary fix similar to this.)

@agrawal-d agrawal-d deleted the edit-message branch May 13, 2020 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot cancel editing a message
2 participants