Skip to content

Commit 47d876f

Browse files
chore: fix merge
1 parent eb807cc commit 47d876f

File tree

4 files changed

+57
-113
lines changed

4 files changed

+57
-113
lines changed

examples/js/app.ts

Lines changed: 0 additions & 94 deletions
This file was deleted.

examples/js/app.tsx

Lines changed: 54 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,25 @@
22
import {
33
autocomplete,
44
getAlgoliaHits,
5-
highlightHit,
5+
snippetHit,
66
} from '@algolia/autocomplete-js';
77
import { createAlgoliaInsightsPlugin } from '@algolia/autocomplete-plugin-algolia-insights';
88
import { createQuerySuggestionsPlugin } from '@algolia/autocomplete-plugin-query-suggestions';
99
import { createLocalStorageRecentSearchesPlugin } from '@algolia/autocomplete-plugin-recent-searches';
1010
import { Hit } from '@algolia/client-search';
1111
import algoliasearch from 'algoliasearch';
12-
import { h } from 'preact';
12+
import { h, Fragment } from 'preact';
1313
import insightsClient from 'search-insights';
1414

1515
import '@algolia/autocomplete-theme-classic';
1616

17-
type Product = { name: string; image: string };
17+
import { shortcutsPlugin } from './shortcutsPlugin';
18+
19+
type Product = {
20+
name: string;
21+
image: string;
22+
description: string;
23+
};
1824
type ProductHit = Hit<Product>;
1925

2026
const appId = 'latency';
@@ -44,6 +50,7 @@ autocomplete({
4450
debug: true,
4551
openOnFocus: true,
4652
plugins: [
53+
shortcutsPlugin,
4754
algoliaInsightsPlugin,
4855
recentSearchesPlugin,
4956
querySuggestionsPlugin,
@@ -59,16 +66,38 @@ autocomplete({
5966
getItems() {
6067
return getAlgoliaHits<Product>({
6168
searchClient,
62-
queries: [{ indexName: 'instant_search', query }],
69+
queries: [
70+
{
71+
indexName: 'instant_search',
72+
query,
73+
params: {
74+
clickAnalytics: true,
75+
attributesToSnippet: ['name:10', 'description:35'],
76+
snippetEllipsisText: '…',
77+
},
78+
},
79+
],
6380
});
6481
},
6582
templates: {
83+
header() {
84+
return (
85+
<Fragment>
86+
<span className="aa-SourceHeaderTitle">Products</span>
87+
<div className="aa-SourceHeaderLine"></div>
88+
</Fragment>
89+
);
90+
},
6691
item({ item }) {
6792
return <ProductItem hit={item} />;
6893
},
6994
empty() {
7095
return (
71-
<div className="aa-ItemContent">No results for this query.</div>
96+
<div className="aa-ItemContent">
97+
<div className="aa-ItemContentTitle">
98+
No products for this query.
99+
</div>
100+
</div>
72101
);
73102
},
74103
},
@@ -83,14 +112,27 @@ type ProductItemProps = {
83112

84113
function ProductItem({ hit }: ProductItemProps) {
85114
return (
86-
<div className="aa-ItemContent">
87-
<div className="aa-ItemSourceIcon">
88-
<img src={hit.image} alt={hit.name} width="20" height="20" />
115+
<Fragment>
116+
<div className="aa-ItemIcon">
117+
<img src={hit.image} alt={hit.name} width="40" height="40" />
89118
</div>
90-
91-
<div className="aa-ItemTitle">
92-
{highlightHit<ProductHit>({ hit, attribute: 'name' })}
119+
<div className="aa-ItemContent">
120+
<div className="aa-ItemContentTitle">
121+
{snippetHit<ProductHit>({ hit, attribute: 'name' })}
122+
</div>
123+
<div className="aa-ItemContentDescription">
124+
{snippetHit<ProductHit>({ hit, attribute: 'description' })}
125+
</div>
93126
</div>
94-
</div>
127+
<button
128+
className="aa-ItemActionButton aa-TouchOnly aa-ActiveOnly"
129+
type="button"
130+
title="Select"
131+
>
132+
<svg fill="currentColor" viewBox="0 0 24 24" width="20" height="20">
133+
<path d="M18.984 6.984h2.016v6h-15.188l3.609 3.609-1.406 1.406-6-6 6-6 1.406 1.406-3.609 3.609h13.172v-4.031z"></path>
134+
</svg>
135+
</button>
136+
</Fragment>
95137
);
96138
}

packages/autocomplete-js/src/__tests__/autocomplete.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ describe('autocomplete-js', () => {
9393
stroke-dasharray="164.93361431346415 56.97787143782138"
9494
stroke-width="6"
9595
>
96-
97-
96+
97+
9898
<animatetransform
9999
attributeName="transform"
100100
dur="1s"
@@ -103,7 +103,7 @@ describe('autocomplete-js', () => {
103103
type="rotate"
104104
values="0 50 50;90 50 50;180 50 50;360 50 50"
105105
/>
106-
106+
107107
108108
</circle>
109109
</svg>

packages/autocomplete-js/src/autocomplete.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,6 @@ export function autocomplete<TItem extends BaseItem>(
144144
state: lastStateRef.current,
145145
};
146146

147-
hasEmptySourceTemplateRef.current = renderProps.state.collections.some(
148-
(collection) => collection.source.templates.empty
149-
);
150-
151147
const render =
152148
(!getItemsCount(state) &&
153149
!hasEmptySourceTemplateRef.current &&

0 commit comments

Comments
 (0)