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 ae0eb6b9cf..43205ba4ae 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,18 +15,18 @@ import {showSnackBar} from '@utils/snack_bar'; import type PostModel from '@typings/database/models/servers/post'; type Props = { - location: typeof Screens[keyof typeof Screens]; + sourceScreen: typeof Screens[keyof typeof Screens]; post: PostModel; teamName: string; } -const CopyPermalinkOption = ({teamName, post, location}: Props) => { +const CopyPermalinkOption = ({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); - showSnackBar({barType: SNACK_BAR_TYPE.LINK_COPIED, location}); + showSnackBar({barType: SNACK_BAR_TYPE.LINK_COPIED, sourceScreen}); }, [teamName, post.id]); return ( diff --git a/app/screens/post_options/options/copy_text_option.tsx b/app/screens/post_options/options/copy_text_option.tsx index 81de162dff..a42c002586 100644 --- a/app/screens/post_options/options/copy_text_option.tsx +++ b/app/screens/post_options/options/copy_text_option.tsx @@ -12,14 +12,14 @@ import {dismissBottomSheet} from '@screens/navigation'; import {showSnackBar} from '@utils/snack_bar'; type Props = { - location: typeof Screens[keyof typeof Screens]; + sourceScreen: typeof Screens[keyof typeof Screens]; postMessage: string; } -const CopyTextOption = ({postMessage, location}: Props) => { +const CopyTextOption = ({postMessage, sourceScreen}: Props) => { const handleCopyText = useCallback(async () => { Clipboard.setString(postMessage); await dismissBottomSheet(Screens.POST_OPTIONS); - showSnackBar({barType: SNACK_BAR_TYPE.MESSAGE_COPIED, location}); + showSnackBar({barType: SNACK_BAR_TYPE.MESSAGE_COPIED, sourceScreen}); }, [postMessage]); return ( diff --git a/app/screens/post_options/post_options.tsx b/app/screens/post_options/post_options.tsx index f80031477f..97b1d56a08 100644 --- a/app/screens/post_options/post_options.tsx +++ b/app/screens/post_options/post_options.tsx @@ -31,7 +31,7 @@ type PostOptionsProps = { canReply: boolean; combinedPost?: Post; isSaved: boolean; - location: typeof Screens[keyof typeof Screens]; + sourceScreen: typeof Screens[keyof typeof Screens]; post: PostModel; thread?: ThreadModel; componentId: string; @@ -41,7 +41,7 @@ const PostOptions = ({ canAddReaction, canDelete, canEdit, canMarkAsUnread, canPin, canReply, combinedPost, componentId, isSaved, - location, post, thread, + sourceScreen, post, thread, }: PostOptionsProps) => { const managedConfig = useManagedConfig(); @@ -67,7 +67,7 @@ const PostOptions = ({ const canCopyPermalink = !isSystemPost && managedConfig?.copyAndPasteProtection !== 'true'; const canCopyText = canCopyPermalink && post.message; - const shouldRenderFollow = !(location !== Screens.CHANNEL || !thread); + const shouldRenderFollow = !(sourceScreen !== Screens.CHANNEL || !thread); const snapPoints = [ canAddReaction, canCopyPermalink, canCopyText, @@ -88,10 +88,10 @@ const PostOptions = ({ {canMarkAsUnread && !isSystemPost && } - { Boolean(canCopyPermalink && post.message) && + { canCopyPermalink && } {!isSystemPost && @@ -103,7 +103,7 @@ const PostOptions = ({ {Boolean(canCopyText && post.message) && } {canPin && { return { text: { @@ -29,11 +30,12 @@ const getStyleSheet = makeStyleSheetFromTheme((theme: Theme) => { type SnackBarProps = { componentId: string; - onPress?: () => void; + onUndoPress?: () => void; barType: keyof typeof SNACK_BAR_TYPE; - location: typeof Screens[keyof typeof Screens]; + sourceScreen: typeof Screens[keyof typeof Screens]; } -const SnackBar = ({barType, componentId, onPress, location}: SnackBarProps) => { + +const SnackBar = ({barType, componentId, onUndoPress, sourceScreen}: SnackBarProps) => { const [showToast, setShowToast] = useState(); const intl = useIntl(); const theme = useTheme(); @@ -45,14 +47,14 @@ const SnackBar = ({barType, componentId, onPress, location}: SnackBarProps) => { const onPressHandler = useCallback(() => { dismissOverlay(componentId); - onPress?.(); - }, [onPress, componentId]); + onUndoPress?.(); + }, [onUndoPress, componentId]); const animatedStyle = useAnimatedStyle(() => { const DRAFT_INPUT_HEIGHT = 130; let delta: number; - switch (location) { + switch (sourceScreen) { case Screens.MENTIONS: delta = BOTTOM_TAB_HEIGHT - 15; break; @@ -77,21 +79,21 @@ const SnackBar = ({barType, componentId, onPress, location}: SnackBarProps) => { let tabletStyle: Partial; switch (true) { - case location === Screens.THREAD : + case sourceScreen === Screens.THREAD : tabletStyle = { marginLeft: 0, width: `${TABLET_PORTRAIT_RATIO}%`, marginBottom: 30, }; break; - case location === Screens.SAVED_POSTS : + case sourceScreen === Screens.SAVED_POSTS : tabletStyle = { marginBottom: 20, marginLeft: TABLET_SIDEBAR_WIDTH, width: (TABLET_PORTRAIT_RATIO / 100) * diffWidth, }; break; - case [Screens.PERMALINK, Screens.MENTIONS].includes(location): + case [Screens.PERMALINK, Screens.MENTIONS].includes(sourceScreen): tabletStyle = { marginBottom: 0, marginLeft: 0, @@ -144,17 +146,16 @@ const SnackBar = ({barType, componentId, onPress, location}: SnackBarProps) => { textStyle={styles.text} style={toastStyle} > - {config.canUndo && onPress && ( + {config.canUndo && onUndoPress && ( - + {intl.formatMessage({ id: 'snack.bar.undo', defaultMessage: 'Undo', })} - )} + + )} ); }; diff --git a/app/utils/snack_bar/index.ts b/app/utils/snack_bar/index.ts index 5941814910..7ae325b176 100644 --- a/app/utils/snack_bar/index.ts +++ b/app/utils/snack_bar/index.ts @@ -7,7 +7,7 @@ import {showOverlay} from '@screens/navigation'; type ShowSnackBarArgs = { barType: keyof typeof SNACK_BAR_TYPE; onPress?: () => void; - location?: typeof Screens[keyof typeof Screens]; + sourceScreen?: typeof Screens[keyof typeof Screens]; }; export const showSnackBar = (passProps: ShowSnackBarArgs) => { const screen = Screens.SNACK_BAR;