Improve top search to include authors
This commit is contained in:
@@ -13,11 +13,21 @@
|
||||
<p-button *ngIf="searchQuery" icon="pi pi-times" (click)="clearSearch()" [text]="true" [rounded]="true" class="clear-btn" aria-label="Clear Search"></p-button>
|
||||
</div>
|
||||
|
||||
<div class="search-dropdown layout-menu" [class.show]="(books.length > 0)">
|
||||
<div class="search-dropdown layout-menu pt-4" [class.show]="(books.length > 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.metadata?.title }}</span>
|
||||
<div class="search-dropdown-item flex flex-col" *ngFor="let book of books" (click)="onBookClick(book)">
|
||||
<div class="flex flex-row w-full px-2">
|
||||
<img [src]="getBookCoverUrl(book.id)" alt="Book Cover" class="search-book-cover"/>
|
||||
<div class="search-book-details">
|
||||
<div class="flex items-center">
|
||||
<p class="search-book-name text-lg font-medium truncate">{{ book.metadata?.title | slice:0:70 }}</p>
|
||||
</div>
|
||||
<div *ngIf="book.metadata?.authors?.length ?? 0 > 0" class="search-book-authors">
|
||||
<p class="italic">by: {{ getAuthorNames(book.metadata?.authors) }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<p-divider></p-divider>
|
||||
</div>
|
||||
</ng-container>
|
||||
|
||||
|
||||
@@ -57,7 +57,6 @@
|
||||
.search-dropdown-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 10px;
|
||||
cursor: pointer;
|
||||
transition: background-color 0.3s;
|
||||
|
||||
@@ -67,18 +66,11 @@
|
||||
}
|
||||
|
||||
.search-book-cover {
|
||||
width: 25px;
|
||||
height: 37px;
|
||||
width: 35px;
|
||||
height: 47px;
|
||||
object-fit: cover;
|
||||
max-width: 100px;
|
||||
max-height: 150px;
|
||||
border-radius: 4px;
|
||||
margin-right: 10px;
|
||||
}
|
||||
|
||||
.search-book-name {
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: var(--text-color);
|
||||
flex-grow: 1;
|
||||
}
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
import {Component, inject, OnDestroy, OnInit} from '@angular/core';
|
||||
import {Subject, Subscription} from 'rxjs';
|
||||
import {catchError, debounceTime, distinctUntilChanged, switchMap} from 'rxjs/operators';
|
||||
import {Book} from '../../model/book.model';
|
||||
import {Author, Book} from '../../model/book.model';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {InputTextModule} from 'primeng/inputtext';
|
||||
import {BookService} from '../../service/book.service';
|
||||
import {Button} from 'primeng/button';
|
||||
import {NgForOf, NgIf} from '@angular/common';
|
||||
import {NgForOf, NgIf, SlicePipe} from '@angular/common';
|
||||
import {MetadataDialogService} from '../../../metadata/service/metadata-dialog.service';
|
||||
import {Divider} from 'primeng/divider';
|
||||
|
||||
@Component({
|
||||
selector: 'app-book-searcher',
|
||||
@@ -17,7 +18,9 @@ import {MetadataDialogService} from '../../../metadata/service/metadata-dialog.s
|
||||
InputTextModule,
|
||||
Button,
|
||||
NgIf,
|
||||
NgForOf
|
||||
NgForOf,
|
||||
SlicePipe,
|
||||
Divider
|
||||
],
|
||||
styleUrls: ['./book-searcher.component.scss'],
|
||||
standalone: true
|
||||
@@ -52,6 +55,14 @@ export class BookSearcherComponent implements OnInit, OnDestroy {
|
||||
});
|
||||
}
|
||||
|
||||
getLibraryName(libraryId: number): string {
|
||||
return `${libraryId}`;
|
||||
}
|
||||
|
||||
getAuthorNames(authors: Author[] | undefined): string {
|
||||
return authors?.map(author => author.name).join(', ') || 'Unknown Author';
|
||||
}
|
||||
|
||||
onSearchInputChange(): void {
|
||||
this.#searchSubject.next(this.searchQuery.trim());
|
||||
}
|
||||
|
||||
@@ -139,7 +139,8 @@ export class BookService {
|
||||
return this.bookState$.pipe(
|
||||
map(state =>
|
||||
(state.books || []).filter(book =>
|
||||
book.metadata?.title?.toLowerCase().includes(query.toLowerCase())
|
||||
(book.metadata?.title?.toLowerCase().includes(query.toLowerCase()) ||
|
||||
book.metadata?.authors.some(author => author.name.toLowerCase().includes(query.toLowerCase())))
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user