1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { History, Location } from 'history';
6 import { RootStore } from '~/store/store';
7 import { matchProcessRoute, matchProcessLogRoute, matchProjectRoute, matchCollectionRoute, matchFavoritesRoute, matchTrashRoute, matchRootRoute } from './routes';
8 import { loadProject, loadCollection, loadFavorites, loadTrash, loadProcess, loadProcessLog } from '~/store/workbench/workbench-actions';
9 import { navigateToRootProject } from '~/store/navigation/navigation-action';
11 export const addRouteChangeHandlers = (history: History, store: RootStore) => {
12 const handler = handleLocationChange(store);
13 handler(history.location);
14 history.listen(handler);
17 const handleLocationChange = (store: RootStore) => ({ pathname }: Location) => {
18 const rootMatch = matchRootRoute(pathname);
19 const projectMatch = matchProjectRoute(pathname);
20 const collectionMatch = matchCollectionRoute(pathname);
21 const favoriteMatch = matchFavoritesRoute(pathname);
22 const trashMatch = matchTrashRoute(pathname);
23 const processMatch = matchProcessRoute(pathname);
24 const processLogMatch = matchProcessLogRoute(pathname);
27 store.dispatch(loadProject(projectMatch.params.id));
28 } else if (collectionMatch) {
29 store.dispatch(loadCollection(collectionMatch.params.id));
30 } else if (favoriteMatch) {
31 store.dispatch(loadFavorites());
32 } else if (trashMatch) {
33 store.dispatch(loadTrash());
34 } else if (processMatch) {
35 store.dispatch(loadProcess(processMatch.params.id));
36 } else if (processLogMatch) {
37 store.dispatch(loadProcessLog(processLogMatch.params.id));
38 } else if (rootMatch) {
39 store.dispatch(navigateToRootProject);