Fetch unfetched otherAccounts
This commit is contained in:
parent
0162eac662
commit
88420ccca6
|
@ -1,4 +1,6 @@
|
|||
import api from '../api';
|
||||
import { importFetchedAccount } from './importer';
|
||||
import { throttle } from 'lodash';
|
||||
import snackbar from 'soapbox/actions/snackbar';
|
||||
|
||||
export const SWITCH_ACCOUNT = 'SWITCH_ACCOUNT';
|
||||
|
@ -146,6 +148,7 @@ export function verifyCredentials(token) {
|
|||
};
|
||||
|
||||
return api(getState).request(request).then(({ data: account }) => {
|
||||
dispatch(importFetchedAccount(account));
|
||||
dispatch({ type: VERIFY_CREDENTIALS_SUCCESS, token, account });
|
||||
return account;
|
||||
}).catch(error => {
|
||||
|
@ -192,6 +195,18 @@ export function switchAccount(accountId) {
|
|||
return { type: SWITCH_ACCOUNT, accountId };
|
||||
}
|
||||
|
||||
export function fetchOwnAccounts() {
|
||||
return throttle((dispatch, getState) => {
|
||||
const state = getState();
|
||||
state.getIn(['auth', 'users']).forEach((token, id) => {
|
||||
const account = state.getIn(['accounts', id]);
|
||||
if (!account) {
|
||||
dispatch(verifyCredentials(token));
|
||||
}
|
||||
});
|
||||
}, 2000);
|
||||
}
|
||||
|
||||
export function register(params) {
|
||||
return (dispatch, getState) => {
|
||||
params.fullname = params.username;
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import api from '../api';
|
||||
import { importFetchedAccount } from './importer';
|
||||
import { List as ImmutableList } from 'immutable';
|
||||
import { verifyCredentials } from './auth';
|
||||
|
||||
export const ME_FETCH_REQUEST = 'ME_FETCH_REQUEST';
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
import React from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
// import { openModal } from '../../../actions/modal';
|
||||
import { fetchOwnAccounts } from 'soapbox/actions/auth';
|
||||
import PropTypes from 'prop-types';
|
||||
import ImmutablePropTypes from 'react-immutable-proptypes';
|
||||
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 { Map as ImmutableMap, List as ImmutableList } from 'immutable';
|
||||
import { List as ImmutableList } from 'immutable';
|
||||
|
||||
const messages = defineMessages({
|
||||
switch: { id: 'profile_dropdown.switch_account', defaultMessage: 'Switch to @{acct}' },
|
||||
|
@ -23,8 +24,8 @@ const mapStateToProps = state => {
|
|||
.keySeq()
|
||||
.reduce((list, id) => {
|
||||
if (id === me) return list;
|
||||
const account = state.getIn(['accounts', id]) || ImmutableMap({ id: id, acct: id });
|
||||
return list.push(account);
|
||||
const account = state.getIn(['accounts', id]);
|
||||
return account ? list.push(account) : list;
|
||||
}, ImmutableList());
|
||||
|
||||
return {
|
||||
|
@ -61,6 +62,14 @@ class ProfileDropdown extends React.PureComponent {
|
|||
};
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
this.props.dispatch(fetchOwnAccounts());
|
||||
}
|
||||
|
||||
componentDidUpdate() {
|
||||
this.props.dispatch(fetchOwnAccounts());
|
||||
}
|
||||
|
||||
render() {
|
||||
const { intl, account, otherAccounts } = this.props;
|
||||
const size = this.props.size || 16;
|
||||
|
|
Loading…
Reference in New Issue