@@ -9,29 +9,19 @@ import {
99 createAlgoliaInsightsPlugin ,
1010} from '@algolia/autocomplete-plugin-algolia-insights' ;
1111import { createQuerySuggestionsPlugin } from '@algolia/autocomplete-plugin-query-suggestions' ;
12- import { Hit } from '@algolia/client-search' ;
1312import algoliasearch from 'algoliasearch' ;
1413import { h , Fragment } from 'preact' ;
1514import insightsClient from 'search-insights' ;
1615
1716import '@algolia/autocomplete-theme-classic' ;
1817
19- type Product = {
20- brand : string ;
21- categories : string [ ] ;
22- description : string ;
23- image : string ;
24- name : string ;
25- price : number ;
26- rating : number ;
27- __autocomplete_indexName : string ;
28- __autocomplete_queryID : string ;
29- } ;
30- type ProductHit = Hit < Product > ;
18+ import { ProductHit } from './types' ;
3119
3220const appId = 'latency' ;
3321const apiKey = '6be0576ff61c053d5f9a3225e2a90f76' ;
3422const searchClient = algoliasearch ( appId , apiKey ) ;
23+
24+ // @ts -expect-error type error in search-insights
3525insightsClient ( 'init' , { appId, apiKey } ) ;
3626
3727const algoliaInsightsPlugin = createAlgoliaInsightsPlugin ( { insightsClient } ) ;
@@ -46,10 +36,9 @@ const querySuggestionsPlugin = createQuerySuggestionsPlugin({
4636 } ,
4737} ) ;
4838
49- autocomplete ( {
39+ autocomplete < ProductHit > ( {
5040 container : '#autocomplete' ,
5141 placeholder : 'Search' ,
52- debug : true ,
5342 openOnFocus : true ,
5443 plugins : [ algoliaInsightsPlugin , querySuggestionsPlugin ] ,
5544 getSources ( { query, state } ) {
@@ -61,7 +50,7 @@ autocomplete({
6150 {
6251 sourceId : 'products' ,
6352 getItems ( ) {
64- return getAlgoliaHits < Product > ( {
53+ return getAlgoliaHits < ProductHit > ( {
6554 searchClient,
6655 queries : [
6756 {
@@ -111,7 +100,7 @@ type ProductItemProps = {
111100
112101function ProductItem ( { hit, insights, components } : ProductItemProps ) {
113102 return (
114- < div className = "aa-ItemWrapper " >
103+ < a href = { hit . url } className = "aa-ItemLink " >
115104 < div className = "aa-ItemContent" >
116105 < div className = "aa-ItemIcon aa-ItemIcon--picture aa-ItemIcon--alignTop" >
117106 < img src = { hit . image } alt = { hit . name } width = "40" height = "40" />
@@ -185,6 +174,6 @@ function ProductItem({ hit, insights, components }: ProductItemProps) {
185174 </ svg >
186175 </ button >
187176 </ div >
188- </ div >
177+ </ a >
189178 ) ;
190179}
0 commit comments