[MM-18768] Remove deprecated lifecycle methods from channel info (#3377)

* Removed deprecated method componentWillReceiveProps

* Moved updateChannelRequest to state

* Added static to getDerivedStateFromProps method

* Fixed build errors

* Removed getDerivedStateFromProps and Refactored code

* updating updateChannelRequest inside state

* Added getDerivedStateFromProps

* Refactored code
This commit is contained in:
Deepak Sah 2019-11-04 20:19:14 +05:30 committed by Harrison Healey
parent 0ab53505af
commit 9708fb583c
2 changed files with 47 additions and 29 deletions

View file

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

View file

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