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