mirror of
https://github.com/Prowlarr/Prowlarr.git
synced 2026-04-24 22:55:21 -04:00
New: Project Aphrodite
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
import $ from 'jquery';
|
||||
import { batchActions } from 'redux-batched-actions';
|
||||
import getSectionState from 'Utilities/State/getSectionState';
|
||||
import { set, update } from '../baseActions';
|
||||
|
||||
function createSaveHandler(section, url) {
|
||||
return function(getState, payload, dispatch) {
|
||||
dispatch(set({ section, isSaving: true }));
|
||||
|
||||
const state = getSectionState(getState(), section, true);
|
||||
const saveData = Object.assign({}, state.item, state.pendingChanges, payload);
|
||||
|
||||
const promise = $.ajax({
|
||||
url,
|
||||
method: 'PUT',
|
||||
dataType: 'json',
|
||||
data: JSON.stringify(saveData)
|
||||
});
|
||||
|
||||
promise.done((data) => {
|
||||
dispatch(batchActions([
|
||||
update({ section, data }),
|
||||
|
||||
set({
|
||||
section,
|
||||
isSaving: false,
|
||||
saveError: null,
|
||||
pendingChanges: {}
|
||||
})
|
||||
]));
|
||||
});
|
||||
|
||||
promise.fail((xhr) => {
|
||||
dispatch(set({
|
||||
section,
|
||||
isSaving: false,
|
||||
saveError: xhr
|
||||
}));
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
export default createSaveHandler;
|
||||
Reference in New Issue
Block a user