bigbuffet-rw/app/soapbox/actions/import_follows.js

31 lines
896 B
JavaScript

import api from '../api';
export const IMPORT_FOLLOWS_REQUEST = 'IMPORT_FOLLOWS_REQUEST';
export const IMPORT_FOLLOWS_SUCCESS = 'IMPORT_FOLLOWS_SUCCESS';
export const IMPORT_FOLLOWS_FAIL = 'IMPORT_FOLLOWS_FAIL';
function getData(path) {
var request = new XMLHttpRequest();
request.open('GET', path, false); // `false` makes the request synchronous
request.send(null);
if (request.status === 200) {
return request.responseText;
}
return null;
}
export function importFollows(path) {
return (dispatch, getState) => {
dispatch({ type: IMPORT_FOLLOWS_REQUEST });
return api(getState)
.post('/api/pleroma/follow_import', {
list: getData(path),
})
.then(response => {
dispatch({ type: IMPORT_FOLLOWS_SUCCESS, config: response.data });
}).catch(error => {
dispatch({ type: IMPORT_FOLLOWS_FAIL, error });
});
};
}