X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/e83b5a007f55a47a9acfa5c363c3f9f3bc7495de..4a4da2249d80ed4116f534689684abff61ee2cd9:/src/store/file-uploader/file-uploader-reducer.ts diff --git a/src/store/file-uploader/file-uploader-reducer.ts b/src/store/file-uploader/file-uploader-reducer.ts index cadafe01..4218fbee 100644 --- a/src/store/file-uploader/file-uploader-reducer.ts +++ b/src/store/file-uploader/file-uploader-reducer.ts @@ -3,7 +3,7 @@ // SPDX-License-Identifier: AGPL-3.0 import { UploadFile, fileUploaderActions, FileUploaderAction } from "./file-uploader-actions"; -import * as _ from 'lodash'; +import { uniqBy } from 'lodash'; export type UploaderState = UploadFile[]; @@ -33,7 +33,7 @@ export const fileUploaderReducer = (state: UploaderState = initialState, action: currentTime: 0 })); const updatedState = state.concat(updateFiles); - const uniqUpdatedState = _.uniqBy(updatedState, 'file.name'); + const uniqUpdatedState = uniqBy(updatedState, 'file.name'); return uniqUpdatedState; }, @@ -43,6 +43,21 @@ export const fileUploaderReducer = (state: UploaderState = initialState, action: return updatedState; }, + CANCEL_FILES_UPLOAD: () => { + state.forEach((file) => { + let interval = setInterval(() => { + const key = Object.keys((window as any).cancelTokens).find(key => key.indexOf(file.file.name) > -1); + + if (key) { + clearInterval(interval); + (window as any).cancelTokens[key](); + delete (window as any).cancelTokens[key]; + } + }, 100); + }); + + return []; + }, START_UPLOAD: () => { const startTime = Date.now(); return state.map(f => ({ ...f, startTime, prevTime: startTime }));