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);
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) {
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<typeof dialogActions>;
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;