Avoid re-loading already loaded relationships. Also fixes issue where wrong

button would be displayed in account lists for unloaded relationships
lolsob-rspec
Eugen Rochko 2017-04-02 22:02:38 +02:00
parent eb85833dc7
commit 4bfabbd5e2
2 changed files with 8 additions and 5 deletions

View File

@ -579,15 +579,18 @@ export function expandFollowingFail(id, error) {
}; };
}; };
export function fetchRelationships(account_ids) { export function fetchRelationships(accountIds) {
return (dispatch, getState) => { return (dispatch, getState) => {
if (account_ids.length === 0) { const loadedRelationships = getState().get('relationships');
const newAccountIds = accountIds.filter(id => loadedRelationships.get(id, null) === null);
if (newAccountIds.length === 0) {
return; return;
} }
dispatch(fetchRelationshipsRequest(account_ids)); dispatch(fetchRelationshipsRequest(newAccountIds));
api(getState).get(`/api/v1/accounts/relationships?${account_ids.map(id => `id[]=${id}`).join('&')}`).then(response => { api(getState).get(`/api/v1/accounts/relationships?${newAccountIds.map(id => `id[]=${id}`).join('&')}`).then(response => {
dispatch(fetchRelationshipsSuccess(response.data)); dispatch(fetchRelationshipsSuccess(response.data));
}).catch(error => { }).catch(error => {
dispatch(fetchRelationshipsFail(error)); dispatch(fetchRelationshipsFail(error));

View File

@ -5,7 +5,7 @@ const getStatuses = state => state.get('statuses');
const getAccounts = state => state.get('accounts'); const getAccounts = state => state.get('accounts');
const getAccountBase = (state, id) => state.getIn(['accounts', id], null); const getAccountBase = (state, id) => state.getIn(['accounts', id], null);
const getAccountRelationship = (state, id) => state.getIn(['relationships', id]); const getAccountRelationship = (state, id) => state.getIn(['relationships', id], null);
export const makeGetAccount = () => { export const makeGetAccount = () => {
return createSelector([getAccountBase, getAccountRelationship], (base, relationship) => { return createSelector([getAccountBase, getAccountRelationship], (base, relationship) => {