Merge branch 'master' of git.curoverse.com:arvados-workbench2 into 14307-search-basic...
[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
7 interface SearchBar {
8     currentView: string;
9     open: boolean;
10 }
11
12 export enum SearchView {
13     BASIC = 'basic',
14     ADVANCED = 'advanced',
15     AUTOCOMPLETE = 'autocomplete'
16 }
17
18 const initialState: SearchBar = {
19     currentView: SearchView.BASIC,
20     open: false
21 };
22
23 export const searchBarReducer = (state = initialState, action: SearchBarActions): SearchBar =>
24     searchBarActions.match(action, {
25         SET_CURRENT_VIEW: currentView => ({ ...state, currentView }),
26         OPEN_SEARCH_VIEW: () => ({ ...state, open: true }),
27         CLOSE_SEARCH_VIEW: () => ({ ...state, open: false }),
28         default: () => state
29     });