You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Lidarr/frontend/src/Store/Actions/Creators/createRemoveItemHandler.js

46 lines
919 B

import $ from 'jquery';
import { batchActions } from 'redux-batched-actions';
import { set, removeItem } from '../baseActions';
function createRemoveItemHandler(section, url) {
return function(getState, payload, dispatch) {
const {
id,
...queryParams
} = payload;
dispatch(set({ section, isDeleting: true }));
const ajaxOptions = {
url: `${url}/${id}?${$.param(queryParams, true)}`,
method: 'DELETE'
};
const promise = $.ajax(ajaxOptions);
promise.done((data) => {
dispatch(batchActions([
set({
section,
isDeleting: false,
deleteError: null
}),
removeItem({ section, id })
]));
});
promise.fail((xhr) => {
dispatch(set({
section,
isDeleting: false,
deleteError: xhr
}));
});
return promise;
};
}
export default createRemoveItemHandler;