X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/4b065bb111ccdfdde1756e6507b84b72ce67c511..40952ad86a823635968c9abc5d6feacef316cffd:/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 2a977e33ad..d0a66b4cc0 100644 --- a/src/store/collections/creator/collection-creator-action.ts +++ b/src/store/collections/creator/collection-creator-action.ts @@ -6,8 +6,10 @@ import { default as unionize, ofType, UnionOf } from "unionize"; import { Dispatch } from "redux"; import { RootState } from "../../store"; -import { collectionService } from '../../../services/services'; import { CollectionResource } from '../../../models/collection'; +import { ServiceRepository } from "../../../services/services"; +import { collectionUploaderActions } from "../uploader/collection-uploader-actions"; +import { reset } from "redux-form"; export const collectionCreateActions = unionize({ OPEN_COLLECTION_CREATOR: ofType<{ ownerUuid: string }>(), @@ -15,18 +17,30 @@ export const collectionCreateActions = unionize({ CREATE_COLLECTION: ofType<{}>(), CREATE_COLLECTION_SUCCESS: ofType<{}>(), }, { - tag: 'type', - value: 'payload' - }); + tag: 'type', + value: 'payload' +}); -export const createCollection = (collection: Partial) => - (dispatch: Dispatch, getState: () => RootState) => { +export const createCollection = (collection: Partial, files: File[]) => + (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { const { ownerUuid } = getState().collections.creator; const collectiontData = { ownerUuid, ...collection }; dispatch(collectionCreateActions.CREATE_COLLECTION(collectiontData)); - return collectionService + return services.collectionService .create(collectiontData) - .then(collection => dispatch(collectionCreateActions.CREATE_COLLECTION_SUCCESS(collection))); + .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; + }); }; -export type CollectionCreateAction = UnionOf; \ No newline at end of file +export type CollectionCreateAction = UnionOf;