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
This commit is contained in:
Daniel Espino García 2022-06-21 18:22:41 +02:00 committed by GitHub
parent f3c082d58c
commit b97fd550f1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View file

@ -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) {

View file

@ -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`;