Search by title and author
This commit is contained in:
@@ -15,7 +15,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="header-right-items">
|
<div class="header-right-items">
|
||||||
<input type="text" pInputText placeholder="Search by title..." [(ngModel)]="bookTitle" (ngModelChange)="onBookTitleChange($event)"/>
|
<input type="text" pInputText placeholder="Search title or author..." [(ngModel)]="bookTitle" (ngModelChange)="onBookTitleChange($event)"/>
|
||||||
<p-select [options]="sortOptions" optionLabel="label" placeholder="Select Sorting" [(ngModel)]="selectedSort" (onChange)="updateSortOption($event.value)"></p-select>
|
<p-select [options]="sortOptions" optionLabel="label" placeholder="Select Sorting" [(ngModel)]="selectedSort" (onChange)="updateSortOption($event.value)"></p-select>
|
||||||
<div *ngFor="let option of stateOptions" class="field-checkbox">
|
<div *ngFor="let option of stateOptions" class="field-checkbox">
|
||||||
<p-radioButton [inputId]="option.key" [value]="option.value" [(ngModel)]="value" (onClick)="viewChanged()"></p-radioButton>
|
<p-radioButton [inputId]="option.key" [value]="option.value" [(ngModel)]="value" (onClick)="viewChanged()"></p-radioButton>
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ export class BookBrowserComponent implements OnInit {
|
|||||||
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;
|
||||||
bookTitle$ = new BehaviorSubject<string>('');
|
bookOrAuthor$ = new BehaviorSubject<string>('');
|
||||||
|
|
||||||
entity: Library | Shelf | null = null;
|
entity: Library | Shelf | null = null;
|
||||||
entityType: EntityType | undefined;
|
entityType: EntityType | undefined;
|
||||||
@@ -124,7 +124,7 @@ export class BookBrowserComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.activatedRoute.paramMap.subscribe(() => {
|
this.activatedRoute.paramMap.subscribe(() => {
|
||||||
this.bookTitle$.next('');
|
this.bookOrAuthor$.next('');
|
||||||
this.bookTitle = '';
|
this.bookTitle = '';
|
||||||
this.deselectAllBooks();
|
this.deselectAllBooks();
|
||||||
});
|
});
|
||||||
@@ -179,7 +179,7 @@ export class BookBrowserComponent implements OnInit {
|
|||||||
private fetchAllBooks(): Observable<BookState> {
|
private fetchAllBooks(): Observable<BookState> {
|
||||||
return this.bookService.bookState$.pipe(
|
return this.bookService.bookState$.pipe(
|
||||||
map(bookState => this.processBookState(bookState)),
|
map(bookState => this.processBookState(bookState)),
|
||||||
switchMap(bookState => this.filterBooksByTitle(bookState))
|
switchMap(bookState => this.filterBooks(bookState))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -193,7 +193,7 @@ export class BookBrowserComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
return bookState;
|
return bookState;
|
||||||
}),
|
}),
|
||||||
switchMap(bookState => this.filterBooksByTitle(bookState))
|
switchMap(bookState => this.filterBooks(bookState))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -205,13 +205,17 @@ export class BookBrowserComponent implements OnInit {
|
|||||||
return bookState;
|
return bookState;
|
||||||
}
|
}
|
||||||
|
|
||||||
private filterBooksByTitle(bookState: BookState): Observable<BookState> {
|
private filterBooks(bookState: BookState): Observable<BookState> {
|
||||||
return this.bookTitle$.pipe(
|
return this.bookOrAuthor$.pipe(
|
||||||
map(title => {
|
map(title => {
|
||||||
if (title && title.trim() !== '') {
|
if (title && title.trim() !== '') {
|
||||||
const filteredBooks = bookState.books?.filter(book =>
|
const filteredBooks = bookState.books?.filter(book => {
|
||||||
book.metadata?.title?.toLowerCase().includes(title.toLowerCase())
|
const matchesTitle = book.metadata?.title?.toLowerCase().includes(title.toLowerCase());
|
||||||
) || null;
|
const matchesAuthor = book.metadata?.authors.some(author =>
|
||||||
|
author.name.toLowerCase().includes(title.toLowerCase())
|
||||||
|
);
|
||||||
|
return matchesTitle || matchesAuthor;
|
||||||
|
}) || null;
|
||||||
return {...bookState, books: filteredBooks};
|
return {...bookState, books: filteredBooks};
|
||||||
}
|
}
|
||||||
return bookState;
|
return bookState;
|
||||||
@@ -309,7 +313,7 @@ export class BookBrowserComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onBookTitleChange(newTitle: string): void {
|
onBookTitleChange(newTitle: string): void {
|
||||||
this.bookTitle$.next(newTitle);
|
this.bookOrAuthor$.next(newTitle);
|
||||||
}
|
}
|
||||||
|
|
||||||
openShelfAssigner() {
|
openShelfAssigner() {
|
||||||
|
|||||||
@@ -28,7 +28,7 @@
|
|||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
padding: 0 6px;
|
padding-left: 6px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.book-cover {
|
.book-cover {
|
||||||
@@ -79,3 +79,7 @@
|
|||||||
.book-card.selected .select-checkbox {
|
.book-card.selected .select-checkbox {
|
||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
::ng-deep .p-button-icon-only {
|
||||||
|
--p-button-icon-only-width: 20px !important;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user