mirror of
https://github.com/lidarr/lidarr.git
synced 2025-07-15 01:23:53 -07:00
Re-saving edited providers will forcibly save them
Fixes #1673 Co-Authored-By: Mark McDowall <markus101@users.noreply.github.com>
This commit is contained in:
parent
de830b9c1f
commit
c401581913
1 changed files with 16 additions and 9 deletions
|
@ -6,6 +6,7 @@ import getProviderState from 'Utilities/State/getProviderState';
|
||||||
import { removeItem, set, updateItem } from '../baseActions';
|
import { removeItem, set, updateItem } from '../baseActions';
|
||||||
|
|
||||||
const abortCurrentRequests = {};
|
const abortCurrentRequests = {};
|
||||||
|
let lastSaveData = null;
|
||||||
|
|
||||||
export function createCancelSaveProviderHandler(section) {
|
export function createCancelSaveProviderHandler(section) {
|
||||||
return function(getState, payload, dispatch) {
|
return function(getState, payload, dispatch) {
|
||||||
|
@ -27,27 +28,33 @@ function createSaveProviderHandler(section, url, options = {}, removeStale = fal
|
||||||
} = payload;
|
} = payload;
|
||||||
|
|
||||||
const saveData = Array.isArray(id) ? id.map((x) => getProviderState({ id: x, ...otherPayload }, getState, section)) : getProviderState({ id, ...otherPayload }, getState, section);
|
const saveData = Array.isArray(id) ? id.map((x) => getProviderState({ id: x, ...otherPayload }, getState, section)) : getProviderState({ id, ...otherPayload }, getState, section);
|
||||||
|
const requestUrl = id ? `${url}/${id}` : url;
|
||||||
|
const params = { ...queryParams };
|
||||||
|
|
||||||
|
// If the user is re-saving the same provider without changes
|
||||||
|
// force it to be saved. Only applies to editing existing providers.
|
||||||
|
|
||||||
|
if (id && _.isEqual(saveData, lastSaveData)) {
|
||||||
|
params.forceSave = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
lastSaveData = saveData;
|
||||||
|
|
||||||
const ajaxOptions = {
|
const ajaxOptions = {
|
||||||
url: `${url}?${$.param(queryParams, true)}`,
|
url: `${requestUrl}?${$.param(params, true)}`,
|
||||||
method: 'POST',
|
method: id ? 'PUT' : 'POST',
|
||||||
contentType: 'application/json',
|
contentType: 'application/json',
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
data: JSON.stringify(saveData)
|
data: JSON.stringify(saveData)
|
||||||
};
|
};
|
||||||
|
|
||||||
if (id) {
|
|
||||||
ajaxOptions.method = 'PUT';
|
|
||||||
if (!Array.isArray(id)) {
|
|
||||||
ajaxOptions.url = `${url}/${id}?${$.param(queryParams, true)}`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const { request, abortRequest } = createAjaxRequest(ajaxOptions);
|
const { request, abortRequest } = createAjaxRequest(ajaxOptions);
|
||||||
|
|
||||||
abortCurrentRequests[section] = abortRequest;
|
abortCurrentRequests[section] = abortRequest;
|
||||||
|
|
||||||
request.done((data) => {
|
request.done((data) => {
|
||||||
|
lastSaveData = null;
|
||||||
|
|
||||||
if (!Array.isArray(data)) {
|
if (!Array.isArray(data)) {
|
||||||
data = [data];
|
data = [data];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue