diff --git a/app/components/post_draft/index.ts b/app/components/post_draft/index.ts index e296aae23..35bffd143 100644 --- a/app/components/post_draft/index.ts +++ b/app/components/post_draft/index.ts @@ -28,7 +28,7 @@ type OwnProps = { const observeFirst = (v: DraftModel[]) => v[0]?.observe() || of$(undefined); -const enhanced = withObservables([], (ownProps: WithDatabaseArgs & OwnProps) => { +const enhanced = withObservables(['channelId', 'rootId', 'channelIsArchived'], (ownProps: WithDatabaseArgs & OwnProps) => { const {database, rootId = ''} = ownProps; let channelId = of$(ownProps.channelId); if (!ownProps.channelId) { diff --git a/app/components/post_draft/post_draft.tsx b/app/components/post_draft/post_draft.tsx index 7fec124b4..c449a8057 100644 --- a/app/components/post_draft/post_draft.tsx +++ b/app/components/post_draft/post_draft.tsx @@ -1,7 +1,7 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -import React, {RefObject, useState} from 'react'; +import React, {RefObject, useEffect, useState} from 'react'; import {Platform, View} from 'react-native'; import {KeyboardTrackingView, KeyboardTrackingViewRef} from 'react-native-keyboard-tracking-view'; @@ -51,6 +51,12 @@ function PostDraft({ const [postInputTop, setPostInputTop] = useState(0); const isTablet = useIsTablet(); + // Update draft in case we switch channels or threads + useEffect(() => { + setValue(message); + setCursorPosition(message.length); + }, [channelId, rootId]); + if (channelIsArchived || deactivatedChannel) { const archivedTestID = `${testID}.archived`;