Skip to content

Commit

Permalink
Fixed: Abort old fetch items requests in manual import
Browse files Browse the repository at this point in the history
Fixes #4375
  • Loading branch information
mynameisbogdan committed Dec 22, 2023
1 parent 761e34f commit 9f6302e
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions frontend/src/Store/Actions/interactiveImportActions.js
Expand Up @@ -18,6 +18,7 @@ export const section = 'interactiveImport';

const albumsSection = `${section}.albums`;
const trackFilesSection = `${section}.trackFiles`;
let abortCurrentFetchRequest = null;
let abortCurrentRequest = null;
let currentIds = [];

Expand Down Expand Up @@ -127,19 +128,26 @@ export const clearInteractiveImportTrackFiles = createAction(CLEAR_INTERACTIVE_I
// Action Handlers
export const actionHandlers = handleThunks({
[FETCH_INTERACTIVE_IMPORT_ITEMS]: function(getState, payload, dispatch) {
if (abortCurrentFetchRequest) {
abortCurrentFetchRequest();
abortCurrentFetchRequest = null;
}

if (!payload.downloadId && !payload.folder) {
dispatch(set({ section, error: { message: '`downloadId` or `folder` is required.' } }));
return;
}

dispatch(set({ section, isFetching: true }));

const promise = createAjaxRequest({
const { request, abortRequest } = createAjaxRequest({
url: '/manualimport',
data: payload
}).request;
});

abortCurrentFetchRequest = abortRequest;

promise.done((data) => {
request.done((data) => {
dispatch(batchActions([
update({ section, data }),

Expand All @@ -152,7 +160,11 @@ export const actionHandlers = handleThunks({
]));
});

promise.fail((xhr) => {
request.fail((xhr) => {
if (xhr.aborted) {
return;
}

dispatch(set({
section,
isFetching: false,
Expand Down

0 comments on commit 9f6302e

Please sign in to comment.