Throttle fetchOwnAccounts correctly

This commit is contained in:
Alex Gleason 2021-03-25 13:47:01 -05:00
parent c14fc83ac1
commit 663d375dc5
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
2 changed files with 10 additions and 6 deletions

View file

@ -1,6 +1,5 @@
import api from '../api'; import api from '../api';
import { importFetchedAccount } from './importer'; import { importFetchedAccount } from './importer';
import { throttle } from 'lodash';
import snackbar from 'soapbox/actions/snackbar'; import snackbar from 'soapbox/actions/snackbar';
export const SWITCH_ACCOUNT = 'SWITCH_ACCOUNT'; export const SWITCH_ACCOUNT = 'SWITCH_ACCOUNT';
@ -197,7 +196,7 @@ export function switchAccount(accountId) {
} }
export function fetchOwnAccounts() { export function fetchOwnAccounts() {
return throttle((dispatch, getState) => { return (dispatch, getState) => {
const state = getState(); const state = getState();
state.getIn(['auth', 'users']).forEach(user => { state.getIn(['auth', 'users']).forEach(user => {
const account = state.getIn(['accounts', user.get('id')]); const account = state.getIn(['accounts', user.get('id')]);
@ -205,7 +204,7 @@ export function fetchOwnAccounts() {
dispatch(verifyCredentials(user.get('access_token'))); dispatch(verifyCredentials(user.get('access_token')));
} }
}); });
}, 2000); };
} }
export function register(params) { export function register(params) {

View file

@ -2,6 +2,7 @@ import React from 'react';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { openModal } from '../../../actions/modal'; import { openModal } from '../../../actions/modal';
import { fetchOwnAccounts } from 'soapbox/actions/auth'; import { fetchOwnAccounts } from 'soapbox/actions/auth';
import { throttle } from 'lodash';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import ImmutablePropTypes from 'react-immutable-proptypes'; import ImmutablePropTypes from 'react-immutable-proptypes';
import DropdownMenuContainer from '../../../containers/dropdown_menu_container'; import DropdownMenuContainer from '../../../containers/dropdown_menu_container';
@ -69,12 +70,16 @@ class ProfileDropdown extends React.PureComponent {
e.preventDefault(); e.preventDefault();
} }
componentDidMount() { fetchOwnAccounts = throttle(() => {
this.props.dispatch(fetchOwnAccounts()); this.props.dispatch(fetchOwnAccounts());
}, 2000);
componentDidMount() {
this.fetchOwnAccounts();
} }
componentDidUpdate() { componentDidUpdate() {
this.props.dispatch(fetchOwnAccounts()); this.fetchOwnAccounts();
} }
renderAccount = account => { renderAccount = account => {
@ -104,7 +109,7 @@ class ProfileDropdown extends React.PureComponent {
menu.push(null); 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 }); menu.push({ text: intl.formatMessage(messages.logout, { acct: account.get('acct') }), to: '/auth/sign_out', action: this.handleLogOut });
return ( return (