/
index.astro
122 lines (115 loc) · 2.84 KB
/
index.astro
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
---
import Layout from '../layouts/Layout.astro';
import Heading from '../components/Heading.astro';
import '../styles/infiniteHits.css';
import '../styles/searchAndFilter.css';
---
<script>
import { typesenseInstantsearchAdapter } from '../utils/typesense';
import instantsearch from 'instantsearch.js';
import {
configure,
infiniteHits,
refinementList,
} from 'instantsearch.js/es/widgets';
import RenderChord from '../utils/reactChords';
const search = instantsearch({
indexName: 'guitar-chords',
searchClient: typesenseInstantsearchAdapter.searchClient,
future: {
preserveSharedStateOnUnmount: true,
},
});
search.addWidgets([
configure({
hitsPerPage: 12,
enablePersonalization: true,
}),
infiniteHits({
container: '#infiniteHits',
templates: {
item(hit, { html, components }) {
// @ts-ignore
const chord = html([RenderChord(hit.positions[0])]);
const positionCount = hit.positions.length;
return html`
<h2 class="chord_name">
${components.Highlight({ attribute: 'key', hit })}${hit.suffix}
</h2>
${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();
</script>
<Layout title='Guitar chords search Astro | Typesense'>
<main>
<Heading />
<div id='flex_row'>
<aside class='SearchAndFilter'>
<h3>Key</h3>
<div id='key_refinementList'></div>
<h3>Suffix</h3>
<div id='suffix_refinementList'></div>
<h3>Capo</h3>
<div id='capo_refinementList'></div>
</aside>
<div id='infiniteHits'></div>
</div>
</main>
</Layout>
<style>
main {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
padding: calc(3rem + 3.5vmax) 1rem;
min-height: 100vh;
min-height: 100dvh;
gap: 5rem;
width: 100%;
max-width: min(1200px, 100vw);
margin: auto;
position: relative;
}
#flex_row {
display: flex;
width: 100%;
align-items: flex-start;
gap: 2rem;
min-height: 474px;
}
#infiniteHits {
flex: 1;
}
</style>