From 663d375dc5b5e165c03e1a9afbe2e3f6f4a3ed70 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Thu, 25 Mar 2021 13:47:01 -0500 Subject: [PATCH] Throttle fetchOwnAccounts correctly --- app/soapbox/actions/auth.js | 5 ++--- .../features/ui/components/profile_dropdown.js | 11 ++++++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/soapbox/actions/auth.js b/app/soapbox/actions/auth.js index 6b0418b8b..6b74c6234 100644 --- a/app/soapbox/actions/auth.js +++ b/app/soapbox/actions/auth.js @@ -1,6 +1,5 @@ import api from '../api'; import { importFetchedAccount } from './importer'; -import { throttle } from 'lodash'; import snackbar from 'soapbox/actions/snackbar'; export const SWITCH_ACCOUNT = 'SWITCH_ACCOUNT'; @@ -197,7 +196,7 @@ export function switchAccount(accountId) { } export function fetchOwnAccounts() { - return throttle((dispatch, getState) => { + return (dispatch, getState) => { const state = getState(); state.getIn(['auth', 'users']).forEach(user => { const account = state.getIn(['accounts', user.get('id')]); @@ -205,7 +204,7 @@ export function fetchOwnAccounts() { dispatch(verifyCredentials(user.get('access_token'))); } }); - }, 2000); + }; } export function register(params) { diff --git a/app/soapbox/features/ui/components/profile_dropdown.js b/app/soapbox/features/ui/components/profile_dropdown.js index 0836682ba..34311ca17 100644 --- a/app/soapbox/features/ui/components/profile_dropdown.js +++ b/app/soapbox/features/ui/components/profile_dropdown.js @@ -2,6 +2,7 @@ import React from 'react'; import { connect } from 'react-redux'; import { openModal } from '../../../actions/modal'; import { fetchOwnAccounts } from 'soapbox/actions/auth'; +import { throttle } from 'lodash'; import PropTypes from 'prop-types'; import ImmutablePropTypes from 'react-immutable-proptypes'; import DropdownMenuContainer from '../../../containers/dropdown_menu_container'; @@ -69,12 +70,16 @@ class ProfileDropdown extends React.PureComponent { e.preventDefault(); } - componentDidMount() { + fetchOwnAccounts = throttle(() => { this.props.dispatch(fetchOwnAccounts()); + }, 2000); + + componentDidMount() { + this.fetchOwnAccounts(); } componentDidUpdate() { - this.props.dispatch(fetchOwnAccounts()); + this.fetchOwnAccounts(); } renderAccount = account => { @@ -104,7 +109,7 @@ class ProfileDropdown extends React.PureComponent { menu.push(null); } - menu.push({ text: intl.formatMessage(messages.add), action: this.handleAddAccount }); + menu.push({ text: intl.formatMessage(messages.add), to: '/auth/sign_in' }); menu.push({ text: intl.formatMessage(messages.logout, { acct: account.get('acct') }), to: '/auth/sign_out', action: this.handleLogOut }); return (