From 2de1b5466e21be1e57cab3f5f29c13c28e8121ff Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 20 Apr 2020 16:08:31 -0500 Subject: [PATCH] Refactor isStaff, fixing profile page issues --- app/gabsocial/components/status_action_bar.js | 12 ++++++++---- app/gabsocial/features/account/components/header.js | 11 ++++++++--- .../features/status/components/action_bar.js | 12 ++++++++---- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/app/gabsocial/components/status_action_bar.js b/app/gabsocial/components/status_action_bar.js index 2f718366b..0fdac1b6f 100644 --- a/app/gabsocial/components/status_action_bar.js +++ b/app/gabsocial/components/status_action_bar.js @@ -66,9 +66,13 @@ class StatusActionBar extends ImmutablePureComponent { withGroupAdmin: PropTypes.bool, intl: PropTypes.object.isRequired, me: PropTypes.string, - account: ImmutablePropTypes.map, + isStaff: PropTypes.bool.isRequired, }; + static defaultProps = { + isStaff: false, + } + // Avoid checking props that are functions (and whose equality will always // evaluate to false. See react-immutable-pure-component for usage. updateOnProps = [ @@ -188,7 +192,7 @@ class StatusActionBar extends ImmutablePureComponent { } _makeMenu = (publicStatus) => { - const { status, intl, withDismiss, withGroupAdmin, me, account } = this.props; + const { status, intl, withDismiss, withGroupAdmin, me, isStaff } = this.props; const mutingConversation = status.get('muted'); let menu = []; @@ -230,7 +234,7 @@ class StatusActionBar extends ImmutablePureComponent { menu.push({ text: intl.formatMessage(messages.block, { name: status.getIn(['account', 'username']) }), action: this.handleBlockClick }); menu.push({ text: intl.formatMessage(messages.report, { name: status.getIn(['account', 'username']) }), action: this.handleReport }); - if (isStaff(account)) { + if (isStaff) { menu.push(null); menu.push({ text: intl.formatMessage(messages.admin_account, { name: status.getIn(['account', 'username']) }), href: `/admin/accounts/${status.getIn(['account', 'id'])}` }); menu.push({ text: intl.formatMessage(messages.admin_status), href: `/admin/accounts/${status.getIn(['account', 'id'])}/statuses/${status.get('id')}` }); @@ -307,7 +311,7 @@ const mapStateToProps = state => { const me = state.get('me'); return { me, - account: state.getIn(['accounts', me]), + isStaff: isStaff(state.getIn(['accounts', me])), }; }; diff --git a/app/gabsocial/features/account/components/header.js b/app/gabsocial/features/account/components/header.js index 49f940006..5fdfe15c5 100644 --- a/app/gabsocial/features/account/components/header.js +++ b/app/gabsocial/features/account/components/header.js @@ -51,7 +51,7 @@ const mapStateToProps = state => { const me = state.get('me'); return { me, - account: state.getIn(['accounts', me]), + isStaff: isStaff(state.getIn(['accounts', me])), autoPlayGif: state.getIn(['settings', 'autoPlayGif']), }; }; @@ -69,8 +69,13 @@ class Header extends ImmutablePureComponent { domain: PropTypes.string.isRequired, username: PropTypes.string, autoPlayGif: PropTypes.bool, + isStaff: PropTypes.bool.isRequired, }; + static defaultProps = { + isStaff: false, + } + state = { isSmallScreen: (window.innerWidth <= 895), } @@ -102,7 +107,7 @@ class Header extends ImmutablePureComponent { }); makeMenu() { - const { account, intl, me } = this.props; + const { account, intl, me, isStaff } = this.props; let menu = []; @@ -165,7 +170,7 @@ class Header extends ImmutablePureComponent { } } - if (account.get('id') !== me && isStaff(account)) { + if (account.get('id') !== me && isStaff) { menu.push(null); menu.push({ text: intl.formatMessage(messages.admin_account, { name: account.get('username') }), href: `/admin/accounts/${account.get('id')}` }); } diff --git a/app/gabsocial/features/status/components/action_bar.js b/app/gabsocial/features/status/components/action_bar.js index 3ba27be4f..b842a4b8b 100644 --- a/app/gabsocial/features/status/components/action_bar.js +++ b/app/gabsocial/features/status/components/action_bar.js @@ -37,7 +37,7 @@ const mapStateToProps = state => { const me = state.get('me'); return { me, - account: state.getIn(['accounts', me]), + isStaff: isStaff(state.getIn(['accounts', me])), }; }; @@ -70,9 +70,13 @@ class ActionBar extends React.PureComponent { intl: PropTypes.object.isRequired, onOpenUnauthorizedModal: PropTypes.func.isRequired, me: PropTypes.string, - account: ImmutablePropTypes.map, + isStaff: PropTypes.bool.isRequired, }; + static defaultProps = { + isStaff: false, + } + handleReplyClick = () => { const { me } = this.props; if (me) { @@ -167,7 +171,7 @@ class ActionBar extends React.PureComponent { } render() { - const { status, intl, me, account } = this.props; + const { status, intl, me, isStaff } = this.props; const publicStatus = ['public', 'unlisted'].includes(status.get('visibility')); const mutingConversation = status.get('muted'); @@ -201,7 +205,7 @@ class ActionBar extends React.PureComponent { menu.push({ text: intl.formatMessage(messages.mute, { name: status.getIn(['account', 'username']) }), action: this.handleMuteClick }); menu.push({ text: intl.formatMessage(messages.block, { name: status.getIn(['account', 'username']) }), action: this.handleBlockClick }); menu.push({ text: intl.formatMessage(messages.report, { name: status.getIn(['account', 'username']) }), action: this.handleReport }); - if (isStaff(account)) { + if (isStaff) { menu.push(null); menu.push({ text: intl.formatMessage(messages.admin_account, { name: status.getIn(['account', 'username']) }), href: `/admin/accounts/${status.getIn(['account', 'id'])}` }); menu.push({ text: intl.formatMessage(messages.admin_status), href: `/admin/accounts/${status.getIn(['account', 'id'])}/statuses/${status.get('id')}` });