Throttle fetchOwnAccounts correctly

merge-requests/451/head
Alex Gleason 2021-03-25 13:47:01 -05:00
rodzic c14fc83ac1
commit 663d375dc5
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 7211D1F99744FBB7
2 zmienionych plików z 10 dodań i 6 usunięć

Wyświetl plik

@ -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) {

Wyświetl plik

@ -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 (