X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/5a40b5b582b25e410622da8b7e484fad757f6bd1..605e792e4854c7aad2f08e08fa7a8d9eba9d64a1:/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 f1044a9205..8c35ffa833 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({ @@ -21,46 +21,17 @@ export const collectionCreateActions = unionize({ 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(() => { - dispatch(collectionCreateActions.CREATE_COLLECTION_SUCCESS(collection)); - dispatch(reset('collectionCreateDialog')); - dispatch(collectionUploaderActions.CLEAR_UPLOAD()); - }); - return collection; - }); - }; - -export const uploadCollectionFiles = (collectionUuid: string, files: File[]) => - (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { - dispatch(collectionUploaderActions.START_UPLOAD()); - return services.collectionService.uploadFiles(collectionUuid, files, - (fileId, loaded, total, currentTime) => { - dispatch(collectionUploaderActions.SET_UPLOAD_PROGRESS({ fileId, loaded, total, currentTime })); - }) - .then(() => { - dispatch(collectionUploaderActions.CLEAR_UPLOAD()); - }); + const newCollection = await services.collectionService.create(collectiontData); + await dispatch(uploadCollectionFiles(newCollection.uuid)); + dispatch(collectionCreateActions.CREATE_COLLECTION_SUCCESS(collection)); + dispatch(reset('collectionCreateDialog')); + return newCollection; }; -export const uploadCurrentCollectionFiles = (files: File[]) => - (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { - const currentCollection = getState().collectionPanel.item; - if (currentCollection) { - return dispatch(uploadCollectionFiles(currentCollection.uuid, files)); - } - }; - -export type CollectionCreateAction = UnionOf;