side-panel-progress
[arvados.git] / src / store / progress-indicator / progress-indicator-reducer.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { ProgressIndicatorAction, progressIndicatorActions } from "~/store/progress-indicator/progress-indicator-actions";
6 import { Dispatch } from 'redux';
7 import { RootState } from '~/store/store';
8 import { ServiceRepository } from '~/services/services';
9
10 export interface ProgressIndicatorState {
11     'sidePanelProgress': { started: boolean };
12     'contentProgress': { started: boolean };
13     // 'workbenchProgress': { started: boolean };
14 }
15
16 const initialState: ProgressIndicatorState = {
17     'sidePanelProgress': { started: false },
18     'contentProgress': { started: false },
19     // 'workbenchProgress': { started: false }
20 };
21
22 export enum ProgressIndicatorData {
23     SIDE_PANEL_PROGRESS = 'sidePanelProgress',
24     CONTENT_PROGRESS = 'contentProgress',
25     // WORKBENCH_PROGRESS = 'workbenchProgress',
26 }
27
28 export const progressIndicatorReducer = (state: ProgressIndicatorState = initialState, action: ProgressIndicatorAction) => {
29     return progressIndicatorActions.match(action, {
30         START_SUBMIT: ({ id }) => ({ ...state, [id]: { started: true } }),
31         STOP_SUBMIT: ({ id }) => ({
32             ...state,
33             [id]: state[id] ? { ...state[id], started: false } : { started: false }
34         }),
35         default: () => state,
36     });
37 };
38
39 // export const getProgress = () =>
40 //     (dispatch: Dispatch, getState: () => RootState) => {
41 //         const progress = getState().progressIndicator;
42 //         if (progress.sidePanelProgress.started || progress.contentProgress.started) {
43 //             dispatch(progressIndicatorActions.START_SUBMIT({ id: ProgressIndicatorData.WORKBENCH_PROGRESS }));
44 //         } else {
45 //             dispatch(progressIndicatorActions.STOP_SUBMIT({ id: ProgressIndicatorData.WORKBENCH_PROGRESS }));
46 //         }
47 //     };