-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.js
89 lines (84 loc) · 2.19 KB
/
main.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import './style.css';
import './src/styles/heading.css';
import './src/styles/searchAndFilter.css';
import './src/styles/infiniteHits.css';
import TypesenseInstantSearchAdapter from 'typesense-instantsearch-adapter';
import instantsearch from 'instantsearch.js';
import {
configure,
infiniteHits,
refinementList,
} from 'instantsearch.js/es/widgets';
import RenderChord from './src/reactChords';
const adapter = new TypesenseInstantSearchAdapter({
server: {
apiKey: import.meta.env.VITE_TYPESENSE_SEARCH_ONLY_API_KEY || 'xyz',
nodes: [
{
host: import.meta.env.VITE_TYPESENSE_HOST || 'localhost',
port: parseInt(import.meta.env.VITE_TYPESENSE_PORT || '8108'),
protocol: import.meta.env.VITE_TYPESENSE_PROTOCOL || 'http',
},
],
},
additionalSearchParameters: {
query_by: 'key,suffix',
num_typos: 0,
},
});
const search = instantsearch({
indexName: 'guitar-chords',
searchClient: adapter.searchClient,
future: {
preserveSharedStateOnUnmount: true,
},
});
search.addWidgets([
configure({
hitsPerPage: 12,
enablePersonalization: true,
}),
infiniteHits({
container: '#infiniteHits',
templates: {
item(hit, { html, components }) {
const chord = `${RenderChord(hit.positions[0])}`;
const positionCount = hit.positions.length;
return html`
<h2 class="chord_name">
${components.Highlight({ attribute: 'key', hit })}${hit.suffix}
</h2>
${html([chord])}
<span class="posCount"
>${positionCount > 1
? positionCount + ' positions'
: '1 position'}</span
>
`;
},
},
}),
// Refinement lists
refinementList({
container: '#key_refinementList',
attribute: 'key',
sortBy: ['name'],
limit: 7,
showMore: true,
showMoreLimit: 100,
}),
refinementList({
container: '#suffix_refinementList',
attribute: 'suffix',
limit: 8,
showMore: true,
showMoreLimit: 100,
searchable: true,
searchablePlaceholder: 'Search suffixes...',
}),
refinementList({
container: '#capo_refinementList',
attribute: 'positions.capo',
}),
]);
search.start();