-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
52 lines (41 loc) · 1.27 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import type { BaseFacetState, FacetFilterObject, FacetFilter } from "./facets";
import type { SortOrder, FSResponse } from "./use-search/types";
import React from "react";
import { FacetsDataReducerAction } from "./actions";
/**
* SearchState
*
* Context to keep the state of the full text input and the facets. This
* context is also used in other parts of the Docere UI to adjust the
* search state.
*/
type FacetStates = Map<string, BaseFacetState>;
export interface SearchState {
currentPage: number;
sortOrder: SortOrder;
searchResult: FSResponse | undefined;
facetValues: Record<string, any>;
facetStates: FacetStates;
facetFilters: Map<string, FacetFilterObject<FacetFilter>>;
query: string;
initialSearchResult?: FSResponse;
initialFacetStates?: FacetStates;
initialFacetValues?: Record<string, any>;
loading: boolean;
error?: any;
}
export const intialSearchState = {
currentPage: 1,
facetFilters: new Map(),
facetStates: new Map(),
facetValues: {},
query: "",
searchResult: undefined,
sortOrder: new Map(),
loading: false,
};
export const SearchStateContext =
React.createContext<SearchState>(intialSearchState);
export const SearchStateDispatchContext = React.createContext<
React.Dispatch<FacetsDataReducerAction>
>(() => {});