Add support for series name in search bar
This commit is contained in:
committed by
Aditya Chandel
parent
e0187d0ede
commit
74c2f11531
@@ -61,19 +61,22 @@
|
||||
|
||||
<p-fluid>
|
||||
<div class="relative">
|
||||
<i class="pi pi-search search-icon"></i>
|
||||
<input
|
||||
type="text"
|
||||
pInputText
|
||||
placeholder="Search title or author..."
|
||||
placeholder="Title, Series or Author..."
|
||||
[(ngModel)]="bookTitle"
|
||||
(ngModelChange)="onBookTitleChange($event)"/>
|
||||
(ngModelChange)="onSearchTermChange($event)"
|
||||
class="search-input"
|
||||
/>
|
||||
<p-button
|
||||
*ngIf="bookTitle"
|
||||
icon="pi pi-times"
|
||||
[text]="true"
|
||||
size="small"
|
||||
[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()">
|
||||
</p-button>
|
||||
</div>
|
||||
|
||||
@@ -85,3 +85,21 @@
|
||||
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;
|
||||
entity$: Observable<Library | Shelf | null> | undefined;
|
||||
entityType$: Observable<EntityType> | undefined;
|
||||
bookOrAuthor$ = new BehaviorSubject<string>('');
|
||||
searchTerm$ = new BehaviorSubject<string>('');
|
||||
|
||||
entity: Library | Shelf | null = null;
|
||||
entityType: EntityType | undefined;
|
||||
@@ -178,7 +178,7 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
|
||||
}
|
||||
|
||||
this.activatedRoute.paramMap.subscribe(() => {
|
||||
this.bookOrAuthor$.next('');
|
||||
this.searchTerm$.next('');
|
||||
this.bookTitle = '';
|
||||
this.deselectAllBooks();
|
||||
this.clearFilter();
|
||||
@@ -312,15 +312,16 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
|
||||
}
|
||||
|
||||
private headerFilter(bookState: BookState): Observable<BookState> {
|
||||
return this.bookOrAuthor$.pipe(
|
||||
map(title => {
|
||||
if (title && title.trim() !== '') {
|
||||
return this.searchTerm$.pipe(
|
||||
map(term => {
|
||||
if (term && term.trim() !== '') {
|
||||
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 =>
|
||||
author.toLowerCase().includes(title.toLowerCase())
|
||||
author.toLowerCase().includes(term.toLowerCase())
|
||||
);
|
||||
return matchesTitle || matchesAuthor;
|
||||
return matchesTitle || matchesSeries || matchesAuthor;
|
||||
}) || null;
|
||||
return {...bookState, books: filteredBooks};
|
||||
}
|
||||
@@ -426,13 +427,13 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
|
||||
}
|
||||
}
|
||||
|
||||
onBookTitleChange(newTitle: string): void {
|
||||
this.bookOrAuthor$.next(newTitle);
|
||||
onSearchTermChange(term: string): void {
|
||||
this.searchTerm$.next(term);
|
||||
}
|
||||
|
||||
clearSearch(): void {
|
||||
this.bookTitle = '';
|
||||
this.onBookTitleChange('');
|
||||
this.onSearchTermChange('');
|
||||
this.resetFilters();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user