X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/876e5e2f31a218255845977489ea70aacc0211cd..540750a7749cb71ea0a8fde4b7a3689eeaa1c3dd:/src/store/collections/creator/collection-creator-action.ts diff --git a/src/store/collections/creator/collection-creator-action.ts b/src/store/collections/creator/collection-creator-action.ts index 323ba8d8..8c35ffa8 100644 --- a/src/store/collections/creator/collection-creator-action.ts +++ b/src/store/collections/creator/collection-creator-action.ts @@ -8,7 +8,7 @@ import { Dispatch } from "redux"; import { RootState } from "../../store"; import { CollectionResource } from '~/models/collection'; import { ServiceRepository } from "~/services/services"; -import { collectionUploaderActions } from "../uploader/collection-uploader-actions"; +import { uploadCollectionFiles } from '../uploader/collection-uploader-actions'; import { reset } from "redux-form"; export const collectionCreateActions = unionize({ @@ -17,30 +17,21 @@ export const collectionCreateActions = unionize({ CREATE_COLLECTION: ofType<{}>(), CREATE_COLLECTION_SUCCESS: ofType<{}>(), }, { - tag: 'type', - value: 'payload' -}); + tag: 'type', + value: 'payload' + }); + +export type CollectionCreateAction = UnionOf; export const createCollection = (collection: Partial, files: File[]) => - (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { + async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { const { ownerUuid } = getState().collections.creator; const collectiontData = { ownerUuid, ...collection }; dispatch(collectionCreateActions.CREATE_COLLECTION(collectiontData)); - return services.collectionService - .create(collectiontData) - .then(collection => { - dispatch(collectionUploaderActions.START_UPLOAD()); - services.collectionService.uploadFiles(collection.uuid, files, - (fileId, loaded, total, currentTime) => { - dispatch(collectionUploaderActions.SET_UPLOAD_PROGRESS({ fileId, loaded, total, currentTime })); - }) - .then(collection => { - dispatch(collectionCreateActions.CREATE_COLLECTION_SUCCESS(collection)); - dispatch(reset('collectionCreateDialog')); - dispatch(collectionUploaderActions.CLEAR_UPLOAD()); - }); - return collection; - }); + const newCollection = await services.collectionService.create(collectiontData); + await dispatch(uploadCollectionFiles(newCollection.uuid)); + dispatch(collectionCreateActions.CREATE_COLLECTION_SUCCESS(collection)); + dispatch(reset('collectionCreateDialog')); + return newCollection; }; -export type CollectionCreateAction = UnionOf;