Create collection files upload dialog
[arvados-workbench2.git] / src / store / collections / creator / collection-creator-action.ts
index a3a6bf8a59f4ec57d74de6f3a4186bf6bfa6f9bb..f1044a9205da7f96d08fc8612e3633913b3aade1 100644 (file)
@@ -43,4 +43,24 @@ export const createCollection = (collection: Partial<CollectionResource>, files:
             });
     };
 
+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());
+            });
+    };
+
+export const uploadCurrentCollectionFiles = (files: File[]) =>
+    (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
+        const currentCollection = getState().collectionPanel.item;
+        if (currentCollection) {
+            return dispatch<any>(uploadCollectionFiles(currentCollection.uuid, files));
+        }
+    };
+
 export type CollectionCreateAction = UnionOf<typeof collectionCreateActions>;