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(); this.loadPageHtml();
} }

View file

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

View file

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

View file

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

View file

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

View file

@ -168,6 +168,18 @@ class PrivacyDropdown extends React.PureComponent {
placement: 'bottom', 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 }) => { handleToggle = ({ target }) => {
if (this.props.isUserTouching()) { if (this.props.isUserTouching()) {
if (this.state.open) { if (this.state.open) {
@ -210,17 +222,6 @@ class PrivacyDropdown extends React.PureComponent {
this.props.onChange(value); 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() { render() {
const { value, intl } = this.props; const { value, intl } = this.props;
const { open, placement } = this.state; const { open, placement } = this.state;

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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