init search and display results
[arvados-workbench2.git] / src / store / search-bar / search-bar-reducer.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { searchBarActions, SearchBarActions } from '~/store/search-bar/search-bar-actions';
6 import { GroupContentsResource } from '~/services/groups-service/groups-service';
7
8 interface SearchBar {
9     currentView: string;
10     open: boolean;
11     searchResults: GroupContentsResource[];
12 }
13
14 export enum SearchView {
15     BASIC = 'basic',
16     ADVANCED = 'advanced',
17     AUTOCOMPLETE = 'autocomplete'
18 }
19
20 const initialState: SearchBar = {
21     currentView: SearchView.BASIC,
22     open: false,
23     searchResults: []
24 };
25
26 export const searchBarReducer = (state = initialState, action: SearchBarActions): SearchBar =>
27     searchBarActions.match(action, {
28         SET_CURRENT_VIEW: currentView => ({ ...state, currentView }),
29         OPEN_SEARCH_VIEW: () => ({ ...state, open: true }),
30         CLOSE_SEARCH_VIEW: () => ({ ...state, open: false }),
31         SET_SEARCH_RESULTS: (searchResults) => ({ ...state, searchResults }),
32         default: () => state
33     });