modals-are-closed-after-using-browsers-back-or-forward-option
[arvados-workbench2.git] / src / store / dialog / dialog-reducer.ts
index 48f8ee8a1e6caac149fb07b8c94a10a46a3f2377..775a4d5fce87eed6f93f30650bd3ad5148567ce2 100644 (file)
@@ -6,19 +6,24 @@ import { DialogAction, dialogActions } from "./dialog-actions";
 
 export type DialogState = Record<string, Dialog<any>>;
 
-export interface Dialog <T> {
+export interface Dialog<T> {
     open: boolean;
     data: T;
 }
 
-export const dialogReducer = (state: DialogState = {}, action: DialogAction) =>
+const initialState: DialogState = {};
+
+export const dialogReducer = (state: DialogState = initialState, action: DialogAction) =>
+
     dialogActions.match(action, {
         OPEN_DIALOG: ({ id, data }) => ({ ...state, [id]: { open: true, data } }),
-        CLOSE_DIALOG: ({ id }) => ({ 
-            ...state, 
-            [id]: state[id] ? { ...state[id], open: false } : { open: false, data: {} } }),
+        CLOSE_DIALOG: ({ id }) => ({
+            ...state,
+            [id]: state[id] ? { ...state[id], open: false } : { open: false, data: {} }
+        }),
+        CLOSE_ALL_DIALOGS: () => ({ ...initialState }),
         default: () => state,
     });
 
-export const getDialog = <T>(state: DialogState, id: string) => 
+export const getDialog = <T>(state: DialogState, id: string) =>
     state[id] ? state[id] as Dialog<T> : undefined;