diff --git a/webapp/channels/src/actions/views/drafts.test.ts b/webapp/channels/src/actions/views/drafts.test.ts index da03b540cf..76dc5adbe3 100644 --- a/webapp/channels/src/actions/views/drafts.test.ts +++ b/webapp/channels/src/actions/views/drafts.test.ts @@ -172,6 +172,7 @@ describe('draft actions', () => { message: '', fileInfos: [], uploadsInProgress: [], + metadata: {}, })); expect(store.getActions()).toEqual(testStore.getActions()); diff --git a/webapp/channels/src/actions/views/drafts.ts b/webapp/channels/src/actions/views/drafts.ts index 297eb94a30..0d3de8092a 100644 --- a/webapp/channels/src/actions/views/drafts.ts +++ b/webapp/channels/src/actions/views/drafts.ts @@ -73,7 +73,7 @@ export function removeDraft(key: string, channelId: string, rootId = ''): Action return async (dispatch, getState) => { const state = getState(); - dispatch(setGlobalItem(key, {message: '', fileInfos: [], uploadsInProgress: []})); + dispatch(setGlobalItem(key, {message: '', fileInfos: [], uploadsInProgress: [], metadata: {}})); if (syncedDraftsAreAllowedAndEnabled(state)) { const connectionId = getConnectionId(getState()); diff --git a/webapp/channels/src/components/advanced_text_editor/advanced_text_editor.tsx b/webapp/channels/src/components/advanced_text_editor/advanced_text_editor.tsx index c0c3b3ad0d..8653415905 100644 --- a/webapp/channels/src/components/advanced_text_editor/advanced_text_editor.tsx +++ b/webapp/channels/src/components/advanced_text_editor/advanced_text_editor.tsx @@ -13,7 +13,6 @@ import {savePreferences} from 'mattermost-redux/actions/preferences'; import {Permissions} from 'mattermost-redux/constants'; import {getChannel, makeGetChannel, getDirectChannel} from 'mattermost-redux/selectors/entities/channels'; import {getConfig, getFeatureFlagValue} from 'mattermost-redux/selectors/entities/general'; -import {getPost} from 'mattermost-redux/selectors/entities/posts'; import {get, getBool, getInt} from 'mattermost-redux/selectors/entities/preferences'; import {haveIChannelPermission} from 'mattermost-redux/selectors/entities/roles'; import {getCurrentUserId, isCurrentUserGuestUser, getStatusForUserId, makeGetDisplayName} from 'mattermost-redux/selectors/entities/users'; @@ -143,7 +142,6 @@ const AdvancedTextEditor = ({ return name; }; - const post = useSelector((state: GlobalState) => getPost(state, postId)); const currentUserId = useSelector(getCurrentUserId); const channel = useSelector((state: GlobalState) => getChannelSelector(state, channelId)); const channelDisplayName = channel?.display_name || ''; @@ -338,12 +336,17 @@ const AdvancedTextEditor = ({ ); const handleCancel = useCallback(() => { - // This resets the draft to the post's original content handleDraftChange({ - ...draft, - message: post?.message || '', + message: '', + fileInfos: [], + uploadsInProgress: [], + createAt: 0, + updateAt: 0, + channelId, + rootId: postId, + metadata: {}, }); - }, [handleDraftChange, draft, post]); + }, [handleDraftChange, channelId, postId]); const handleSubmitWrapper = useCallback(() => { const isEmptyPost = isPostDraftEmpty(draft); diff --git a/webapp/channels/src/components/post_edit_history/edited_post_item/edited_post_item.tsx b/webapp/channels/src/components/post_edit_history/edited_post_item/edited_post_item.tsx index af5d65af24..4155af79bf 100644 --- a/webapp/channels/src/components/post_edit_history/edited_post_item/edited_post_item.tsx +++ b/webapp/channels/src/components/post_edit_history/edited_post_item/edited_post_item.tsx @@ -13,6 +13,7 @@ import {getPostEditHistory, restorePostVersion} from 'mattermost-redux/actions/p import type {Theme} from 'mattermost-redux/selectors/entities/preferences'; import {ensureString} from 'mattermost-redux/utils/post_utils'; +import {removeDraft} from 'actions/views/drafts'; import {getConnectionId} from 'selectors/general'; import CompassThemeProvider from 'components/compass_theme_provider/compass_theme_provider'; @@ -25,7 +26,7 @@ import UserProfileComponent from 'components/user_profile'; import Avatar from 'components/widgets/users/avatar'; import WithTooltip from 'components/with_tooltip'; -import {ModalIdentifiers} from 'utils/constants'; +import {ModalIdentifiers, StoragePrefixes} from 'utils/constants'; import {imageURLForUser} from 'utils/utils'; import RestorePostModal from '../restore_post_modal'; @@ -123,6 +124,9 @@ const EditedPostItem = ({post, isCurrent = false, postCurrentVersion, theme, act actions.closeRightHandSide(); showInfoTooltip(); } + + const key = StoragePrefixes.EDIT_DRAFT + post.original_id; + dispatch(removeDraft(key, post.channel_id, post.root_id)); }; const handleUndo = async () => {