diff --git a/app/screens/channel_info/channel_info.js b/app/screens/channel_info/channel_info.js index 208d10c3f..0dc41efad 100644 --- a/app/screens/channel_info/channel_info.js +++ b/app/screens/channel_info/channel_info.js @@ -87,32 +87,29 @@ export default class ChannelInfo extends PureComponent { }; } + static getDerivedStateFromProps(nextProps, state) { + if (state.isFavorite !== nextProps.isFavorite || + state.isMuted !== nextProps.isChannelMuted || + state.ignoreChannelMentions !== nextProps.ignoreChannelMentions) { + return { + isFavorite: nextProps.isFavorite, + isMuted: nextProps.isChannelMuted, + ignoreChannelMentions: nextProps.ignoreChannelMentions, + }; + } + + return null; + } + componentDidMount() { this.props.actions.getChannelStats(this.props.currentChannel.id); this.props.actions.getCustomEmojisInText(this.props.currentChannel.header); } - componentWillReceiveProps(nextProps) { - if (this.props.theme !== nextProps.theme) { - setNavigatorStyles(this.props.componentId, nextProps.theme); + componentDidUpdate(prevProps) { + if (prevProps.theme !== this.props.theme) { + setNavigatorStyles(prevProps.componentId, this.props.theme); } - - let isFavorite = this.state.isFavorite; - if (isFavorite !== nextProps.isFavorite) { - isFavorite = nextProps.isFavorite; - } - - let isMuted = this.state.isMuted; - if (isMuted !== nextProps.isChannelMuted) { - isMuted = nextProps.isChannelMuted; - } - - let ignoreChannelMentions = this.state.ignoreChannelMentions; - if (ignoreChannelMentions !== nextProps.ignoreChannelMentions) { - ignoreChannelMentions = nextProps.ignoreChannelMentions; - } - - this.setState({isFavorite, isMuted, ignoreChannelMentions}); } close = (redirect = true) => { diff --git a/app/screens/edit_channel/edit_channel.js b/app/screens/edit_channel/edit_channel.js index 22aa7f883..c439afc05 100644 --- a/app/screens/edit_channel/edit_channel.js +++ b/app/screens/edit_channel/edit_channel.js @@ -92,6 +92,7 @@ export default class EditChannel extends PureComponent { this.state = { error: null, updating: false, + updateChannelRequest: props.updateChannelRequest, displayName, channelURL, purpose, @@ -114,30 +115,50 @@ export default class EditChannel extends PureComponent { this.emitCanUpdateChannel(false); } - componentWillReceiveProps(nextProps) { - if (this.props.theme !== nextProps.theme) { - setNavigatorStyles(this.props.componentId, nextProps.theme); - } - + static getDerivedStateFromProps(nextProps, state) { const {updateChannelRequest} = nextProps; - if (this.props.updateChannelRequest !== updateChannelRequest) { + if (state.updateChannelRequest !== updateChannelRequest) { + const newState = { + error: null, + updating: true, + updateChannelRequest, + }; + switch (updateChannelRequest.status) { + case RequestStatus.SUCCESS: + newState.updating = false; + break; + case RequestStatus.FAILURE: + newState.error = updateChannelRequest.error; + newState.updating = false; + break; + } + + return newState; + } + return null; + } + + componentDidUpdate(prevProps) { + if (prevProps.theme !== this.props.theme) { + setNavigatorStyles(prevProps.componentId, this.props.theme); + } + + if (prevProps.updateChannelRequest !== this.props.updateChannelRequest) { + switch (this.props.updateChannelRequest.status) { case RequestStatus.STARTED: this.emitUpdating(true); - this.setState({error: null, updating: true}); break; case RequestStatus.SUCCESS: EventEmitter.emit('close_channel_drawer'); InteractionManager.runAfterInteractions(() => { this.emitUpdating(false); - this.setState({error: null, updating: false}); this.close(); }); break; case RequestStatus.FAILURE: this.emitUpdating(false); - this.setState({error: updateChannelRequest.error, updating: false}); break; } }