-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
executable file
·62 lines (55 loc) · 1.45 KB
/
App.js
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
import React, { Component } from "react";
import { Body, Header } from "./components";
import {
SearchProvider,
SearchDriver,
AppSearchAPIConnector
} from "./search-lib";
import {
buildFacetConfigFromConfig,
buildSearchOptionsFromConfig,
getConfig,
getFacetFields,
getSortFields
} from "./config/config-helper";
function createDriver() {
const { hostIdentifier, searchKey, endpointBase, engineName } = getConfig();
return new SearchDriver({
apiConnector: new AppSearchAPIConnector({
hostIdentifier,
searchKey,
endpointBase,
engineName
}),
facetConfig: buildFacetConfigFromConfig(),
searchOptions: buildSearchOptionsFromConfig()
});
}
class App extends Component {
render() {
const config = getConfig();
if (!config.engineName) {
return (
<div>
No config found. Be sure to provide configuration by either including
a src/config/engine.json file, or including window.appConfig.
</div>
);
}
return (
<SearchProvider driver={createDriver()}>
{({ searchTerm, results }) => (
<div
className={`reference-ui${
searchTerm || results.length > 0 ? " active-search" : ""
}`}
>
<Header />
<Body hasSidebar={getFacetFields().length > 0 || getSortFields().length > 0 ? true : false} />
</div>
)}
</SearchProvider>
);
}
}
export default App;