progress-indicator-store-and-HOC
[arvados-workbench2.git] / src / store / progress-indicator / progress-indicator-reducer.ts
diff --git a/src/store/progress-indicator/progress-indicator-reducer.ts b/src/store/progress-indicator/progress-indicator-reducer.ts
new file mode 100644 (file)
index 0000000..7e1c236
--- /dev/null
@@ -0,0 +1,34 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import { ProgressIndicatorAction, progressIndicatorActions } from "~/store/progress-indicator/progress-indicator-actions";
+
+export interface ProgressIndicatorState {
+    'workbenchProgress': { started: boolean };
+    'contentProgress': { started: boolean };
+    'detailsProgress': { started: boolean };
+}
+
+const initialState: ProgressIndicatorState = {
+    'workbenchProgress': { started: false },
+    'contentProgress': { started: false },
+    'detailsProgress': { started: false }
+};
+
+export enum ProgressIndicatorData {
+    WORKBENCH_PROGRESS = 'workbenchProgress',
+    CONTENT_PROGRESS = 'contentProgress',
+    DETAILS_PROGRESS = 'detailsProgress'
+}
+
+export const progressIndicatorReducer = (state: ProgressIndicatorState = initialState, action: ProgressIndicatorAction) => {
+    return progressIndicatorActions.match(action, {
+        START_SUBMIT: ({ id }) => ({ ...state, [id]: { started: true } }),
+        STOP_SUBMIT: ({ id }) => ({
+            ...state,
+            [id]: state[id] ? { ...state[id], started: false } : { started: false }
+        }),
+        default: () => state,
+    });
+};