-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathEmbeddedPublicSearch.tsx
More file actions
73 lines (69 loc) · 1.79 KB
/
EmbeddedPublicSearch.tsx
File metadata and controls
73 lines (69 loc) · 1.79 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import React, { useEffect, useState } from "react";
import { DataSearch, ReactiveBase } from "@appbaseio/reactivesearch";
import { useNavigate } from "react-router-dom";
import config from "../../app.config";
import { searchTheme } from "../../theme";
import Cookies from "universal-cookie";
export function EmbeddedPublicSearch() {
const history = useNavigate();
const cookies = new Cookies();
const [authorizationHeader, setAuthorizationHeader] = useState({
Authorization: cookies.get("Authorization"),
});
const getUpdatedCookie = () => {
const cookies = new Cookies();
setAuthorizationHeader({ Authorization: cookies.get("Authorization") });
};
// Pulling latest cookie
useEffect(() => {
const intervalId = setInterval(
getUpdatedCookie,
config.refreshTokenInterval
);
return () => clearInterval(intervalId);
}, []);
// @ts-ignore
return (
<ReactiveBase
url={config.publicSearchEndpoint}
app="all"
headers={authorizationHeader}
theme={searchTheme}
>
<DataSearch
componentId="searchbox"
autosuggest={true}
highlight={true}
queryFormat="or"
fuzziness={0}
debounce={100}
// apply react to the filter
URLParams={true}
showFilter={true}
showClear
renderNoSuggestion="No suggestions found."
dataField={[
"name",
"description",
"metadata_stringify",
"creator.keyword",
]}
fieldWeights={[3, 2, 2, 1]}
// placeholder="Search for Dataset"
innerClass={{
title: "search-title",
input: "embedded-search-input",
}}
onValueSelected={function (value, cause, _) {
if (
cause === "SUGGESTION_SELECT" ||
cause === "ENTER_PRESS" ||
cause === "SEARCH_ICON_CLICK"
) {
history(`/public_search?searchbox="${value}"`);
}
}}
/>
</ReactiveBase>
);
}