diff --git a/native/chat/settings/thread-settings.react.js b/native/chat/settings/thread-settings.react.js --- a/native/chat/settings/thread-settings.react.js +++ b/native/chat/settings/thread-settings.react.js @@ -259,10 +259,6 @@ } componentDidMount() { - const threadInfo = this.props.threadInfo; - if (!threadInChatList(threadInfo)) { - threadWatcher.watchID(threadInfo.id); - } const tabNavigation: ?TabNavigationProp< 'Chat', > = this.props.navigation.dangerouslyGetParent(); @@ -271,10 +267,6 @@ } componentWillUnmount() { - const threadInfo = this.props.threadInfo; - if (!threadInChatList(threadInfo)) { - threadWatcher.removeID(threadInfo.id); - } const tabNavigation: ?TabNavigationProp< 'Chat', > = this.props.navigation.dangerouslyGetParent(); @@ -292,19 +284,6 @@ const prevThreadInfo = prevProps.threadInfo; const newThreadInfo = this.props.threadInfo; - if (newThreadInfo && newThreadInfo !== prevThreadInfo) { - this.props.navigation.setParams({ threadInfo: newThreadInfo }); - } - - if (prevThreadInfo.id !== newThreadInfo.id) { - if (!threadInChatList(prevThreadInfo)) { - threadWatcher.removeID(prevThreadInfo.id); - } - if (!threadInChatList(newThreadInfo)) { - threadWatcher.watchID(newThreadInfo.id); - } - } - if ( !tinycolor.equals(newThreadInfo.color, prevThreadInfo.color) && tinycolor.equals(this.state.colorEditValue, prevThreadInfo.color) @@ -1081,6 +1060,7 @@ state => state.currentUserInfo && state.currentUserInfo.id, ); const threadID = props.route.params.threadInfo.id; + const reduxThreadInfo: ?ThreadInfo = useSelector( state => threadInfoSelector(state)[threadID], ); @@ -1091,8 +1071,27 @@ ); // eslint-disable-next-line react-hooks/exhaustive-deps }, []); + + const { setParams } = props.navigation; + React.useEffect(() => { + if (reduxThreadInfo) { + setParams({ threadInfo: reduxThreadInfo }); + } + }, [reduxThreadInfo, setParams]); const threadInfo: ThreadInfo = reduxThreadInfo ?? props.route.params.threadInfo; + + useEffect(() => { + if (!threadInChatList(threadInfo)) { + threadWatcher.watchID(threadInfo.id); + } + return () => { + if (!threadInChatList(threadInfo)) { + threadWatcher.removeID(threadInfo.id); + } + }; + }, [threadInfo]); + const parentThreadID = threadInfo.parentThreadID; const parentThreadInfo: ?ThreadInfo = useSelector(state => parentThreadID ? threadInfoSelector(state)[parentThreadID] : null,