Decoupled services from redux
[arvados-workbench2.git] / src / store / collection / collection-action.ts
index 5f1d60f3927e706b10c03dd7cfa836f32556ff7c..f50e6458ef4ec0549c005ef736ace716480ac652 100644 (file)
@@ -4,6 +4,8 @@
 
 import { Collection } from "../../models/collection";
 import { default as unionize, ofType, UnionOf } from "unionize";
+import { Dispatch } from "redux";
+import { collectionService } from "../../services/services";
 
 const actions = unionize({
     CREATE_COLLECTION: ofType<Collection>(),
@@ -15,5 +17,13 @@ const actions = unionize({
     value: 'payload'
 });
 
+export const getCollectionList = (parentUuid?: string) => (dispatch: Dispatch): Promise<Collection[]> => {
+    dispatch(actions.COLLECTIONS_REQUEST());
+    return collectionService.getCollectionList(parentUuid).then(collections => {
+        dispatch(actions.COLLECTIONS_SUCCESS({collections}));
+        return collections;
+    });
+};
+
 export type CollectionAction = UnionOf<typeof actions>;
 export default actions;