From b5969fdfb453dc2c6dce89cad37c2a76aa6cbf3a Mon Sep 17 00:00:00 2001 From: Rajat Dabade Date: Mon, 14 Jul 2025 17:55:27 +0530 Subject: [PATCH] Edit mode when no text and no attachment on save calls delete post (#8984) * Edit mode when no text and no attachment on save calls delete post * Removed the hasAttachment and isPost props to use shouldDirectlyReact props --- app/components/autocomplete/autocomplete.tsx | 9 +++------ .../autocomplete/emoji_suggestion/emoji_suggestion.tsx | 10 ++++------ app/components/post_draft/post_draft.tsx | 3 +-- .../create_or_edit_channel/channel_info_form.tsx | 2 +- app/screens/edit_post/edit_post.test.tsx | 2 +- app/screens/edit_post/edit_post.tsx | 8 +++----- app/screens/edit_post/index.test.tsx | 1 - app/screens/edit_post/index.tsx | 9 +-------- app/screens/home/search/search.tsx | 2 +- 9 files changed, 15 insertions(+), 31 deletions(-) diff --git a/app/components/autocomplete/autocomplete.tsx b/app/components/autocomplete/autocomplete.tsx index a9d4e0a02..c6d3fef36 100644 --- a/app/components/autocomplete/autocomplete.tsx +++ b/app/components/autocomplete/autocomplete.tsx @@ -59,9 +59,8 @@ type Props = { isAppsEnabled: boolean; nestedScrollEnabled?: boolean; updateValue: (v: string) => void; - hasFilesAttached?: boolean; + shouldDirectlyReact?: boolean; availableSpace: SharedValue; - inPost?: boolean; growDown?: boolean; teamId?: string; containerStyle?: StyleProp; @@ -80,8 +79,7 @@ const Autocomplete = ({ isAppsEnabled, nestedScrollEnabled = false, updateValue, - hasFilesAttached, - inPost = false, + shouldDirectlyReact = false, growDown = false, containerStyle, teamId, @@ -178,8 +176,7 @@ const Autocomplete = ({ value={value || ''} nestedScrollEnabled={nestedScrollEnabled} rootId={rootId} - hasFilesAttached={hasFilesAttached} - inPost={inPost} + shouldDirectlyReact={shouldDirectlyReact} /> } {showCommands && channelId && diff --git a/app/components/autocomplete/emoji_suggestion/emoji_suggestion.tsx b/app/components/autocomplete/emoji_suggestion/emoji_suggestion.tsx index f47d719dd..8587565dd 100644 --- a/app/components/autocomplete/emoji_suggestion/emoji_suggestion.tsx +++ b/app/components/autocomplete/emoji_suggestion/emoji_suggestion.tsx @@ -70,8 +70,7 @@ type Props = { value: string; nestedScrollEnabled: boolean; skinTone: string; - hasFilesAttached?: boolean; - inPost: boolean; + shouldDirectlyReact?: boolean; listStyle: StyleProp; } const EmojiSuggestion = ({ @@ -83,8 +82,7 @@ const EmojiSuggestion = ({ value, nestedScrollEnabled, skinTone, - hasFilesAttached = false, - inPost, + shouldDirectlyReact = false, listStyle, }: Props) => { const insets = useSafeAreaInsets(); @@ -118,7 +116,7 @@ const EmojiSuggestion = ({ const showingElements = Boolean(data.length); const completeSuggestion = useCallback((emoji: string) => { - if (!hasFilesAttached && inPost) { + if (shouldDirectlyReact) { const match = value.match(REACTION_REGEX); if (match) { handleReactionToLatestPost(serverUrl, emoji, match[1] === '+', rootId); @@ -160,7 +158,7 @@ const EmojiSuggestion = ({ updateValue(completedDraft.replace(`::${emoji}: `, `:${emoji}: `)); }); } - }, [value, updateValue, rootId, cursorPosition, hasFilesAttached]); + }, [value, updateValue, rootId, cursorPosition, shouldDirectlyReact]); const renderItem = useCallback(({item}: {item: string}) => { const completeItemSuggestion = () => completeSuggestion(item); diff --git a/app/components/post_draft/post_draft.tsx b/app/components/post_draft/post_draft.tsx index 373116219..0afba7fe7 100644 --- a/app/components/post_draft/post_draft.tsx +++ b/app/components/post_draft/post_draft.tsx @@ -117,8 +117,7 @@ function PostDraft({ cursorPosition={cursorPosition} value={value} isSearch={isSearch} - hasFilesAttached={Boolean(files?.length)} - inPost={true} + shouldDirectlyReact={!Boolean(files?.length)} availableSpace={animatedAutocompleteAvailableSpace} serverUrl={serverUrl} /> diff --git a/app/screens/create_or_edit_channel/channel_info_form.tsx b/app/screens/create_or_edit_channel/channel_info_form.tsx index 0ce2e2873..d9089525a 100644 --- a/app/screens/create_or_edit_channel/channel_info_form.tsx +++ b/app/screens/create_or_edit_channel/channel_info_form.tsx @@ -400,7 +400,7 @@ export default function ChannelInfoForm({ value={header} nestedScrollEnabled={true} availableSpace={animatedAutocompleteAvailableSpace} - inPost={false} + shouldDirectlyReact={false} growDown={growDown} /> diff --git a/app/screens/edit_post/edit_post.test.tsx b/app/screens/edit_post/edit_post.test.tsx index 2fb2cece4..21e781a2f 100644 --- a/app/screens/edit_post/edit_post.test.tsx +++ b/app/screens/edit_post/edit_post.test.tsx @@ -96,7 +96,7 @@ describe('Edit Post', () => { metadata: {}, } as PostModel, maxPostSize: TEST_CONFIG.maxPostSize, - hasFilesAttached: true, + canDelete: true, files: [TEST_FILES.existingFile1, TEST_FILES.existingFile2], maxFileCount: TEST_CONFIG.maxFileCount, diff --git a/app/screens/edit_post/edit_post.tsx b/app/screens/edit_post/edit_post.tsx index 465f7c1bb..12597d7a6 100644 --- a/app/screens/edit_post/edit_post.tsx +++ b/app/screens/edit_post/edit_post.tsx @@ -63,7 +63,6 @@ type EditPostProps = { closeButtonId: string; post: PostModel; maxPostSize: number; - hasFilesAttached: boolean; canDelete: boolean; files?: FileInfo[]; maxFileCount: number; @@ -76,7 +75,6 @@ const EditPost = ({ maxPostSize, post, closeButtonId, - hasFilesAttached, canDelete, files, maxFileCount, @@ -101,7 +99,8 @@ const EditPost = ({ const intl = useIntl(); const serverUrl = useServerUrl(); - const shouldDeleteOnSave = !postMessage && canDelete && !hasFilesAttached; + const hasNoCurrentFiles = postFiles.length === 0; + const shouldDeleteOnSave = !postMessage && canDelete && hasNoCurrentFiles; const shouldEnableSaveButton = useCallback(() => { const loadingFiles = postFiles.filter((v) => v.clientId && DraftEditPostUploadManager.isUploading(v.clientId)); @@ -479,7 +478,7 @@ const EditPost = ({ diff --git a/app/screens/edit_post/index.test.tsx b/app/screens/edit_post/index.test.tsx index c597467a5..ae074f55c 100644 --- a/app/screens/edit_post/index.test.tsx +++ b/app/screens/edit_post/index.test.tsx @@ -70,7 +70,6 @@ describe('EditPost', () => { expect(editPost.props.maxFileCount).toBe(10); expect(editPost.props.maxFileSize).toBe(1000); expect(editPost.props.canUploadFiles).toBe(true); - expect(editPost.props.hasFilesAttached).toBe(false); }); }); }); diff --git a/app/screens/edit_post/index.tsx b/app/screens/edit_post/index.tsx index 554f1524e..c7df48588 100644 --- a/app/screens/edit_post/index.tsx +++ b/app/screens/edit_post/index.tsx @@ -2,30 +2,23 @@ // See LICENSE.txt for license information. import {withDatabase, withObservables} from '@nozbe/watermelondb/react'; -import {of as of$} from 'rxjs'; -import {switchMap} from 'rxjs/operators'; import {DEFAULT_SERVER_MAX_FILE_SIZE, MAX_MESSAGE_LENGTH_FALLBACK} from '@constants/post_draft'; -import {observeFilesForPost} from '@queries/servers/file'; import {observeCanUploadFiles} from '@queries/servers/security'; import {observeConfigIntValue, observeMaxFileCount} from '@queries/servers/system'; import EditPost from './edit_post'; import type {WithDatabaseArgs} from '@typings/database/database'; -import type PostModel from '@typings/database/models/servers/post'; -const enhance = withObservables([], ({database, post}: WithDatabaseArgs & { post: PostModel}) => { +const enhance = withObservables([], ({database}: WithDatabaseArgs) => { const maxPostSize = observeConfigIntValue(database, 'MaxPostSize', MAX_MESSAGE_LENGTH_FALLBACK); const canUploadFiles = observeCanUploadFiles(database); const maxFileSize = observeConfigIntValue(database, 'MaxFileSize', DEFAULT_SERVER_MAX_FILE_SIZE); const maxFileCount = observeMaxFileCount(database); - const hasFilesAttached = observeFilesForPost(database, post.id).pipe(switchMap((files) => of$(files?.length > 0))); - return { maxPostSize, - hasFilesAttached, canUploadFiles, maxFileSize, maxFileCount, diff --git a/app/screens/home/search/search.tsx b/app/screens/home/search/search.tsx index 685164399..7209dc413 100644 --- a/app/screens/home/search/search.tsx +++ b/app/screens/home/search/search.tsx @@ -471,7 +471,7 @@ const SearchScreen = ({teamId, teams, crossTeamSearchEnabled}: Props) => { cursorPosition={cursorPosition} value={searchValue} isSearch={true} - hasFilesAttached={false} + shouldDirectlyReact={false} availableSpace={autocompleteMaxHeight} position={autocompletePosition} growDown={true}