Add support for series name in search bar

This commit is contained in:
aditya.chandel
2025-05-27 08:37:29 -07:00
committed by Aditya Chandel
parent e0187d0ede
commit 74c2f11531
3 changed files with 36 additions and 14 deletions
@@ -61,19 +61,22 @@
<p-fluid> <p-fluid>
<div class="relative"> <div class="relative">
<i class="pi pi-search search-icon"></i>
<input <input
type="text" type="text"
pInputText pInputText
placeholder="Search title or author..." placeholder="Title, Series or Author..."
[(ngModel)]="bookTitle" [(ngModel)]="bookTitle"
(ngModelChange)="onBookTitleChange($event)"/> (ngModelChange)="onSearchTermChange($event)"
class="search-input"
/>
<p-button <p-button
*ngIf="bookTitle" *ngIf="bookTitle"
icon="pi pi-times" icon="pi pi-times"
[text]="true" [text]="true"
size="small" size="small"
[rounded]="true" [rounded]="true"
class="absolute right-2 top-1/2 transform -translate-y-1/2" class="absolute right-2 top-1/2 -translate-y-1/2"
(click)="clearSearch()"> (click)="clearSearch()">
</p-button> </p-button>
</div> </div>
@@ -85,3 +85,21 @@
font-weight: 100; font-weight: 100;
} }
} }
.search-icon {
position: absolute;
top: 50%;
left: 10px;
transform: translateY(-50%);
color: var(--text-color-secondary);
font-size: 1.0rem;
pointer-events: none;
}
.search-input {
width: 100%;
padding-left: 30px;
height: 2.5rem;
line-height: 2.5rem;
font-size: 1rem;
}
@@ -84,7 +84,7 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
bookState$: Observable<BookState> | undefined; bookState$: Observable<BookState> | undefined;
entity$: Observable<Library | Shelf | null> | undefined; entity$: Observable<Library | Shelf | null> | undefined;
entityType$: Observable<EntityType> | undefined; entityType$: Observable<EntityType> | undefined;
bookOrAuthor$ = new BehaviorSubject<string>(''); searchTerm$ = new BehaviorSubject<string>('');
entity: Library | Shelf | null = null; entity: Library | Shelf | null = null;
entityType: EntityType | undefined; entityType: EntityType | undefined;
@@ -178,7 +178,7 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
} }
this.activatedRoute.paramMap.subscribe(() => { this.activatedRoute.paramMap.subscribe(() => {
this.bookOrAuthor$.next(''); this.searchTerm$.next('');
this.bookTitle = ''; this.bookTitle = '';
this.deselectAllBooks(); this.deselectAllBooks();
this.clearFilter(); this.clearFilter();
@@ -312,15 +312,16 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
} }
private headerFilter(bookState: BookState): Observable<BookState> { private headerFilter(bookState: BookState): Observable<BookState> {
return this.bookOrAuthor$.pipe( return this.searchTerm$.pipe(
map(title => { map(term => {
if (title && title.trim() !== '') { if (term && term.trim() !== '') {
const filteredBooks = bookState.books?.filter(book => { const filteredBooks = bookState.books?.filter(book => {
const matchesTitle = book.metadata?.title?.toLowerCase().includes(title.toLowerCase()); const matchesTitle = book.metadata?.title?.toLowerCase().includes(term.toLowerCase());
const matchesSeries = book.metadata?.seriesName?.toLowerCase().includes(term.toLowerCase());
const matchesAuthor = book.metadata?.authors.some(author => const matchesAuthor = book.metadata?.authors.some(author =>
author.toLowerCase().includes(title.toLowerCase()) author.toLowerCase().includes(term.toLowerCase())
); );
return matchesTitle || matchesAuthor; return matchesTitle || matchesSeries || matchesAuthor;
}) || null; }) || null;
return {...bookState, books: filteredBooks}; return {...bookState, books: filteredBooks};
} }
@@ -426,13 +427,13 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
} }
} }
onBookTitleChange(newTitle: string): void { onSearchTermChange(term: string): void {
this.bookOrAuthor$.next(newTitle); this.searchTerm$.next(term);
} }
clearSearch(): void { clearSearch(): void {
this.bookTitle = ''; this.bookTitle = '';
this.onBookTitleChange(''); this.onSearchTermChange('');
this.resetFilters(); this.resetFilters();
} }