Replace componentWillMount with componentDidMount and as required, construct(). Fixes #179

This commit is contained in:
crockwave 2020-06-17 20:42:30 -05:00
parent 7e1457bb8d
commit 24b72b5828
29 changed files with 47 additions and 54 deletions

View file

@ -20,7 +20,7 @@ class AboutPage extends ImmutablePureComponent {
});
}
componentWillMount() {
componentDidMount() {
this.loadPageHtml();
}

View file

@ -91,7 +91,7 @@ class Header extends ImmutablePureComponent {
return !location.pathname.match(/\/(followers|following|favorites|pins)\/?$/);
}
componentWillMount() {
componentDidMount() {
window.addEventListener('resize', this.handleResize, { passive: true });
}

View file

@ -64,7 +64,7 @@ class AccountTimeline extends ImmutablePureComponent {
unavailable: PropTypes.bool,
};
componentWillMount() {
componentDidMount() {
const { params: { username }, accountId, withReplies, me } = this.props;
if (accountId && accountId !== -1) {

View file

@ -61,7 +61,7 @@ class CaptchaField extends React.Component {
});
}
componentWillMount() {
componentDidMount() {
this.fetchCaptcha();
this.startRefresh(); // Refresh periodically
}

View file

@ -32,7 +32,7 @@ class Blocks extends ImmutablePureComponent {
intl: PropTypes.object.isRequired,
};
componentWillMount() {
componentDidMount() {
this.props.dispatch(fetchBlocks());
}

View file

@ -168,6 +168,18 @@ class PrivacyDropdown extends React.PureComponent {
placement: 'bottom',
};
constructor(props) {
super(props);
const { intl: { formatMessage } } = this.props;
this.options = [
{ icon: 'globe', value: 'public', text: formatMessage(messages.public_short), meta: formatMessage(messages.public_long) },
{ icon: 'unlock', value: 'unlisted', text: formatMessage(messages.unlisted_short), meta: formatMessage(messages.unlisted_long) },
{ icon: 'lock', value: 'private', text: formatMessage(messages.private_short), meta: formatMessage(messages.private_long) },
{ icon: 'envelope', value: 'direct', text: formatMessage(messages.direct_short), meta: formatMessage(messages.direct_long) },
];
}
handleToggle = ({ target }) => {
if (this.props.isUserTouching()) {
if (this.state.open) {
@ -210,17 +222,6 @@ class PrivacyDropdown extends React.PureComponent {
this.props.onChange(value);
}
componentWillMount() {
const { intl: { formatMessage } } = this.props;
this.options = [
{ icon: 'globe', value: 'public', text: formatMessage(messages.public_short), meta: formatMessage(messages.public_long) },
{ icon: 'unlock', value: 'unlisted', text: formatMessage(messages.unlisted_short), meta: formatMessage(messages.unlisted_long) },
{ icon: 'lock', value: 'private', text: formatMessage(messages.private_short), meta: formatMessage(messages.private_long) },
{ icon: 'envelope', value: 'direct', text: formatMessage(messages.direct_short), meta: formatMessage(messages.direct_long) },
];
}
render() {
const { value, intl } = this.props;
const { open, placement } = this.state;

View file

@ -33,7 +33,7 @@ class Blocks extends ImmutablePureComponent {
intl: PropTypes.object.isRequired,
};
componentWillMount() {
componentDidMount() {
this.props.dispatch(fetchDomainBlocks());
}

View file

@ -117,18 +117,15 @@ class EditProfile extends ImmutablePureComponent {
event.preventDefault();
}
setInitialState = () => {
constructor(props) {
super(props);
const initialState = this.props.account.withMutations(map => {
map.merge(map.get('source'));
map.delete('source');
map.set('fields', normalizeFields(map.get('fields')));
unescapeParams(map, ['display_name', 'note']);
});
this.setState(initialState.toObject());
}
componentWillMount() {
this.setInitialState();
this.state = initialState.toObject();
}
handleCheckboxChange = e => {

View file

@ -34,7 +34,7 @@ class Favourites extends ImmutablePureComponent {
isMyAccount: PropTypes.bool.isRequired,
};
componentWillMount() {
componentDidMount() {
this.props.dispatch(fetchFavouritedStatuses());
}

View file

@ -23,7 +23,7 @@ class Favourites extends ImmutablePureComponent {
accountIds: ImmutablePropTypes.list,
};
componentWillMount() {
componentDidMount() {
this.props.dispatch(fetchFavourites(this.props.params.statusId));
}

View file

@ -24,7 +24,7 @@ class Filters extends ImmutablePureComponent {
intl: PropTypes.object.isRequired,
};
componentWillMount() {
componentDidMount() {
this.props.dispatch(fetchFilters());
}

View file

@ -32,7 +32,7 @@ class FollowRequests extends ImmutablePureComponent {
intl: PropTypes.object.isRequired,
};
componentWillMount() {
componentDidMount() {
this.props.dispatch(fetchFollowRequests());
}

View file

@ -58,7 +58,7 @@ class Followers extends ImmutablePureComponent {
unavailable: PropTypes.bool,
};
componentWillMount() {
componentDidMount() {
const { params: { username }, accountId } = this.props;
if (accountId && accountId !== -1) {

View file

@ -58,7 +58,7 @@ class Following extends ImmutablePureComponent {
diffCount: PropTypes.number,
};
componentWillMount() {
componentDidMount() {
const { params: { username }, accountId } = this.props;
if (accountId && accountId !== -1) {

View file

@ -49,7 +49,8 @@ class Create extends React.PureComponent {
onCoverImageChange: PropTypes.func.isRequired,
};
componentWillMount() {
constructor(props) {
super(props);
this.props.reset();
}

View file

@ -55,7 +55,8 @@ class Edit extends React.PureComponent {
setUp: PropTypes.func.isRequired,
};
componentWillMount(nextProps) {
constructor(nextProps) {
super(nextProps);
if (this.props.group) {
this.props.setUp(this.props.group);
}

View file

@ -36,7 +36,7 @@ class Groups extends ImmutablePureComponent {
intl: PropTypes.object.isRequired,
};
componentWillMount() {
componentDidMount() {
this.props.dispatch(fetchGroups(this.props.activeTab));
}

View file

@ -30,7 +30,7 @@ class GroupMembers extends ImmutablePureComponent {
hasMore: PropTypes.bool,
};
componentWillMount() {
componentDidMount() {
const { params: { id } } = this.props;
this.props.dispatch(fetchMembers(id));

View file

@ -37,7 +37,7 @@ class GroupRemovedAccounts extends ImmutablePureComponent {
hasMore: PropTypes.bool,
};
componentWillMount() {
componentDidMount() {
const { params: { id } } = this.props;
this.props.dispatch(fetchRemovedAccounts(id));

View file

@ -84,7 +84,8 @@ class Introduction extends React.PureComponent {
currentIndex: 0,
};
componentWillMount() {
constructor(props) {
super(props);
this.pages = [
<FrameWelcome domain={this.props.domain} onNext={this.handleNext} />,
<FrameFederation onNext={this.handleNext} />,

View file

@ -42,7 +42,7 @@ class Lists extends ImmutablePureComponent {
intl: PropTypes.object.isRequired,
};
componentWillMount() {
componentDidMount() {
this.props.dispatch(fetchLists());
}

View file

@ -32,7 +32,7 @@ class Mutes extends ImmutablePureComponent {
intl: PropTypes.object.isRequired,
};
componentWillMount() {
componentDidMount() {
this.props.dispatch(fetchMutes());
}

View file

@ -31,7 +31,7 @@ class PinnedStatuses extends ImmutablePureComponent {
isMyAccount: PropTypes.bool.isRequired,
};
componentWillMount() {
componentDidMount() {
this.props.dispatch(fetchPinnedStatuses());
}

View file

@ -36,7 +36,7 @@ class Reblogs extends ImmutablePureComponent {
status: ImmutablePropTypes.map,
};
componentWillMount() {
componentDidMount() {
this.props.dispatch(fetchReblogs(this.props.params.statusId));
this.props.dispatch(fetchStatus(this.props.params.statusId));
}

View file

@ -139,11 +139,8 @@ class Status extends ImmutablePureComponent {
loadedStatusId: undefined,
};
componentWillMount() {
this.props.dispatch(fetchStatus(this.props.params.statusId));
}
componentDidMount() {
this.props.dispatch(fetchStatus(this.props.params.statusId));
attachFullscreenListener(this.onFullScreenChange);
}

View file

@ -33,7 +33,7 @@ class Bundle extends React.PureComponent {
forceRender: false,
}
componentWillMount() {
componentDidMount() {
this.load(this.props);
}

View file

@ -34,7 +34,7 @@ class FocalPointModal extends ImmutablePureComponent {
dragging: false,
};
componentWillMount() {
componentDidMount() {
this.updatePositionFromMedia(this.props.media);
}

View file

@ -167,7 +167,7 @@ class SwitchingColumnsArea extends React.PureComponent {
mobile: isMobile(window.innerWidth),
};
componentWillMount() {
componentDidMount() {
window.addEventListener('resize', this.handleResize, { passive: true });
}
@ -394,9 +394,9 @@ class UI extends React.PureComponent {
}
}
componentWillMount() {
componentDidMount() {
const { me } = this.props;
if (!me) return;
window.addEventListener('beforeunload', this.handleBeforeUnload, false);
document.addEventListener('dragenter', this.handleDragEnter, false);
@ -420,11 +420,6 @@ class UI extends React.PureComponent {
setTimeout(() => this.props.dispatch(fetchFilters()), 500);
}
}
componentDidMount() {
const { me } = this.props;
if (!me) return;
this.connectStreaming();
}

View file

@ -25,7 +25,7 @@ class GroupPage extends ImmutablePureComponent {
dispatch: PropTypes.func.isRequired,
};
componentWillMount() {
componentDidMount() {
const { params: { id }, dispatch } = this.props;
dispatch(fetchGroup(id));