diff --git a/app/soapbox/components/sidebar_menu.js b/app/soapbox/components/sidebar_menu.js index 0d247f936..cfd774538 100644 --- a/app/soapbox/components/sidebar_menu.js +++ b/app/soapbox/components/sidebar_menu.js @@ -17,7 +17,7 @@ import { makeGetAccount } from '../selectors'; import { logOut, switchAccount } from 'soapbox/actions/auth'; import ThemeToggle from '../features/ui/components/theme_toggle_container'; import { fetchOwnAccounts } from 'soapbox/actions/auth'; -import { List as ImmutableList } from 'immutable'; +import { List as ImmutableList, is as ImmutableIs } from 'immutable'; const messages = defineMessages({ followers: { id: 'account.followers', defaultMessage: 'Followers' }, @@ -63,7 +63,6 @@ const mapStateToProps = state => { donateUrl: state.getIn(['patron', 'instance', 'url']), isStaff: isStaff(state.getIn(['accounts', me])), otherAccounts, - }; }; @@ -90,6 +89,7 @@ class SidebarMenu extends ImmutablePureComponent { static propTypes = { intl: PropTypes.object.isRequired, account: ImmutablePropTypes.map, + otherAccounts: ImmutablePropTypes.list, sidebarOpen: PropTypes.bool, onClose: PropTypes.func.isRequired, isStaff: PropTypes.bool.isRequired, @@ -128,8 +128,13 @@ class SidebarMenu extends ImmutablePureComponent { this.fetchOwnAccounts(); } - componentDidUpdate() { - this.fetchOwnAccounts(); + componentDidUpdate(prevProps) { + const accountChanged = !ImmutableIs(prevProps.account, this.props.account); + const otherAccountsChanged = !ImmutableIs(prevProps.otherAccounts, this.props.otherAccounts); + + if (accountChanged || otherAccountsChanged) { + this.fetchOwnAccounts(); + } } renderAccount = account => { diff --git a/app/soapbox/features/ui/components/profile_dropdown.js b/app/soapbox/features/ui/components/profile_dropdown.js index d73005da3..f1e6f9d54 100644 --- a/app/soapbox/features/ui/components/profile_dropdown.js +++ b/app/soapbox/features/ui/components/profile_dropdown.js @@ -8,7 +8,7 @@ import DropdownMenuContainer from '../../../containers/dropdown_menu_container'; import { isStaff } from 'soapbox/utils/accounts'; import { defineMessages, injectIntl } from 'react-intl'; import { logOut, switchAccount } from 'soapbox/actions/auth'; -import { List as ImmutableList } from 'immutable'; +import { List as ImmutableList, is as ImmutableIs } from 'immutable'; import Avatar from 'soapbox/components/avatar'; import DisplayName from 'soapbox/components/display_name'; @@ -80,8 +80,13 @@ class ProfileDropdown extends React.PureComponent { this.fetchOwnAccounts(); } - componentDidUpdate() { - this.fetchOwnAccounts(); + componentDidUpdate(prevProps) { + const accountChanged = !ImmutableIs(prevProps.account, this.props.account); + const otherAccountsChanged = !ImmutableIs(prevProps.otherAccounts, this.props.otherAccounts); + + if (accountChanged || otherAccountsChanged) { + this.fetchOwnAccounts(); + } } renderAccount = account => { diff --git a/app/soapbox/reducers/accounts.js b/app/soapbox/reducers/accounts.js index 5a908941d..889ed0d38 100644 --- a/app/soapbox/reducers/accounts.js +++ b/app/soapbox/reducers/accounts.js @@ -24,6 +24,7 @@ const initialState = ImmutableMap(); const normalizePleroma = account => { if (!account.pleroma) return account; account.pleroma = normalizePleromaUserFields(account.pleroma); + delete account.pleroma.chat_token; return account; };