diff --git a/app/components/sidebars/main/channels_list/filtered_list/filtered_list.js b/app/components/sidebars/main/channels_list/filtered_list/filtered_list.js index 0430e11ac..3552c35fe 100644 --- a/app/components/sidebars/main/channels_list/filtered_list/filtered_list.js +++ b/app/components/sidebars/main/channels_list/filtered_list/filtered_list.js @@ -80,14 +80,16 @@ class FilteredList extends Component { return !deepEqual(this.props, nextProps, {strict: true}) || !deepEqual(this.state, nextState, {strict: true}); } - componentWillReceiveProps(nextProps) { - if (this.props.term !== nextProps.term) { - const {actions, currentTeam} = this.props; - const {term} = nextProps; + setDataSourceAndTerm(dataSource, term) { + this.setState({dataSource, term}); + } + + componentDidUpdate(prevProps) { + if (prevProps.term !== this.props.term) { + const {actions, currentTeam, term} = this.props; const {searchChannels, searchProfiles} = actions; const dataSource = this.buildData(this.props, term); - - this.setState({dataSource, term}); + this.setDataSourceAndTerm(dataSource, term); clearTimeout(this.searchTimeoutId); this.searchTimeoutId = setTimeout(() => { diff --git a/app/components/sidebars/main/channels_list/list/list.js b/app/components/sidebars/main/channels_list/list/list.js index e20ffb533..600335af8 100644 --- a/app/components/sidebars/main/channels_list/list/list.js +++ b/app/components/sidebars/main/channels_list/list/list.js @@ -81,21 +81,23 @@ export default class List extends PureComponent { } } - componentWillReceiveProps(nextProps) { + setSections(sections) { + this.setState({sections}); + } + + componentDidUpdate(prevProps, prevState) { const { canCreatePrivateChannels, orderedChannelIds, unreadChannelIds, - } = this.props; + } = prevProps; - if (nextProps.canCreatePrivateChannels !== canCreatePrivateChannels || - nextProps.unreadChannelIds !== unreadChannelIds || - nextProps.orderedChannelIds !== orderedChannelIds) { - this.setState({sections: this.buildSections(nextProps)}); + if (this.props.canCreatePrivateChannels !== canCreatePrivateChannels || + this.props.unreadChannelIds !== unreadChannelIds || + this.props.orderedChannelIds !== orderedChannelIds) { + this.setSections(this.buildSections(this.props)); } - } - componentDidUpdate(prevProps, prevState) { if (prevState.sections !== this.state.sections && this.listRef?._wrapperListRef?.getListRef()._viewabilityHelper) { //eslint-disable-line this.listRef.recordInteraction(); this.updateUnreadIndicators({ diff --git a/app/screens/create_channel/create_channel.js b/app/screens/create_channel/create_channel.js index 1dbe52929..d88b447c9 100644 --- a/app/screens/create_channel/create_channel.js +++ b/app/screens/create_channel/create_channel.js @@ -72,14 +72,20 @@ export default class CreateChannel extends PureComponent { this.emitCanCreateChannel(false); } - componentWillReceiveProps(nextProps) { - const {createChannelRequest} = nextProps; + onRequestStart() { + this.setState({error: null, creating: true}); + } - if (this.props.createChannelRequest !== createChannelRequest) { - switch (createChannelRequest.status) { + onRequestFailure(error) { + this.setState({error, creating: false}); + } + + componentDidUpdate(prevProps) { + if (this.props.createChannelRequest !== prevProps.createChannelRequest) { + switch (this.props.createChannelRequest.status) { case RequestStatus.STARTED: this.emitCreating(true); - this.setState({error: null, creating: true}); + this.onRequestStart(); break; case RequestStatus.SUCCESS: EventEmitter.emit(NavigationTypes.CLOSE_MAIN_SIDEBAR); @@ -91,7 +97,7 @@ export default class CreateChannel extends PureComponent { break; case RequestStatus.FAILURE: this.emitCreating(false); - this.setState({error: createChannelRequest.error, creating: false}); + this.onRequestFailure(this.props.createChannelRequest.error); break; } } diff --git a/app/screens/more_channels/more_channels.js b/app/screens/more_channels/more_channels.js index 1c82b2925..6c428df7d 100644 --- a/app/screens/more_channels/more_channels.js +++ b/app/screens/more_channels/more_channels.js @@ -102,22 +102,26 @@ export default class MoreChannels extends PureComponent { this.mounted = false; } - componentWillReceiveProps(nextProps) { + setChannelsOrArchivedChannels(state) { + this.setState(state); + } + + componentDidUpdate(prevProps) { const {term} = this.state; let channels; let archivedChannels; - if (nextProps.channels !== this.props.channels) { - channels = nextProps.channels; + if (this.props.channels !== prevProps.channels) { + channels = this.props.channels; if (term) { - channels = this.filterChannels(nextProps.channels, term); + channels = this.filterChannels(this.props.channels, term); } } - if (nextProps.archivedChannels !== this.props.archivedChannels) { - archivedChannels = nextProps.archivedChannels; + if (this.props.archivedChannels !== prevProps.archivedChannels) { + archivedChannels = this.props.archivedChannels; if (term) { - archivedChannels = this.filterChannels(nextProps.archivedChannels, term); + archivedChannels = this.filterChannels(this.props.archivedChannels, term); } } @@ -131,7 +135,7 @@ export default class MoreChannels extends PureComponent { } if (nextState.archivedChannels || nextState.channels) { - this.setState(nextState); + this.setChannelsOrArchivedChannels(nextState); } }