From 936aa32e065b7f672e27b95262720c2ce8258bf6 Mon Sep 17 00:00:00 2001 From: Pawel Kowalczyk Date: Thu, 13 Dec 2018 15:54:25 +0100 Subject: [PATCH] modals-are-closed-after-using-browsers-back-or-forward-option Feature #14489 Arvados-DCO-1.1-Signed-off-by: Pawel Kowalczyk --- src/routes/route-change-handlers.ts | 3 +++ src/store/dialog/dialog-actions.ts | 3 ++- src/store/dialog/dialog-reducer.ts | 17 +++++++++++------ 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/routes/route-change-handlers.ts b/src/routes/route-change-handlers.ts index c4b0fc7d..655c806f 100644 --- a/src/routes/route-change-handlers.ts +++ b/src/routes/route-change-handlers.ts @@ -7,6 +7,7 @@ import { RootStore } from '~/store/store'; import * as Routes from '~/routes/routes'; import * as WorkbenchActions from '~/store/workbench/workbench-actions'; import { navigateToRootProject } from '~/store/navigation/navigation-action'; +import { dialogActions } from '~/store/dialog/dialog-actions'; export const addRouteChangeHandlers = (history: History, store: RootStore) => { const handler = handleLocationChange(store); @@ -38,6 +39,8 @@ const handleLocationChange = (store: RootStore) => ({ pathname }: Location) => { const userMatch = Routes.matchUsersRoute(pathname); const linksMatch = Routes.matchLinksRoute(pathname); + store.dispatch(dialogActions.CLOSE_ALL_DIALOGS()); + if (projectMatch) { store.dispatch(WorkbenchActions.loadProject(projectMatch.params.id)); } else if (collectionMatch) { diff --git a/src/store/dialog/dialog-actions.ts b/src/store/dialog/dialog-actions.ts index 22629b69..ce01a50d 100644 --- a/src/store/dialog/dialog-actions.ts +++ b/src/store/dialog/dialog-actions.ts @@ -6,7 +6,8 @@ import { unionize, ofType, UnionOf } from "~/common/unionize"; export const dialogActions = unionize({ OPEN_DIALOG: ofType<{ id: string, data: any }>(), - CLOSE_DIALOG: ofType<{ id: string }>() + CLOSE_DIALOG: ofType<{ id: string }>(), + CLOSE_ALL_DIALOGS: ofType<{}>() }); export type DialogAction = UnionOf; diff --git a/src/store/dialog/dialog-reducer.ts b/src/store/dialog/dialog-reducer.ts index 48f8ee8a..775a4d5f 100644 --- a/src/store/dialog/dialog-reducer.ts +++ b/src/store/dialog/dialog-reducer.ts @@ -6,19 +6,24 @@ import { DialogAction, dialogActions } from "./dialog-actions"; export type DialogState = Record>; -export interface Dialog { +export interface Dialog { 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 = (state: DialogState, id: string) => +export const getDialog = (state: DialogState, id: string) => state[id] ? state[id] as Dialog : undefined; -- 2.30.2