From f913819b796751fd88882c1ae435d6a66bcbbf2b Mon Sep 17 00:00:00 2001 From: Elias Nahum Date: Sun, 1 Jan 2023 22:54:04 +0200 Subject: [PATCH] Dismiss correct bottom sheet screen for post / thread options (#6919) --- .../copy_permalink_option.tsx | 7 +++-- .../follow_thread_option.tsx | 11 ++++--- .../common_post_options/reply_option.tsx | 8 ++--- .../common_post_options/save_option.tsx | 7 +++-- .../options/app_bindings_post_option.tsx | 7 +++-- .../post_options/options/copy_text_option.tsx | 5 +-- .../options/delete_post_option.tsx | 7 +++-- .../post_options/options/edit_option.tsx | 7 +++-- .../mark_unread_option/mark_unread_option.tsx | 7 +++-- .../options/pin_channel_option.tsx | 7 +++-- app/screens/post_options/post_options.tsx | 31 ++++++++++++++++--- .../reaction_bar/reaction_bar.tsx | 11 ++++--- .../options/mark_as_unread_option.tsx | 7 +++-- .../options/open_in_channel_option.tsx | 7 +++-- app/screens/thread_options/thread_options.tsx | 11 +++++-- 15 files changed, 89 insertions(+), 51 deletions(-) diff --git a/app/components/common_post_options/copy_permalink_option/copy_permalink_option.tsx b/app/components/common_post_options/copy_permalink_option/copy_permalink_option.tsx index 49afc06697..8ba0ee61d0 100644 --- a/app/components/common_post_options/copy_permalink_option/copy_permalink_option.tsx +++ b/app/components/common_post_options/copy_permalink_option/copy_permalink_option.tsx @@ -15,19 +15,20 @@ import {showSnackBar} from '@utils/snack_bar'; import type PostModel from '@typings/database/models/servers/post'; type Props = { + bottomSheetId: typeof Screens[keyof typeof Screens]; sourceScreen: typeof Screens[keyof typeof Screens]; post: PostModel; teamName: string; } -const CopyPermalinkOption = ({teamName, post, sourceScreen}: Props) => { +const CopyPermalinkOption = ({bottomSheetId, teamName, post, sourceScreen}: Props) => { const serverUrl = useServerUrl(); const handleCopyLink = useCallback(async () => { const permalink = `${serverUrl}/${teamName}/pl/${post.id}`; Clipboard.setString(permalink); - await dismissBottomSheet(Screens.POST_OPTIONS); + await dismissBottomSheet(bottomSheetId); showSnackBar({barType: SNACK_BAR_TYPE.LINK_COPIED, sourceScreen}); - }, [teamName, post.id]); + }, [teamName, post.id, bottomSheetId]); return ( { +const FollowThreadOption = ({bottomSheetId, thread, teamId}: FollowThreadOptionProps) => { let id: string; let defaultMessage: string; let icon: string; @@ -44,13 +45,13 @@ const FollowThreadOption = ({thread, teamId}: FollowThreadOptionProps) => { const serverUrl = useServerUrl(); - const handleToggleFollow = async () => { + const handleToggleFollow = useCallback(async () => { if (teamId == null) { return; } - await dismissBottomSheet(Screens.POST_OPTIONS); + await dismissBottomSheet(bottomSheetId); updateThreadFollowing(serverUrl, teamId, thread.id, !thread.isFollowing); - }; + }, [bottomSheetId, teamId, thread]); const followThreadOptionTestId = thread.isFollowing ? 'post_options.following_thread.option' : 'post_options.follow_thread.option'; diff --git a/app/components/common_post_options/reply_option.tsx b/app/components/common_post_options/reply_option.tsx index fc912f733b..6afa518792 100644 --- a/app/components/common_post_options/reply_option.tsx +++ b/app/components/common_post_options/reply_option.tsx @@ -14,16 +14,16 @@ import type PostModel from '@typings/database/models/servers/post'; type Props = { post: PostModel; - location?: typeof Screens[keyof typeof Screens]; + bottomSheetId: typeof Screens[keyof typeof Screens]; } -const ReplyOption = ({post, location}: Props) => { +const ReplyOption = ({post, bottomSheetId}: Props) => { const serverUrl = useServerUrl(); const handleReply = useCallback(async () => { const rootId = post.rootId || post.id; - await dismissBottomSheet(location || Screens.POST_OPTIONS); + await dismissBottomSheet(bottomSheetId); fetchAndSwitchToThread(serverUrl, rootId); - }, [post, serverUrl]); + }, [bottomSheetId, post, serverUrl]); return ( { +const SaveOption = ({bottomSheetId, isSaved, postId}: CopyTextProps) => { const serverUrl = useServerUrl(); const onHandlePress = useCallback(async () => { const remoteAction = isSaved ? deleteSavedPost : savePostPreference; - await dismissBottomSheet(Screens.POST_OPTIONS); + await dismissBottomSheet(bottomSheetId); remoteAction(serverUrl, postId); - }, [postId, serverUrl]); + }, [bottomSheetId, postId, serverUrl]); const id = isSaved ? t('mobile.post_info.unsave') : t('mobile.post_info.save'); const defaultMessage = isSaved ? 'Unsave' : 'Save'; diff --git a/app/screens/post_options/options/app_bindings_post_option.tsx b/app/screens/post_options/options/app_bindings_post_option.tsx index 43064f1029..0157ef9a93 100644 --- a/app/screens/post_options/options/app_bindings_post_option.tsx +++ b/app/screens/post_options/options/app_bindings_post_option.tsx @@ -21,13 +21,14 @@ import {preventDoubleTap} from '@utils/tap'; import type PostModel from '@typings/database/models/servers/post'; type Props = { + bottomSheetId: typeof Screens[keyof typeof Screens]; bindings: AppBinding[]; post: PostModel; serverUrl: string; teamId: string; } -const AppBindingsPostOptions = ({serverUrl, post, teamId, bindings}: Props) => { +const AppBindingsPostOptions = ({bottomSheetId, serverUrl, post, teamId, bindings}: Props) => { const onCallResponse = useCallback((callResp: AppCallResponse, message: string) => { postEphemeralCallResponseForPost(serverUrl, callResp, message, post); }, [serverUrl, post]); @@ -48,11 +49,11 @@ const AppBindingsPostOptions = ({serverUrl, post, teamId, bindings}: Props) => { const onPress = useCallback(async (binding: AppBinding) => { const submitPromise = handleBindingSubmit(binding); - await dismissBottomSheet(Screens.POST_OPTIONS); + await dismissBottomSheet(bottomSheetId); const finish = await submitPromise; await finish(); - }, [handleBindingSubmit]); + }, [bottomSheetId, handleBindingSubmit]); if (isSystemMessage(post)) { return null; diff --git a/app/screens/post_options/options/copy_text_option.tsx b/app/screens/post_options/options/copy_text_option.tsx index f1570b50fd..7662ebbd5e 100644 --- a/app/screens/post_options/options/copy_text_option.tsx +++ b/app/screens/post_options/options/copy_text_option.tsx @@ -12,12 +12,13 @@ import {dismissBottomSheet} from '@screens/navigation'; import {showSnackBar} from '@utils/snack_bar'; type Props = { + bottomSheetId: typeof Screens[keyof typeof Screens]; sourceScreen: typeof Screens[keyof typeof Screens]; postMessage: string; } -const CopyTextOption = ({postMessage, sourceScreen}: Props) => { +const CopyTextOption = ({bottomSheetId, postMessage, sourceScreen}: Props) => { const handleCopyText = useCallback(async () => { - await dismissBottomSheet(Screens.POST_OPTIONS); + await dismissBottomSheet(bottomSheetId); Clipboard.setString(postMessage); showSnackBar({barType: SNACK_BAR_TYPE.MESSAGE_COPIED, sourceScreen}); }, [postMessage]); diff --git a/app/screens/post_options/options/delete_post_option.tsx b/app/screens/post_options/options/delete_post_option.tsx index 95ae35f3c7..6ef2e478db 100644 --- a/app/screens/post_options/options/delete_post_option.tsx +++ b/app/screens/post_options/options/delete_post_option.tsx @@ -15,10 +15,11 @@ import {dismissBottomSheet} from '@screens/navigation'; import type PostModel from '@typings/database/models/servers/post'; type Props = { + bottomSheetId: typeof Screens[keyof typeof Screens]; combinedPost?: Post | PostModel; post: PostModel; } -const DeletePostOption = ({combinedPost, post}: Props) => { +const DeletePostOption = ({bottomSheetId, combinedPost, post}: Props) => { const serverUrl = useServerUrl(); const {formatMessage} = useIntl(); @@ -36,12 +37,12 @@ const DeletePostOption = ({combinedPost, post}: Props) => { text: formatMessage({id: 'post_info.del', defaultMessage: 'Delete'}), style: 'destructive', onPress: async () => { - await dismissBottomSheet(Screens.POST_OPTIONS); + await dismissBottomSheet(bottomSheetId); deletePost(serverUrl, combinedPost || post); }, }], ); - }, [post, combinedPost, serverUrl]); + }, [bottomSheetId, post, combinedPost, serverUrl]); return ( { +const EditOption = ({bottomSheetId, post, canDelete}: Props) => { const intl = useIntl(); const theme = useTheme(); const onPress = useCallback(async () => { - await dismissBottomSheet(Screens.POST_OPTIONS); + await dismissBottomSheet(bottomSheetId); const title = intl.formatMessage({id: 'mobile.edit_post.title', defaultMessage: 'Editing Message'}); const closeButton = CompassIcon.getImageSourceSync('close', 24, theme.sidebarHeaderTextColor); @@ -38,7 +39,7 @@ const EditOption = ({post, canDelete}: Props) => { }, }; showModal(Screens.EDIT_POST, title, passProps, options); - }, [post]); + }, [bottomSheetId, post]); return ( { +const MarkAsUnreadOption = ({bottomSheetId, isCRTEnabled, sourceScreen, post, teamId}: Props) => { const serverUrl = useServerUrl(); const onPress = useCallback(async () => { - await dismissBottomSheet(Screens.POST_OPTIONS); + await dismissBottomSheet(bottomSheetId); if (sourceScreen === Screens.THREAD && isCRTEnabled) { const threadId = post.rootId || post.id; markThreadAsUnread(serverUrl, teamId, threadId, post.id); } else { markPostAsUnread(serverUrl, post.id); } - }, [sourceScreen, post, serverUrl, teamId]); + }, [bottomSheetId, sourceScreen, post, serverUrl, teamId]); return ( { +const PinChannelOption = ({bottomSheetId, isPostPinned, postId}: PinChannelProps) => { const serverUrl = useServerUrl(); const onPress = useCallback(async () => { - await dismissBottomSheet(Screens.POST_OPTIONS); + await dismissBottomSheet(bottomSheetId); togglePinPost(serverUrl, postId); - }, [postId, serverUrl]); + }, [bottomSheetId, postId, serverUrl]); let defaultMessage; let id; diff --git a/app/screens/post_options/post_options.tsx b/app/screens/post_options/post_options.tsx index c14a9e73dd..f783c2eb08 100644 --- a/app/screens/post_options/post_options.tsx +++ b/app/screens/post_options/post_options.tsx @@ -9,7 +9,7 @@ import {ITEM_HEIGHT} from '@components/option_item'; import {Screens} from '@constants'; import useNavButtonPressed from '@hooks/navigation_button_pressed'; import BottomSheet from '@screens/bottom_sheet'; -import {dismissModal} from '@screens/navigation'; +import {dismissBottomSheet} from '@screens/navigation'; import {isSystemMessage} from '@utils/post'; import AppBindingsPostOptions from './options/app_bindings_post_option'; @@ -50,7 +50,7 @@ const PostOptions = ({ const managedConfig = useManagedConfig(); const close = () => { - dismissModal({componentId}); + return dismissBottomSheet(Screens.POST_OPTIONS); }; useNavButtonPressed(POST_OPTIONS_BUTTON, componentId, close, []); @@ -74,53 +74,74 @@ const PostOptions = ({ const renderContent = () => { return ( <> - {canAddReaction && } - {canReply && sourceScreen !== Screens.THREAD && } + {canAddReaction && + + } + {canReply && sourceScreen !== Screens.THREAD && + + } {shouldRenderFollow && - + } {canMarkAsUnread && !isSystemPost && } {canCopyPermalink && } {!isSystemPost && } {Boolean(canCopyText && post.message) && } {canPin && } {canEdit && } {canDelete && } {shouldShowBindings && { }; }); -const ReactionBar = ({recentEmojis = [], postId}: QuickReactionProps) => { +const ReactionBar = ({bottomSheetId, recentEmojis = [], postId}: QuickReactionProps) => { const theme = useTheme(); const intl = useIntl(); const {width} = useWindowDimensions(); @@ -54,12 +55,12 @@ const ReactionBar = ({recentEmojis = [], postId}: QuickReactionProps) => { const isTablet = useIsTablet(); const handleEmojiPress = useCallback(async (emoji: string) => { - await dismissBottomSheet(Screens.POST_OPTIONS); + await dismissBottomSheet(bottomSheetId); addReaction(serverUrl, postId, emoji); - }, [postId, serverUrl]); + }, [bottomSheetId, postId, serverUrl]); const openEmojiPicker = useCallback(async () => { - await dismissBottomSheet(Screens.POST_OPTIONS); + await dismissBottomSheet(bottomSheetId); const closeButton = CompassIcon.getImageSourceSync('close', 24, theme.sidebarHeaderTextColor); const screen = Screens.EMOJI_PICKER; @@ -67,7 +68,7 @@ const ReactionBar = ({recentEmojis = [], postId}: QuickReactionProps) => { const passProps = {closeButton, onEmojiPress: handleEmojiPress}; showModal(screen, title, passProps); - }, [intl, theme]); + }, [bottomSheetId, intl, theme]); let containerSize = LARGE_CONTAINER_SIZE; let iconSize = LARGE_ICON_SIZE; diff --git a/app/screens/thread_options/options/mark_as_unread_option.tsx b/app/screens/thread_options/options/mark_as_unread_option.tsx index 225f55d26d..9cc462d2ed 100644 --- a/app/screens/thread_options/options/mark_as_unread_option.tsx +++ b/app/screens/thread_options/options/mark_as_unread_option.tsx @@ -13,20 +13,21 @@ import {dismissBottomSheet} from '@screens/navigation'; import type ThreadModel from '@typings/database/models/servers/thread'; type Props = { + bottomSheetId: typeof Screens[keyof typeof Screens]; teamId: string; thread: ThreadModel; } -const MarkAsUnreadOption = ({teamId, thread}: Props) => { +const MarkAsUnreadOption = ({bottomSheetId, teamId, thread}: Props) => { const serverUrl = useServerUrl(); const onHandlePress = useCallback(async () => { - await dismissBottomSheet(Screens.THREAD_OPTIONS); + await dismissBottomSheet(bottomSheetId); if (thread.unreadReplies) { markThreadAsRead(serverUrl, teamId, thread.id); } else { markThreadAsUnread(serverUrl, teamId, thread.id, thread.id); } - }, [serverUrl, teamId, thread]); + }, [bottomSheetId, serverUrl, teamId, thread]); const id = thread.unreadReplies ? t('global_threads.options.mark_as_read') : t('mobile.post_info.mark_unread'); const defaultMessage = thread.unreadReplies ? 'Mark as Read' : 'Mark as Unread'; diff --git a/app/screens/thread_options/options/open_in_channel_option.tsx b/app/screens/thread_options/options/open_in_channel_option.tsx index eda805830e..b0df2b0339 100644 --- a/app/screens/thread_options/options/open_in_channel_option.tsx +++ b/app/screens/thread_options/options/open_in_channel_option.tsx @@ -12,16 +12,17 @@ import {t} from '@i18n'; import {dismissBottomSheet} from '@screens/navigation'; type Props = { + bottomSheetId: typeof Screens[keyof typeof Screens]; threadId: string; } -const OpenInChannelOption = ({threadId}: Props) => { +const OpenInChannelOption = ({bottomSheetId, threadId}: Props) => { const intl = useIntl(); const serverUrl = useServerUrl(); const onHandlePress = useCallback(async () => { - await dismissBottomSheet(Screens.THREAD_OPTIONS); + await dismissBottomSheet(bottomSheetId); showPermalink(serverUrl, '', threadId); - }, [intl, serverUrl, threadId]); + }, [bottomSheetId, intl, serverUrl, threadId]); return ( { - dismissModal({componentId}); + return dismissBottomSheet(Screens.THREAD_OPTIONS); }; useNavButtonPressed(THREAD_OPTIONS_BUTTON, componentId, close, []); const options = [ , , , ,