Improve searching

This commit is contained in:
aditya.chandel
2024-12-13 16:05:04 -07:00
parent 1e9249b257
commit 033fc95373
5 changed files with 26 additions and 8 deletions
@@ -12,10 +12,19 @@
<button *ngIf="searchQuery" pButton icon="pi pi-times" (click)="clearSearch()" class="clear-btn" type="button" aria-label="Clear Search"></button>
</span>
<div class="search-dropdown layout-menu" [class.show]="books.length > 0">
<div class="search-dropdown-item" *ngFor="let book of books" (click)="onBookClick(book)">
<img [src]="getBookCoverUrl(book.id)" alt="Book Cover" class="search-book-cover" />
<span class="search-book-name">{{ book.title }}</span>
</div>
<div class="search-dropdown layout-menu" [class.show]="(books.length > 0 || (searchQuery?.length ?? 0) > 0)">
<ng-container *ngIf="books.length > 0; else noResults">
<div class="search-dropdown-item" *ngFor="let book of books" (click)="onBookClick(book)">
<img [src]="getBookCoverUrl(book.id)" alt="Book Cover" class="search-book-cover" />
<span class="search-book-name">{{ book.title }}</span>
</div>
</ng-container>
<!-- No results message -->
<ng-template #noResults>
<div class="search-dropdown-item">
<span>No results found</span>
</div>
</ng-template>
</div>
</div>
@@ -75,3 +75,12 @@
cursor: pointer;
font-size: 12px;
}
.search-dropdown-item.no-results {
font-size: 14px;
color: var(--text-color-secondary);
padding: 10px;
text-align: center;
font-style: italic;
}
@@ -34,7 +34,7 @@ export class SearchComponent implements OnInit, OnDestroy {
initializeSearch(): void {
this.#subscription = this.#searchSubject.pipe(
debounceTime(500),
debounceTime(350),
distinctUntilChanged(),
switchMap((query) => this.bookService.searchBooks(query).pipe(
catchError((error) => {