diff options
author | Paul Frazee <pfrazee@gmail.com> | 2023-06-27 11:01:25 -0500 |
---|---|---|
committer | Paul Frazee <pfrazee@gmail.com> | 2023-06-27 11:01:25 -0500 |
commit | 0f9429605d9d8607df46512482446a524222bac6 (patch) | |
tree | 4fbe926aced978253c0706dbb78ed33e82dd5805 /src | |
parent | a8bbaa06c7266c73f6a71b5e9223c11c96995947 (diff) | |
parent | 2e082b6977e11832ce648e67c52b68a8cc824966 (diff) | |
download | voidsky-0f9429605d9d8607df46512482446a524222bac6.tar.zst |
Merge branch 'skip-confirmation-for-empty-post' of https://github.com/benharri-forks/social-app into benharri-forks-skip-confirmation-for-empty-post
Diffstat (limited to 'src')
-rw-r--r-- | src/view/com/composer/Composer.tsx | 51 |
1 files changed, 28 insertions, 23 deletions
diff --git a/src/view/com/composer/Composer.tsx b/src/view/com/composer/Composer.tsx index 4c73e58bf..fc324d3e5 100644 --- a/src/view/com/composer/Composer.tsx +++ b/src/view/com/composer/Composer.tsx @@ -82,7 +82,7 @@ export const ComposePost = observer(function ComposePost({ // HACK // there's a bug with @mattermost/react-native-paste-input where if the input - // is focused during unmount, an exception will throw (seems that a blur method isnt implemented) + // is focused during unmount, an exception will throw (seems that a blur method isn't implemented) // manually blurring before closing gets around that // -prf const hackfixOnClose = useCallback(() => { @@ -90,6 +90,27 @@ export const ComposePost = observer(function ComposePost({ onClose() }, [textInput, onClose]) + const onPressCancel = useCallback(() => { + if (graphemeLength > 0 || !gallery.isEmpty) { + if (store.shell.activeModals.some(modal => modal.name === 'confirm')) { + store.shell.closeModal() + } + store.shell.openModal({ + name: 'confirm', + title: 'Discard draft', + onPressConfirm: hackfixOnClose, + onPressCancel: () => { + store.shell.closeModal() + }, + message: "Are you sure you'd like to discard this draft?", + confirmBtnText: 'Discard', + confirmBtnStyle: {backgroundColor: colors.red4}, + }) + } else { + hackfixOnClose() + } + }, [store, hackfixOnClose, graphemeLength, gallery]) + // initial setup useEffect(() => { autocompleteView.setup() @@ -99,26 +120,10 @@ export const ComposePost = observer(function ComposePost({ const onEscape = useCallback( (e: KeyboardEvent) => { if (e.key === 'Escape') { - const {shell} = store - - if (shell.activeModals.some(modal => modal.name === 'confirm')) { - store.shell.closeModal() - } - - shell.openModal({ - name: 'confirm', - title: 'Discard draft', - onPressConfirm: onClose, - onPressCancel: () => { - store.shell.closeModal() - }, - message: "Are you sure you'd like to discard this draft?", - confirmBtnText: 'Discard', - confirmBtnStyle: {backgroundColor: colors.red4}, - }) + onPressCancel() } }, - [store, onClose], + [onPressCancel], ) useEffect(() => { if (isDesktopWeb) { @@ -137,7 +142,7 @@ export const ComposePost = observer(function ComposePost({ const onPhotoPasted = useCallback( async (uri: string) => { track('Composer:PastedPhotos') - gallery.paste(uri) + await gallery.paste(uri) }, [gallery, track], ) @@ -187,7 +192,7 @@ export const ComposePost = observer(function ComposePost({ if (replyTo && replyTo.uri) track('Post:Reply') } if (!replyTo) { - store.me.mainFeed.addPostToTop(createdPost.uri) + await store.me.mainFeed.addPostToTop(createdPost.uri) } onPost?.() hackfixOnClose() @@ -227,8 +232,8 @@ export const ComposePost = observer(function ComposePost({ <View style={styles.topbar}> <TouchableOpacity testID="composerDiscardButton" - onPress={hackfixOnClose} - onAccessibilityEscape={hackfixOnClose} + onPress={onPressCancel} + onAccessibilityEscape={onPressCancel} accessibilityRole="button" accessibilityLabel="Discard" accessibilityHint="Closes post composer and discards post draft"> |