bigbuffet-rw/app/soapbox/actions/suggestions_v2.js
2021-09-16 18:46:04 -05:00

18 lines
836 B
JavaScript

import api from '../api';
import { importFetchedAccount } from './importer';
export const SUGGESTIONS_V2_FETCH_REQUEST = 'SUGGESTIONS_V2_FETCH_REQUEST';
export const SUGGESTIONS_V2_FETCH_SUCCESS = 'SUGGESTIONS_V2_FETCH_SUCCESS';
export const SUGGESTIONS_V2_FETCH_FAIL = 'SUGGESTIONS_V2_FETCH_FAIL';
export function fetchSuggestions() {
return (dispatch, getState) => {
dispatch({ type: SUGGESTIONS_V2_FETCH_REQUEST, skipLoading: true });
api(getState).get('/api/v2/suggestions').then(({ data: suggestions }) => {
suggestions.forEach(({ account }) => dispatch(importFetchedAccount(account)));
dispatch({ type: SUGGESTIONS_V2_FETCH_SUCCESS, suggestions, skipLoading: true });
}).catch(error => {
dispatch({ type: SUGGESTIONS_V2_FETCH_FAIL, error, skipLoading: true, skipAlert: true });
});
};
}