From 7227675320a91c9884f7149d47a084e7df114f30 Mon Sep 17 00:00:00 2001 From: Michael Kochell <6913320+mickmister@users.noreply.github.com> Date: Tue, 11 May 2021 12:32:49 -0400 Subject: [PATCH] Allow post option modal to close before opening app modal (#5383) * Allow post option modal to close before opening app modal * lint * revert commits 25ea111d9ab1441094de2b27e1af18a22d863a33 and c0d9e2128610eb02123ccd7362597fd0499d11be * wait for post options to close before kicking off request --- .../post_options/bindings/bindings.tsx | 84 ++++++++++--------- 1 file changed, 43 insertions(+), 41 deletions(-) diff --git a/app/screens/post_options/bindings/bindings.tsx b/app/screens/post_options/bindings/bindings.tsx index 800cc36f8..077de709b 100644 --- a/app/screens/post_options/bindings/bindings.tsx +++ b/app/screens/post_options/bindings/bindings.tsx @@ -22,7 +22,7 @@ type Props = { post: Post, currentUser: UserProfile, teamID: string, - closeWithAnimation: () => void, + closeWithAnimation: (cb?: () => void) => void, appsEnabled: boolean, intl: typeof intlShape, actions: { @@ -69,7 +69,7 @@ type OptionProps = { post: Post, currentUser: UserProfile, teamID: string, - closeWithAnimation: () => void, + closeWithAnimation: (cb?: () => void) => void, intl: typeof intlShape, actions: { doAppCall: DoAppCall; @@ -101,46 +101,48 @@ class Option extends React.PureComponent { }, ); - closeWithAnimation(); - const res = await doAppCall(call, AppCallTypes.SUBMIT, intl); - if (res.error) { - const errorResponse = res.error; - const title = intl.formatMessage({ - id: 'mobile.general.error.title', - defaultMessage: 'Error', - }); - const errorMessage = errorResponse.error || intl.formatMessage({ - id: 'apps.error.unknown', - defaultMessage: 'Unknown error occurred.', - }); - Alert.alert(title, errorMessage); - return; - } - - const callResp = (res as {data: AppCallResponse}).data; - switch (callResp.type) { - case AppCallResponseTypes.OK: - if (callResp.markdown) { - postEphemeralCallResponseForPost(callResp, callResp.markdown, post); + closeWithAnimation(async () => { + const callPromise = doAppCall(call, AppCallTypes.SUBMIT, intl); + const res = await callPromise; + if (res.error) { + const errorResponse = res.error; + const title = intl.formatMessage({ + id: 'mobile.general.error.title', + defaultMessage: 'Error', + }); + const errorMessage = errorResponse.error || intl.formatMessage({ + id: 'apps.error.unknown', + defaultMessage: 'Unknown error occurred.', + }); + Alert.alert(title, errorMessage); + return; } - break; - case AppCallResponseTypes.NAVIGATE: - case AppCallResponseTypes.FORM: - break; - default: { - const title = intl.formatMessage({ - id: 'mobile.general.error.title', - defaultMessage: 'Error', - }); - const errMessage = intl.formatMessage({ - id: 'apps.error.responses.unknown_type', - defaultMessage: 'App response type not supported. Response type: {type}.', - }, { - type: callResp.type, - }); - Alert.alert(title, errMessage); - } - } + + const callResp = (res as {data: AppCallResponse}).data; + switch (callResp.type) { + case AppCallResponseTypes.OK: + if (callResp.markdown) { + postEphemeralCallResponseForPost(callResp, callResp.markdown, post); + } + break; + case AppCallResponseTypes.NAVIGATE: + case AppCallResponseTypes.FORM: + break; + default: { + const title = intl.formatMessage({ + id: 'mobile.general.error.title', + defaultMessage: 'Error', + }); + const errMessage = intl.formatMessage({ + id: 'apps.error.responses.unknown_type', + defaultMessage: 'App response type not supported. Response type: {type}.', + }, { + type: callResp.type, + }); + Alert.alert(title, errMessage); + } + } + }); }; render() {