X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/5e8a5a1c42226e0dd3aceaf4825d870a3786c5d1..52a9925b1ab918d66f1508c948e0db8e99568ccf:/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 4889bace..dbd1beb3 100644 --- a/src/store/progress-indicator/progress-indicator-reducer.ts +++ b/src/store/progress-indicator/progress-indicator-reducer.ts @@ -9,21 +9,32 @@ export type ProgressIndicatorState = { id: string, working: boolean }[]; 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 => startWorking(id), - STOP: id => stopWorking(id), - PERSIST_STOP: id => state.map(p => ({ - id, + START_WORKING: id => startWorking(id, state), + STOP_WORKING: id => stopWorking(id), + PERSIST_STOP_WORKING: id => state.map(p => ({ + ...p, working: p.id === id ? false : p.working })), - TOGGLE: ({ id, working }) => working ? startWorking(id) : stopWorking(id), + TOGGLE_WORKING: ({ id, working }) => working ? startWorking(id, state) : stopWorking(id), default: () => state, }); }; +const startWorking = (id: string, state: ProgressIndicatorState) => { + return getProgressIndicator(id)(state) + ? state.map(indicator => indicator.id === id + ? { ...indicator, working: true } + : indicator) + : state.concat({ id, working: true }); +}; + export function isSystemWorking(state: ProgressIndicatorState): boolean { return state.length > 0 && state.reduce((working, p) => working ? true : p.working, false); } + +export const getProgressIndicator = (id: string) => + (state: ProgressIndicatorState) => + state.find(state => state.id === id);