1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { default as unionize, ofType, UnionOf } from "unionize";
6 import { Dispatch } from "redux";
8 import { RootState } from "../../store";
9 import { CollectionResource } from '../../../models/collection';
10 import { ServiceRepository } from "../../../services/services";
11 import { collectionUploaderActions } from "../uploader/collection-uploader-actions";
13 export const collectionCreateActions = unionize({
14 OPEN_COLLECTION_CREATOR: ofType<{ ownerUuid: string }>(),
15 CLOSE_COLLECTION_CREATOR: ofType<{}>(),
16 CREATE_COLLECTION: ofType<{}>(),
17 CREATE_COLLECTION_SUCCESS: ofType<{}>(),
23 export const createCollection = (collection: Partial<CollectionResource>, files: File[]) =>
24 (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
25 const { ownerUuid } = getState().collections.creator;
26 const collectiontData = { ownerUuid, ...collection };
27 dispatch(collectionCreateActions.CREATE_COLLECTION(collectiontData));
28 return services.collectionService
29 .create(collectiontData)
31 dispatch(collectionUploaderActions.START_UPLOAD());
32 services.collectionService.uploadFiles(collection.uuid, files,
33 (fileId, loaded, total, currentTime) => {
34 dispatch(collectionUploaderActions.SET_UPLOAD_PROGRESS({ fileId, loaded, total, currentTime }));
37 dispatch(collectionCreateActions.CREATE_COLLECTION_SUCCESS(collection));
43 export type CollectionCreateAction = UnionOf<typeof collectionCreateActions>;