X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/6f8e509988756deb7e05a760e718d1ade164fd19..5e8a5a1c42226e0dd3aceaf4825d870a3786c5d1:/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 index 190ad13f54..4889bace06 100644 --- a/src/store/progress-indicator/progress-indicator-reducer.ts +++ b/src/store/progress-indicator/progress-indicator-reducer.ts @@ -4,24 +4,26 @@ import { ProgressIndicatorAction, progressIndicatorActions } from "~/store/progress-indicator/progress-indicator-actions"; -export interface ProgressIndicatorState { - [key: string]: { - working: boolean - }; -} +export type ProgressIndicatorState = { id: string, working: boolean }[]; -const initialState: ProgressIndicatorState = { -}; +const initialState: ProgressIndicatorState = []; export const progressIndicatorReducer = (state: ProgressIndicatorState = initialState, action: ProgressIndicatorAction) => { + const startWorking = (id: string) => state.find(p => p.working) ? state : state.concat({ id, working: true }); + const stopWorking = (id: string) => state.filter(p => p.id !== id); + return progressIndicatorActions.match(action, { - START: id => ({ ...state, [id]: { working: true } }), - STOP: id => ({ ...state, [id]: { working: false } }), - TOGGLE: ({ id, working }) => ({ ...state, [id]: { working }}), + START: id => startWorking(id), + STOP: id => stopWorking(id), + PERSIST_STOP: id => state.map(p => ({ + id, + working: p.id === id ? false : p.working + })), + TOGGLE: ({ id, working }) => working ? startWorking(id) : stopWorking(id), default: () => state, }); }; export function isSystemWorking(state: ProgressIndicatorState): boolean { - return Object.keys(state).reduce((working, k) => working ? true : state[k].working, false); + return state.length > 0 && state.reduce((working, p) => working ? true : p.working, false); }