diff --git a/native/chat/settings/delete-thread.react.js b/native/chat/settings/delete-thread.react.js --- a/native/chat/settings/delete-thread.react.js +++ b/native/chat/settings/delete-thread.react.js @@ -49,7 +49,7 @@ type Props = { ...BaseProps, // Redux state - +threadInfo: ?ThreadInfo, + +threadInfo: ThreadInfo, +loadingStatus: LoadingStatus, +activeTheme: ?GlobalTheme, +colors: Colors, @@ -65,14 +65,6 @@ mounted = false; passwordInput: ?React.ElementRef<typeof BaseTextInput>; - static getThreadInfo(props: Props): ThreadInfo { - const { threadInfo } = props; - if (threadInfo) { - return threadInfo; - } - return props.route.params.threadInfo; - } - componentDidMount() { this.mounted = true; } @@ -87,14 +79,6 @@ } } - componentDidUpdate(prevProps: Props) { - const oldReduxThreadInfo = prevProps.threadInfo; - const newReduxThreadInfo = this.props.threadInfo; - if (newReduxThreadInfo && newReduxThreadInfo !== oldReduxThreadInfo) { - this.props.navigation.setParams({ threadInfo: newReduxThreadInfo }); - } - } - render() { const buttonContent = this.props.loadingStatus === 'loading' ? ( @@ -102,7 +86,7 @@ ) : ( <Text style={this.props.styles.deleteText}>Delete chat</Text> ); - const threadInfo = DeleteThread.getThreadInfo(this.props); + const { threadInfo } = this.props; return ( <ScrollView contentContainerStyle={this.props.styles.scrollViewContentContainer} @@ -143,8 +127,7 @@ }; async deleteThread() { - const threadInfo = DeleteThread.getThreadInfo(this.props); - const { navDispatch } = this.props; + const { threadInfo, navDispatch } = this.props; navDispatch({ type: clearThreadsActionType, payload: { threadIDs: [threadInfo.id] }, @@ -238,10 +221,19 @@ const ConnectedDeleteThread: React.ComponentType<BaseProps> = React.memo<BaseProps>( function ConnectedDeleteThread(props: BaseProps) { const threadID = props.route.params.threadInfo.id; - const threadInfo = useSelector( + const reduxThreadInfo = useSelector( state => threadInfoSelector(state)[threadID], ); + const { setParams } = props.navigation; + React.useEffect(() => { + if (reduxThreadInfo) { + setParams({ threadInfo: reduxThreadInfo }); + } + }, [reduxThreadInfo, setParams]); + const threadInfo: ThreadInfo = + reduxThreadInfo ?? props.route.params.threadInfo; + const loadingStatus = useSelector(loadingStatusSelector); const activeTheme = useSelector(state => state.globalThemeInfo.activeTheme);