mirror of
https://github.com/Sonarr/Sonarr.git
synced 2026-04-21 22:05:38 -04:00
Manual Import: Reprocess after selecting series
New: Reprocess changed items when series is changed Closes #1893
This commit is contained in:
@@ -8,7 +8,7 @@ import { sortDirections } from 'Helpers/Props';
|
||||
import createSetClientSideCollectionSortReducer from './Creators/Reducers/createSetClientSideCollectionSortReducer';
|
||||
import createFetchHandler from './Creators/createFetchHandler';
|
||||
import createHandleActions from './Creators/createHandleActions';
|
||||
import { set, update } from './baseActions';
|
||||
import { set, update, updateItem } from './baseActions';
|
||||
|
||||
//
|
||||
// Variables
|
||||
@@ -16,6 +16,8 @@ import { set, update } from './baseActions';
|
||||
export const section = 'interactiveImport';
|
||||
|
||||
const episodesSection = `${section}.episodes`;
|
||||
let abortCurrentRequest = null;
|
||||
let currentIds = [];
|
||||
|
||||
//
|
||||
// State
|
||||
@@ -49,6 +51,7 @@ export const defaultState = {
|
||||
|
||||
episodes: {
|
||||
isFetching: false,
|
||||
isReprocessing: false,
|
||||
isPopulated: false,
|
||||
error: null,
|
||||
sortKey: 'episodeNumber',
|
||||
@@ -66,6 +69,7 @@ export const persistState = [
|
||||
// Actions Types
|
||||
|
||||
export const FETCH_INTERACTIVE_IMPORT_ITEMS = 'interactiveImport/fetchInteractiveImportItems';
|
||||
export const REPROCESS_INTERACTIVE_IMPORT_ITEMS = 'interactiveImport/reprocessInteractiveImportItems';
|
||||
export const SET_INTERACTIVE_IMPORT_SORT = 'interactiveImport/setInteractiveImportSort';
|
||||
export const UPDATE_INTERACTIVE_IMPORT_ITEM = 'interactiveImport/updateInteractiveImportItem';
|
||||
export const UPDATE_INTERACTIVE_IMPORT_ITEMS = 'interactiveImport/updateInteractiveImportItems';
|
||||
@@ -82,6 +86,7 @@ export const CLEAR_INTERACTIVE_IMPORT_EPISODES = 'interactiveImport/clearInterac
|
||||
// Action Creators
|
||||
|
||||
export const fetchInteractiveImportItems = createThunk(FETCH_INTERACTIVE_IMPORT_ITEMS);
|
||||
export const reprocessInteractiveImportItems = createThunk(REPROCESS_INTERACTIVE_IMPORT_ITEMS);
|
||||
export const setInteractiveImportSort = createAction(SET_INTERACTIVE_IMPORT_SORT);
|
||||
export const updateInteractiveImportItem = createAction(UPDATE_INTERACTIVE_IMPORT_ITEM);
|
||||
export const updateInteractiveImportItems = createAction(UPDATE_INTERACTIVE_IMPORT_ITEMS);
|
||||
@@ -133,6 +138,72 @@ export const actionHandlers = handleThunks({
|
||||
});
|
||||
},
|
||||
|
||||
[REPROCESS_INTERACTIVE_IMPORT_ITEMS]: function(getState, payload, dispatch) {
|
||||
if (abortCurrentRequest) {
|
||||
abortCurrentRequest();
|
||||
}
|
||||
|
||||
dispatch(batchActions([
|
||||
...currentIds.map((id) => updateItem({
|
||||
section,
|
||||
id,
|
||||
isReprocessing: false
|
||||
})),
|
||||
...payload.ids.map((id) => updateItem({
|
||||
section,
|
||||
id,
|
||||
isReprocessing: true
|
||||
}))
|
||||
]));
|
||||
|
||||
const items = getState()[section].items;
|
||||
|
||||
const requestPayload = payload.ids.map((id) => {
|
||||
const item = items.find((i) => i.id === id);
|
||||
|
||||
return {
|
||||
id,
|
||||
path: item.path,
|
||||
seriesId: item.series.id,
|
||||
downloadId: item.downloadId
|
||||
};
|
||||
});
|
||||
|
||||
const { request, abortRequest } = createAjaxRequest({
|
||||
method: 'POST',
|
||||
url: '/manualimport',
|
||||
contentType: 'application/json',
|
||||
data: JSON.stringify(requestPayload)
|
||||
});
|
||||
|
||||
abortCurrentRequest = abortRequest;
|
||||
currentIds = payload.ids;
|
||||
|
||||
request.done((data) => {
|
||||
dispatch(batchActions(
|
||||
data.map((item) => updateItem({
|
||||
section,
|
||||
...item,
|
||||
isReprocessing: false
|
||||
}))
|
||||
));
|
||||
});
|
||||
|
||||
request.fail((xhr) => {
|
||||
if (xhr.aborted) {
|
||||
return;
|
||||
}
|
||||
|
||||
dispatch(batchActions(
|
||||
payload.ids.map((id) => updateItem({
|
||||
section,
|
||||
id,
|
||||
isReprocessing: false
|
||||
}))
|
||||
));
|
||||
});
|
||||
},
|
||||
|
||||
[FETCH_INTERACTIVE_IMPORT_EPISODES]: createFetchHandler('interactiveImport.episodes', '/episode')
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user