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
Closed
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
19 changes: 17 additions & 2 deletions src/nav/navActions.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @flow strict-local */
import { StackActions } from 'react-navigation';
import { cancelEditMessage } from '../session/sessionActions';

import type {
Dispatch,
Expand All @@ -10,10 +11,24 @@ import type {
UserOrBot,
ApiResponseServerSettings,
} from '../types';

import type { Action } from '../actionTypes';
import { getSameRoutesCount } from '../selectors';

export const navigateBack = () => (dispatch: Dispatch, getState: GetState): NavigationAction =>
dispatch(StackActions.pop({ n: getSameRoutesCount(getState()) }));
export const navigateBack = () => (
dispatch: Dispatch,
getState: GetState,
): NavigationAction | Action => {
/**
* If a message is currently being edited, cancel the edit. Otherwise,
* navigate back.
*/
Comment on lines +22 to +25
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.)

if (getState().session.editMessage) {
return dispatch(cancelEditMessage());
} else {
return dispatch(StackActions.pop({ n: getSameRoutesCount(getState()) }));
}
};

// Other stack routes reached through `navReducer`:
// StackActions.push({ routeName: 'loading' });
Expand Down