Create actions and reducer for favorites
[arvados-workbench2.git] / src / store / store.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { createStore, applyMiddleware, compose, Middleware, combineReducers } from 'redux';
6 import { routerMiddleware, routerReducer, RouterState } from "react-router-redux";
7 import thunkMiddleware from 'redux-thunk';
8 import { History } from "history";
9
10 import { projectsReducer, ProjectState } from "./project/project-reducer";
11 import { sidePanelReducer, SidePanelState } from './side-panel/side-panel-reducer';
12 import { authReducer, AuthState } from "./auth/auth-reducer";
13 import { dataExplorerReducer, DataExplorerState } from './data-explorer/data-explorer-reducer';
14 import { projectPanelMiddleware } from './project-panel/project-panel-middleware';
15 import { detailsPanelReducer, DetailsPanelState } from './details-panel/details-panel-reducer';
16 import { contextMenuReducer, ContextMenuState } from './context-menu/context-menu-reducer';
17 import { FavoritesState, favoritesReducer } from './favorites/favorites-reducer';
18
19 const composeEnhancers =
20     (process.env.NODE_ENV === 'development' &&
21         window && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__) ||
22     compose;
23
24 export interface RootState {
25     auth: AuthState;
26     projects: ProjectState;
27     router: RouterState;
28     dataExplorer: DataExplorerState;
29     sidePanel: SidePanelState;
30     detailsPanel: DetailsPanelState;
31     contextMenu: ContextMenuState;
32     favorites: FavoritesState;
33 }
34
35 const rootReducer = combineReducers({
36     auth: authReducer,
37     projects: projectsReducer,
38     router: routerReducer,
39     dataExplorer: dataExplorerReducer,
40     sidePanel: sidePanelReducer,
41     detailsPanel: detailsPanelReducer,
42     contextMenu: contextMenuReducer,
43     favorites: favoritesReducer,
44 });
45
46
47 export function configureStore(history: History) {
48     const middlewares: Middleware[] = [
49         routerMiddleware(history),
50         thunkMiddleware,
51         projectPanelMiddleware
52     ];
53     const enhancer = composeEnhancers(applyMiddleware(...middlewares));
54     return createStore(rootReducer, enhancer);
55 }