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
This commit is contained in:
parent
bb7ff622af
commit
b5969fdfb4
9 changed files with 15 additions and 31 deletions
|
|
@ -59,9 +59,8 @@ type Props = {
|
|||
isAppsEnabled: boolean;
|
||||
nestedScrollEnabled?: boolean;
|
||||
updateValue: (v: string) => void;
|
||||
hasFilesAttached?: boolean;
|
||||
shouldDirectlyReact?: boolean;
|
||||
availableSpace: SharedValue<number>;
|
||||
inPost?: boolean;
|
||||
growDown?: boolean;
|
||||
teamId?: string;
|
||||
containerStyle?: StyleProp<ViewStyle>;
|
||||
|
|
@ -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 &&
|
||||
|
|
|
|||
|
|
@ -70,8 +70,7 @@ type Props = {
|
|||
value: string;
|
||||
nestedScrollEnabled: boolean;
|
||||
skinTone: string;
|
||||
hasFilesAttached?: boolean;
|
||||
inPost: boolean;
|
||||
shouldDirectlyReact?: boolean;
|
||||
listStyle: StyleProp<ViewStyle>;
|
||||
}
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -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}
|
||||
/>
|
||||
|
|
|
|||
|
|
@ -400,7 +400,7 @@ export default function ChannelInfoForm({
|
|||
value={header}
|
||||
nestedScrollEnabled={true}
|
||||
availableSpace={animatedAutocompleteAvailableSpace}
|
||||
inPost={false}
|
||||
shouldDirectlyReact={false}
|
||||
growDown={growDown}
|
||||
/>
|
||||
</SafeAreaView>
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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 = ({
|
|||
</SafeAreaView>
|
||||
<Autocomplete
|
||||
channelId={post.channelId}
|
||||
hasFilesAttached={hasFilesAttached}
|
||||
shouldDirectlyReact={false}
|
||||
nestedScrollEnabled={true}
|
||||
rootId={post.rootId}
|
||||
updateValue={onAutocompleteChangeText}
|
||||
|
|
@ -487,7 +486,6 @@ const EditPost = ({
|
|||
cursorPosition={cursorPosition}
|
||||
position={animatedAutocompletePosition}
|
||||
availableSpace={animatedAutocompleteAvailableSpace}
|
||||
inPost={false}
|
||||
serverUrl={serverUrl}
|
||||
/>
|
||||
</EditPostProvider>
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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}
|
||||
|
|
|
|||
Loading…
Reference in a new issue