From b97fd550f12b0f5b9d091365cb6a9fe154b389b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Espino=20Garc=C3=ADa?= Date: Tue, 21 Jun 2022 18:22:41 +0200 Subject: [PATCH] Fix lingering draft when switching channels while never leaving the channel screen (#6417) * Fix lingering draft when switching channels while never leaving the channel screen * Listen to changes on missing prop --- app/components/post_draft/index.ts | 2 +- app/components/post_draft/post_draft.tsx | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) 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`;