Readarr/frontend/src/Store/Actions/interactiveImportActionHandlers.js
2017-09-05 23:00:26 -04:00

48 lines
1.1 KiB
JavaScript

import $ from 'jquery';
import { batchActions } from 'redux-batched-actions';
import * as types from './actionTypes';
import { set, update } from './baseActions';
const section = 'interactiveImport';
const interactiveImportActionHandlers = {
[types.FETCH_INTERACTIVE_IMPORT_ITEMS]: function(payload) {
return function(dispatch, getState) {
if (!payload.downloadId && !payload.folder) {
dispatch(set({ section, error: { message: '`downloadId` or `folder` is required.' } }));
return;
}
dispatch(set({ section, isFetching: true }));
const promise = $.ajax({
url: '/manualimport',
data: payload
});
promise.done((data) => {
dispatch(batchActions([
update({ section, data }),
set({
section,
isFetching: false,
isPopulated: true,
error: null
})
]));
});
promise.fail((xhr) => {
dispatch(set({
section,
isFetching: false,
isPopulated: false,
error: xhr
}));
});
};
}
};
export default interactiveImportActionHandlers;