Merge branch 'componentWillReceiveProps_to_DidUpdate_refactor' into 'develop'

Component will receive props to did update refactor Fixes #184

Closes #184

See merge request soapbox-pub/soapbox-fe!80
merge-requests/83/head
Alex Gleason 4 years ago
commit ecf26de289

@ -153,10 +153,13 @@ export default class AutosuggestInput extends ImmutablePureComponent {
this.input.focus(); this.input.focus();
} }
componentWillReceiveProps(nextProps) { static getDerivedStateFromProps(nextProps, state) {
if (nextProps.suggestions !== this.props.suggestions && nextProps.suggestions.size > 0 && this.state.suggestionsHidden && this.state.focused) { if (nextProps.suggestions && nextProps.suggestions.size > 0 && state.suggestionsHidden && state.focused) {
this.setState({ suggestionsHidden: false }); return {
suggestionsHidden: false,
};
} }
return null;
} }
setInput = (c) => { setInput = (c) => {

@ -159,10 +159,13 @@ export default class AutosuggestTextarea extends ImmutablePureComponent {
this.textarea.focus(); this.textarea.focus();
} }
componentWillReceiveProps(nextProps) { static getDerivedStateFromProps(nextProps, state) {
if (nextProps.suggestions !== this.props.suggestions && nextProps.suggestions.size > 0 && this.state.suggestionsHidden && this.state.focused) { if (nextProps.suggestions && nextProps.suggestions.size > 0 && state.suggestionsHidden && state.focused) {
this.setState({ suggestionsHidden: false }); return {
suggestionsHidden: false,
};
} }
return null;
} }
setTextarea = (c) => { setTextarea = (c) => {

@ -234,15 +234,21 @@ class MediaGallery extends React.PureComponent {
state = { state = {
visible: this.props.visible !== undefined ? this.props.visible : (this.props.displayMedia !== 'hide_all' && !this.props.sensitive || this.props.displayMedia === 'show_all'), visible: this.props.visible !== undefined ? this.props.visible : (this.props.displayMedia !== 'hide_all' && !this.props.sensitive || this.props.displayMedia === 'show_all'),
width: this.props.defaultWidth, width: this.props.defaultWidth,
media: this.props.media,
displayMedia: this.props.displayMedia,
}; };
componentWillReceiveProps(nextProps) { static getDerivedStateFromProps(nextProps, state) {
const { displayMedia } = this.props; if (!is(nextProps.media, state.media) && nextProps.visible === undefined) {
if (!is(nextProps.media, this.props.media) && nextProps.visible === undefined) { return {
this.setState({ visible: displayMedia !== 'hide_all' && !nextProps.sensitive || displayMedia === 'show_all' }); visible: state.displayMedia !== 'hide_all' && !nextProps.sensitive || state.displayMedia === 'show_all',
} else if (!is(nextProps.visible, this.props.visible) && nextProps.visible !== undefined) { };
this.setState({ visible: nextProps.visible }); } else if (!is(nextProps.visible, state.visible) && nextProps.visible !== undefined) {
return {
visible: nextProps.visible,
};
} }
return null;
} }
handleOpen = () => { handleOpen = () => {

@ -78,21 +78,18 @@ class ModalRoot extends React.PureComponent {
window.addEventListener('keyup', this.handleKeyUp, false); window.addEventListener('keyup', this.handleKeyUp, false);
} }
componentWillReceiveProps(nextProps) { componentDidUpdate(nextProps, prevProps) {
if (!!nextProps.children && !this.props.children) { if (!!nextProps.children && !this.props.children) {
this.activeElement = document.activeElement; this.activeElement = document.activeElement;
this.getSiblings().forEach(sibling => sibling.setAttribute('inert', true)); this.getSiblings().forEach(sibling => sibling.setAttribute('inert', true));
} else if (!nextProps.children) { } else if (!nextProps.children) {
this.setState({ revealed: false }); this.setState({ revealed: false });
} }
if (!nextProps.children && !!this.props.children) { if (!nextProps.children && !!this.props.children) {
this.activeElement = document.activeElement;
this.activeElement.focus(); this.activeElement.focus();
this.activeElement = null; this.activeElement = null;
} }
}
componentDidUpdate(prevProps) {
if (!this.props.children && !!prevProps.children) { if (!this.props.children && !!prevProps.children) {
this.getSiblings().forEach(sibling => sibling.removeAttribute('inert')); this.getSiblings().forEach(sibling => sibling.removeAttribute('inert'));
} }

@ -137,7 +137,7 @@ class RelativeTimestamp extends React.Component {
this.state.now !== nextState.now; this.state.now !== nextState.now;
} }
componentWillReceiveProps(nextProps) { componentDidUpdate(nextProps) {
if (this.props.timestamp !== nextProps.timestamp) { if (this.props.timestamp !== nextProps.timestamp) {
this.setState({ now: Date.now() }); this.setState({ now: Date.now() });
} }

@ -97,7 +97,7 @@ class AccountGallery extends ImmutablePureComponent {
} }
} }
componentWillReceiveProps(nextProps) { componentDidUpdate(nextProps) {
if (nextProps.accountId && nextProps.accountId !== -1 && (nextProps.accountId !== this.props.accountId && nextProps.accountId)) { if (nextProps.accountId && nextProps.accountId !== -1 && (nextProps.accountId !== this.props.accountId && nextProps.accountId)) {
this.props.dispatch(fetchAccount(nextProps.params.accountId)); this.props.dispatch(fetchAccount(nextProps.params.accountId));
this.props.dispatch(expandAccountMediaTimeline(nextProps.accountId)); this.props.dispatch(expandAccountMediaTimeline(nextProps.accountId));

@ -81,7 +81,7 @@ class AccountTimeline extends ImmutablePureComponent {
} }
} }
componentWillReceiveProps(nextProps) { componentDidUpdate(nextProps) {
const { me } = nextProps; const { me } = nextProps;
if (nextProps.accountId && nextProps.accountId !== -1 && (nextProps.accountId !== this.props.accountId && nextProps.accountId) || nextProps.withReplies !== this.props.withReplies) { if (nextProps.accountId && nextProps.accountId !== -1 && (nextProps.accountId !== this.props.accountId && nextProps.accountId) || nextProps.withReplies !== this.props.withReplies) {
this.props.dispatch(fetchAccount(nextProps.accountId)); this.props.dispatch(fetchAccount(nextProps.accountId));

@ -56,7 +56,7 @@ class ModifierPickerMenu extends React.PureComponent {
this.props.onSelect(e.currentTarget.getAttribute('data-index') * 1); this.props.onSelect(e.currentTarget.getAttribute('data-index') * 1);
} }
componentWillReceiveProps(nextProps) { componentDidUpdate(nextProps) {
if (nextProps.active) { if (nextProps.active) {
this.attachListeners(); this.attachListeners();
} else { } else {

@ -27,7 +27,7 @@ class Favourites extends ImmutablePureComponent {
this.props.dispatch(fetchFavourites(this.props.params.statusId)); this.props.dispatch(fetchFavourites(this.props.params.statusId));
} }
componentWillReceiveProps(nextProps) { componentDidUpdate(nextProps) {
if (nextProps.params.statusId !== this.props.params.statusId && nextProps.params.statusId) { if (nextProps.params.statusId !== this.props.params.statusId && nextProps.params.statusId) {
this.props.dispatch(fetchFavourites(nextProps.params.statusId)); this.props.dispatch(fetchFavourites(nextProps.params.statusId));
} }

@ -69,7 +69,7 @@ class Followers extends ImmutablePureComponent {
} }
} }
componentWillReceiveProps(nextProps) { componentDidUpdate(nextProps) {
if (nextProps.accountId && nextProps.accountId !== -1 && (nextProps.accountId !== this.props.accountId && nextProps.accountId)) { if (nextProps.accountId && nextProps.accountId !== -1 && (nextProps.accountId !== this.props.accountId && nextProps.accountId)) {
this.props.dispatch(fetchAccount(nextProps.accountId)); this.props.dispatch(fetchAccount(nextProps.accountId));
this.props.dispatch(fetchFollowers(nextProps.accountId)); this.props.dispatch(fetchFollowers(nextProps.accountId));

@ -69,7 +69,7 @@ class Following extends ImmutablePureComponent {
} }
} }
componentWillReceiveProps(nextProps) { componentDidUpdate(nextProps) {
if (nextProps.accountId && nextProps.accountId !== -1 && (nextProps.accountId !== this.props.accountId && nextProps.accountId)) { if (nextProps.accountId && nextProps.accountId !== -1 && (nextProps.accountId !== this.props.accountId && nextProps.accountId)) {
this.props.dispatch(fetchAccount(nextProps.accountId)); this.props.dispatch(fetchAccount(nextProps.accountId));
this.props.dispatch(fetchFollowing(nextProps.accountId)); this.props.dispatch(fetchFollowing(nextProps.accountId));

@ -62,7 +62,7 @@ class Edit extends React.PureComponent {
} }
} }
componentWillReceiveProps(nextProps) { componentDidUpdate(nextProps) {
if (!this.props.group && nextProps.group) { if (!this.props.group && nextProps.group) {
this.props.setUp(nextProps.group); this.props.setUp(nextProps.group);
} }

@ -36,7 +36,7 @@ class GroupMembers extends ImmutablePureComponent {
this.props.dispatch(fetchMembers(id)); this.props.dispatch(fetchMembers(id));
} }
componentWillReceiveProps(nextProps) { componentDidUpdate(nextProps) {
if (nextProps.params.id !== this.props.params.id) { if (nextProps.params.id !== this.props.params.id) {
this.props.dispatch(fetchMembers(nextProps.params.id)); this.props.dispatch(fetchMembers(nextProps.params.id));
} }

@ -43,7 +43,7 @@ class GroupRemovedAccounts extends ImmutablePureComponent {
this.props.dispatch(fetchRemovedAccounts(id)); this.props.dispatch(fetchRemovedAccounts(id));
} }
componentWillReceiveProps(nextProps) { componentDidUpdate(nextProps) {
if (nextProps.params.id !== this.props.params.id) { if (nextProps.params.id !== this.props.params.id) {
this.props.dispatch(fetchRemovedAccounts(nextProps.params.id)); this.props.dispatch(fetchRemovedAccounts(nextProps.params.id));
} }

@ -81,7 +81,7 @@ class HashtagTimeline extends React.PureComponent {
dispatch(expandHashtagTimeline(id, { tags })); dispatch(expandHashtagTimeline(id, { tags }));
} }
componentWillReceiveProps(nextProps) { componentDidUpdate(nextProps) {
const { dispatch, params } = this.props; const { dispatch, params } = this.props;
const { id, tags } = nextProps.params; const { id, tags } = nextProps.params;

@ -50,7 +50,7 @@ class ListTimeline extends React.PureComponent {
this.handleDisconnect(); this.handleDisconnect();
} }
componentWillReceiveProps(nextProps) { componentDidUpdate(nextProps) {
if (nextProps.params.id !== this.props.params.id) { if (nextProps.params.id !== this.props.params.id) {
this.handleDisconnect(); this.handleDisconnect();
this.handleConnect(nextProps.params.id); this.handleConnect(nextProps.params.id);

@ -41,7 +41,7 @@ class Reblogs extends ImmutablePureComponent {
this.props.dispatch(fetchStatus(this.props.params.statusId)); this.props.dispatch(fetchStatus(this.props.params.statusId));
} }
componentWillReceiveProps(nextProps) { componentDidUpdate(nextProps) {
if (nextProps.params.statusId !== this.props.params.statusId && nextProps.params.statusId) { if (nextProps.params.statusId !== this.props.params.statusId && nextProps.params.statusId) {
this.props.dispatch(fetchReblogs(nextProps.params.statusId)); this.props.dispatch(fetchReblogs(nextProps.params.statusId));
this.props.dispatch(fetchStatus(nextProps.params.statusId)); this.props.dispatch(fetchStatus(nextProps.params.statusId));

@ -21,7 +21,7 @@ class Header extends ImmutablePureComponent {
submittedValue: '', submittedValue: '',
}; };
componentWillReceiveProps(nextProps) { componentDidUpdate(nextProps) {
if (nextProps.submitted) { if (nextProps.submitted) {
const submittedValue = nextProps.value; const submittedValue = nextProps.value;
this.setState({ submittedValue }); this.setState({ submittedValue });

@ -75,7 +75,7 @@ export default class Card extends React.PureComponent {
embedded: false, embedded: false,
}; };
componentWillReceiveProps(nextProps) { componentDidUpdate(nextProps) {
if (!Immutable.is(this.props.card, nextProps.card)) { if (!Immutable.is(this.props.card, nextProps.card)) {
this.setState({ embedded: false }); this.setState({ embedded: false });
} }

@ -144,17 +144,6 @@ class Status extends ImmutablePureComponent {
attachFullscreenListener(this.onFullScreenChange); attachFullscreenListener(this.onFullScreenChange);
} }
componentWillReceiveProps(nextProps) {
if (nextProps.params.statusId !== this.props.params.statusId && nextProps.params.statusId) {
this._scrolledIntoView = false;
this.props.dispatch(fetchStatus(nextProps.params.statusId));
}
if (nextProps.status && nextProps.status.get('id') !== this.state.loadedStatusId) {
this.setState({ showMedia: defaultMediaVisibility(nextProps.status), loadedStatusId: nextProps.status.get('id') });
}
}
handleToggleMediaVisibility = () => { handleToggleMediaVisibility = () => {
this.setState({ showMedia: !this.state.showMedia }); this.setState({ showMedia: !this.state.showMedia });
} }
@ -401,7 +390,16 @@ class Status extends ImmutablePureComponent {
this.node = c; this.node = c;
} }
componentDidUpdate() { componentDidUpdate(nextProps) {
if (nextProps.params.statusId !== this.props.params.statusId && nextProps.params.statusId) {
this._scrolledIntoView = false;
this.props.dispatch(fetchStatus(nextProps.params.statusId));
}
if (nextProps.status && nextProps.status.get('id') !== this.state.loadedStatusId) {
this.setState({ showMedia: defaultMediaVisibility(nextProps.status), loadedStatusId: nextProps.status.get('id') });
}
if (this._scrolledIntoView) { if (this._scrolledIntoView) {
return; return;
} }

@ -37,7 +37,7 @@ class Bundle extends React.PureComponent {
this.load(this.props); this.load(this.props);
} }
componentWillReceiveProps(nextProps) { UNSAFE_componentWillReceiveProps(nextProps) {
if (nextProps.fetchComponent !== this.props.fetchComponent) { if (nextProps.fetchComponent !== this.props.fetchComponent) {
this.load(nextProps); this.load(nextProps);
} }

@ -38,7 +38,7 @@ class FocalPointModal extends ImmutablePureComponent {
this.updatePositionFromMedia(this.props.media); this.updatePositionFromMedia(this.props.media);
} }
componentWillReceiveProps(nextProps) { componentDidUpdate(nextProps) {
if (this.props.media.get('id') !== nextProps.media.get('id')) { if (this.props.media.get('id') !== nextProps.media.get('id')) {
this.updatePositionFromMedia(nextProps.media); this.updatePositionFromMedia(nextProps.media);
} }

@ -42,7 +42,7 @@ export default class ImageLoader extends React.PureComponent {
this.loadImage(this.props); this.loadImage(this.props);
} }
componentWillReceiveProps(nextProps) { componentDidUpdate(nextProps) {
if (this.props.src !== nextProps.src) { if (this.props.src !== nextProps.src) {
this.loadImage(nextProps); this.loadImage(nextProps);
} }

@ -83,7 +83,7 @@ class ReportModal extends ImmutablePureComponent {
this.props.dispatch(expandAccountTimeline(this.props.account.get('id'), { withReplies: true })); this.props.dispatch(expandAccountTimeline(this.props.account.get('id'), { withReplies: true }));
} }
componentWillReceiveProps(nextProps) { componentDidUpdate(nextProps) {
if (this.props.account !== nextProps.account && nextProps.account) { if (this.props.account !== nextProps.account && nextProps.account) {
this.props.dispatch(expandAccountTimeline(nextProps.account.get('id'), { withReplies: true })); this.props.dispatch(expandAccountTimeline(nextProps.account.get('id'), { withReplies: true }));
} }

@ -291,7 +291,7 @@ class Video extends React.PureComponent {
document.removeEventListener('MSFullscreenChange', this.handleFullscreenChange, true); document.removeEventListener('MSFullscreenChange', this.handleFullscreenChange, true);
} }
componentWillReceiveProps(nextProps) { UNSAFE_componentWillReceiveProps(nextProps) {
if (!is(nextProps.visible, this.props.visible) && nextProps.visible !== undefined) { if (!is(nextProps.visible, this.props.visible) && nextProps.visible !== undefined) {
this.setState({ revealed: nextProps.visible }); this.setState({ revealed: nextProps.visible });
} }

Loading…
Cancel
Save