Skip to content

Commit e320898

Browse files
committed
fix(angular/query-suggestions): fix mobile layout, use ais-hits for results and add types
1 parent faaeab2 commit e320898

File tree

3 files changed

+30
-13
lines changed

3 files changed

+30
-13
lines changed

Angular InstantSearch/query-suggestions/src/app/app.component.css

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,10 @@
4949
margin-bottom: 2rem;
5050
}
5151

52-
.ais-Hits-list {
53-
display: grid;
54-
grid-template-columns: repeat(4, 1fr);
55-
gap: 20px;
52+
@media (min-width: 900px) {
53+
.ais-Hits-list {
54+
display: grid;
55+
grid-template-columns: repeat(4, 1fr);
56+
gap: 20px;
57+
}
5658
}

Angular InstantSearch/query-suggestions/src/app/app.component.html

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,15 @@ <h1 class="header-title">
2222
<ais-configure [searchParameters]="searchParameters"></ais-configure>
2323
<div class="search-panel">
2424
<div class="search-panel__results">
25-
<ais-hits>
26-
<ng-template let-hits="hits" let-results="results">
27-
<div *ngIf="hits.length === 0">
28-
No results found matching <strong>{{ results?.query }}</strong>.
25+
<ais-stats>
26+
<ng-template let-state="state">
27+
<div *ngIf="state.nbHits === 0">
28+
No hits for <strong>{{ state.query }}</strong>.
2929
</div>
30-
30+
</ng-template>
31+
</ais-stats>
32+
<ais-hits>
33+
<ng-template let-hits="hits">
3134
<ol class="ais-Hits-list">
3235
<li class="ais-Hits-item" *ngFor="let hit of hits">
3336
<ais-highlight attribute="name" [hit]="hit"></ais-highlight>

Angular InstantSearch/query-suggestions/src/app/autocomplete.component.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { Hit } from '@algolia/client-search';
12
import {
23
Component,
34
EventEmitter,
@@ -21,6 +22,16 @@ export type QuerySuggestion = {
2122
category: string | null;
2223
};
2324

25+
type QuerySuggestionHit = Hit<{
26+
instant_search?: {
27+
facets?: {
28+
exact_matches?: {
29+
categories?: ReadonlyArray<{ value: string; count: number }>;
30+
};
31+
};
32+
};
33+
}>;
34+
2435
@Component({
2536
selector: 'app-autocomplete',
2637
template: `
@@ -81,12 +92,13 @@ export class AutocompleteComponent extends TypedBaseWidget<
8192
super('AutocompleteComponent');
8293
}
8394

84-
hasCategory(hit: any) {
85-
return !!hit?.instant_search?.facets?.exact_matches?.categories?.length;
95+
hasCategory(hit: QuerySuggestionHit) {
96+
return !!hit.instant_search?.facets?.exact_matches?.categories?.length;
8697
}
8798

88-
getCategory(hit: any) {
89-
const [category] = hit.instant_search.facets.exact_matches.categories;
99+
getCategory(hit: QuerySuggestionHit) {
100+
const [category] =
101+
hit.instant_search?.facets?.exact_matches?.categories || [];
90102
return category.value;
91103
}
92104

0 commit comments

Comments
 (0)