From 24b72b5828c249ceb4076708eb03dd17be08bdaa Mon Sep 17 00:00:00 2001 From: crockwave Date: Wed, 17 Jun 2020 20:42:30 -0500 Subject: [PATCH] Replace componentWillMount with componentDidMount and as required, construct(). Fixes #179 --- app/soapbox/features/about/index.js | 2 +- .../features/account/components/header.js | 2 +- .../features/account_timeline/index.js | 2 +- .../features/auth_login/components/captcha.js | 2 +- app/soapbox/features/blocks/index.js | 2 +- .../compose/components/privacy_dropdown.js | 23 ++++++++++--------- app/soapbox/features/domain_blocks/index.js | 2 +- app/soapbox/features/edit_profile/index.js | 9 +++----- .../features/favourited_statuses/index.js | 2 +- app/soapbox/features/favourites/index.js | 2 +- app/soapbox/features/filters/index.js | 2 +- app/soapbox/features/follow_requests/index.js | 2 +- app/soapbox/features/followers/index.js | 2 +- app/soapbox/features/following/index.js | 2 +- app/soapbox/features/groups/create/index.js | 3 ++- app/soapbox/features/groups/edit/index.js | 3 ++- app/soapbox/features/groups/index/index.js | 2 +- app/soapbox/features/groups/members/index.js | 2 +- .../features/groups/removed_accounts/index.js | 2 +- app/soapbox/features/introduction/index.js | 3 ++- app/soapbox/features/lists/index.js | 2 +- app/soapbox/features/mutes/index.js | 2 +- app/soapbox/features/pinned_statuses/index.js | 2 +- app/soapbox/features/reblogs/index.js | 2 +- app/soapbox/features/status/index.js | 5 +--- app/soapbox/features/ui/components/bundle.js | 2 +- .../ui/components/focal_point_modal.js | 2 +- app/soapbox/features/ui/index.js | 11 +++------ app/soapbox/pages/group_page.js | 2 +- 29 files changed, 47 insertions(+), 54 deletions(-) diff --git a/app/soapbox/features/about/index.js b/app/soapbox/features/about/index.js index 55d716878..df7b41aa2 100644 --- a/app/soapbox/features/about/index.js +++ b/app/soapbox/features/about/index.js @@ -20,7 +20,7 @@ class AboutPage extends ImmutablePureComponent { }); } - componentWillMount() { + componentDidMount() { this.loadPageHtml(); } diff --git a/app/soapbox/features/account/components/header.js b/app/soapbox/features/account/components/header.js index 83c87e0bf..c0d30bb65 100644 --- a/app/soapbox/features/account/components/header.js +++ b/app/soapbox/features/account/components/header.js @@ -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 }); } diff --git a/app/soapbox/features/account_timeline/index.js b/app/soapbox/features/account_timeline/index.js index 4bd7090c0..99ef9af94 100644 --- a/app/soapbox/features/account_timeline/index.js +++ b/app/soapbox/features/account_timeline/index.js @@ -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) { diff --git a/app/soapbox/features/auth_login/components/captcha.js b/app/soapbox/features/auth_login/components/captcha.js index 381c5de32..3921f3d6e 100644 --- a/app/soapbox/features/auth_login/components/captcha.js +++ b/app/soapbox/features/auth_login/components/captcha.js @@ -61,7 +61,7 @@ class CaptchaField extends React.Component { }); } - componentWillMount() { + componentDidMount() { this.fetchCaptcha(); this.startRefresh(); // Refresh periodically } diff --git a/app/soapbox/features/blocks/index.js b/app/soapbox/features/blocks/index.js index 0a0560c5b..ef406e3be 100644 --- a/app/soapbox/features/blocks/index.js +++ b/app/soapbox/features/blocks/index.js @@ -32,7 +32,7 @@ class Blocks extends ImmutablePureComponent { intl: PropTypes.object.isRequired, }; - componentWillMount() { + componentDidMount() { this.props.dispatch(fetchBlocks()); } diff --git a/app/soapbox/features/compose/components/privacy_dropdown.js b/app/soapbox/features/compose/components/privacy_dropdown.js index dd13033c9..d980c715b 100644 --- a/app/soapbox/features/compose/components/privacy_dropdown.js +++ b/app/soapbox/features/compose/components/privacy_dropdown.js @@ -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; diff --git a/app/soapbox/features/domain_blocks/index.js b/app/soapbox/features/domain_blocks/index.js index ba2fe8bdf..9c1e313cc 100644 --- a/app/soapbox/features/domain_blocks/index.js +++ b/app/soapbox/features/domain_blocks/index.js @@ -33,7 +33,7 @@ class Blocks extends ImmutablePureComponent { intl: PropTypes.object.isRequired, }; - componentWillMount() { + componentDidMount() { this.props.dispatch(fetchDomainBlocks()); } diff --git a/app/soapbox/features/edit_profile/index.js b/app/soapbox/features/edit_profile/index.js index bd908afd4..dde0d5e5c 100644 --- a/app/soapbox/features/edit_profile/index.js +++ b/app/soapbox/features/edit_profile/index.js @@ -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 => { diff --git a/app/soapbox/features/favourited_statuses/index.js b/app/soapbox/features/favourited_statuses/index.js index 610dbf2bc..9e831e03b 100644 --- a/app/soapbox/features/favourited_statuses/index.js +++ b/app/soapbox/features/favourited_statuses/index.js @@ -34,7 +34,7 @@ class Favourites extends ImmutablePureComponent { isMyAccount: PropTypes.bool.isRequired, }; - componentWillMount() { + componentDidMount() { this.props.dispatch(fetchFavouritedStatuses()); } diff --git a/app/soapbox/features/favourites/index.js b/app/soapbox/features/favourites/index.js index 84cb94c1a..db5cbef49 100644 --- a/app/soapbox/features/favourites/index.js +++ b/app/soapbox/features/favourites/index.js @@ -23,7 +23,7 @@ class Favourites extends ImmutablePureComponent { accountIds: ImmutablePropTypes.list, }; - componentWillMount() { + componentDidMount() { this.props.dispatch(fetchFavourites(this.props.params.statusId)); } diff --git a/app/soapbox/features/filters/index.js b/app/soapbox/features/filters/index.js index 7e6048532..7ae71daac 100644 --- a/app/soapbox/features/filters/index.js +++ b/app/soapbox/features/filters/index.js @@ -24,7 +24,7 @@ class Filters extends ImmutablePureComponent { intl: PropTypes.object.isRequired, }; - componentWillMount() { + componentDidMount() { this.props.dispatch(fetchFilters()); } diff --git a/app/soapbox/features/follow_requests/index.js b/app/soapbox/features/follow_requests/index.js index d40e947bf..e956e5c34 100644 --- a/app/soapbox/features/follow_requests/index.js +++ b/app/soapbox/features/follow_requests/index.js @@ -32,7 +32,7 @@ class FollowRequests extends ImmutablePureComponent { intl: PropTypes.object.isRequired, }; - componentWillMount() { + componentDidMount() { this.props.dispatch(fetchFollowRequests()); } diff --git a/app/soapbox/features/followers/index.js b/app/soapbox/features/followers/index.js index 86709545e..87a60272d 100644 --- a/app/soapbox/features/followers/index.js +++ b/app/soapbox/features/followers/index.js @@ -58,7 +58,7 @@ class Followers extends ImmutablePureComponent { unavailable: PropTypes.bool, }; - componentWillMount() { + componentDidMount() { const { params: { username }, accountId } = this.props; if (accountId && accountId !== -1) { diff --git a/app/soapbox/features/following/index.js b/app/soapbox/features/following/index.js index db42b53b3..f3d404a23 100644 --- a/app/soapbox/features/following/index.js +++ b/app/soapbox/features/following/index.js @@ -58,7 +58,7 @@ class Following extends ImmutablePureComponent { diffCount: PropTypes.number, }; - componentWillMount() { + componentDidMount() { const { params: { username }, accountId } = this.props; if (accountId && accountId !== -1) { diff --git a/app/soapbox/features/groups/create/index.js b/app/soapbox/features/groups/create/index.js index 83ac82583..5bf9b50f4 100644 --- a/app/soapbox/features/groups/create/index.js +++ b/app/soapbox/features/groups/create/index.js @@ -49,7 +49,8 @@ class Create extends React.PureComponent { onCoverImageChange: PropTypes.func.isRequired, }; - componentWillMount() { + constructor(props) { + super(props); this.props.reset(); } diff --git a/app/soapbox/features/groups/edit/index.js b/app/soapbox/features/groups/edit/index.js index f63447b2f..a11d64a6f 100644 --- a/app/soapbox/features/groups/edit/index.js +++ b/app/soapbox/features/groups/edit/index.js @@ -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); } diff --git a/app/soapbox/features/groups/index/index.js b/app/soapbox/features/groups/index/index.js index f99c5533e..36269b08a 100644 --- a/app/soapbox/features/groups/index/index.js +++ b/app/soapbox/features/groups/index/index.js @@ -36,7 +36,7 @@ class Groups extends ImmutablePureComponent { intl: PropTypes.object.isRequired, }; - componentWillMount() { + componentDidMount() { this.props.dispatch(fetchGroups(this.props.activeTab)); } diff --git a/app/soapbox/features/groups/members/index.js b/app/soapbox/features/groups/members/index.js index adf1984ca..0fa713906 100644 --- a/app/soapbox/features/groups/members/index.js +++ b/app/soapbox/features/groups/members/index.js @@ -30,7 +30,7 @@ class GroupMembers extends ImmutablePureComponent { hasMore: PropTypes.bool, }; - componentWillMount() { + componentDidMount() { const { params: { id } } = this.props; this.props.dispatch(fetchMembers(id)); diff --git a/app/soapbox/features/groups/removed_accounts/index.js b/app/soapbox/features/groups/removed_accounts/index.js index c3431fe2f..3f49c3546 100644 --- a/app/soapbox/features/groups/removed_accounts/index.js +++ b/app/soapbox/features/groups/removed_accounts/index.js @@ -37,7 +37,7 @@ class GroupRemovedAccounts extends ImmutablePureComponent { hasMore: PropTypes.bool, }; - componentWillMount() { + componentDidMount() { const { params: { id } } = this.props; this.props.dispatch(fetchRemovedAccounts(id)); diff --git a/app/soapbox/features/introduction/index.js b/app/soapbox/features/introduction/index.js index 42645ecf3..2ac40a865 100644 --- a/app/soapbox/features/introduction/index.js +++ b/app/soapbox/features/introduction/index.js @@ -84,7 +84,8 @@ class Introduction extends React.PureComponent { currentIndex: 0, }; - componentWillMount() { + constructor(props) { + super(props); this.pages = [ , , diff --git a/app/soapbox/features/lists/index.js b/app/soapbox/features/lists/index.js index ffa7f9528..16166047f 100644 --- a/app/soapbox/features/lists/index.js +++ b/app/soapbox/features/lists/index.js @@ -42,7 +42,7 @@ class Lists extends ImmutablePureComponent { intl: PropTypes.object.isRequired, }; - componentWillMount() { + componentDidMount() { this.props.dispatch(fetchLists()); } diff --git a/app/soapbox/features/mutes/index.js b/app/soapbox/features/mutes/index.js index f6814af15..8b7368845 100644 --- a/app/soapbox/features/mutes/index.js +++ b/app/soapbox/features/mutes/index.js @@ -32,7 +32,7 @@ class Mutes extends ImmutablePureComponent { intl: PropTypes.object.isRequired, }; - componentWillMount() { + componentDidMount() { this.props.dispatch(fetchMutes()); } diff --git a/app/soapbox/features/pinned_statuses/index.js b/app/soapbox/features/pinned_statuses/index.js index 0a6bab195..5eef23e00 100644 --- a/app/soapbox/features/pinned_statuses/index.js +++ b/app/soapbox/features/pinned_statuses/index.js @@ -31,7 +31,7 @@ class PinnedStatuses extends ImmutablePureComponent { isMyAccount: PropTypes.bool.isRequired, }; - componentWillMount() { + componentDidMount() { this.props.dispatch(fetchPinnedStatuses()); } diff --git a/app/soapbox/features/reblogs/index.js b/app/soapbox/features/reblogs/index.js index d71c4330b..5e65e6f30 100644 --- a/app/soapbox/features/reblogs/index.js +++ b/app/soapbox/features/reblogs/index.js @@ -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)); } diff --git a/app/soapbox/features/status/index.js b/app/soapbox/features/status/index.js index be2227311..fbdadf191 100644 --- a/app/soapbox/features/status/index.js +++ b/app/soapbox/features/status/index.js @@ -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); } diff --git a/app/soapbox/features/ui/components/bundle.js b/app/soapbox/features/ui/components/bundle.js index a3c7ab77e..7089597b6 100644 --- a/app/soapbox/features/ui/components/bundle.js +++ b/app/soapbox/features/ui/components/bundle.js @@ -33,7 +33,7 @@ class Bundle extends React.PureComponent { forceRender: false, } - componentWillMount() { + componentDidMount() { this.load(this.props); } diff --git a/app/soapbox/features/ui/components/focal_point_modal.js b/app/soapbox/features/ui/components/focal_point_modal.js index 9ec15768a..1b9246390 100644 --- a/app/soapbox/features/ui/components/focal_point_modal.js +++ b/app/soapbox/features/ui/components/focal_point_modal.js @@ -34,7 +34,7 @@ class FocalPointModal extends ImmutablePureComponent { dragging: false, }; - componentWillMount() { + componentDidMount() { this.updatePositionFromMedia(this.props.media); } diff --git a/app/soapbox/features/ui/index.js b/app/soapbox/features/ui/index.js index f98d09088..11e0669a9 100644 --- a/app/soapbox/features/ui/index.js +++ b/app/soapbox/features/ui/index.js @@ -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(); } diff --git a/app/soapbox/pages/group_page.js b/app/soapbox/pages/group_page.js index 423f0b54e..9458638b9 100644 --- a/app/soapbox/pages/group_page.js +++ b/app/soapbox/pages/group_page.js @@ -25,7 +25,7 @@ class GroupPage extends ImmutablePureComponent { dispatch: PropTypes.func.isRequired, }; - componentWillMount() { + componentDidMount() { const { params: { id }, dispatch } = this.props; dispatch(fetchGroup(id));