Fix filter button not clearing the highlighted text
This commit is contained in:
@@ -155,6 +155,6 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<app-book-filter [entity$]="entity$" [entityType$]="entityType$"></app-book-filter>
|
<app-book-filter [entity$]="entity$" [entityType$]="entityType$" [resetFilter$]="resetFilterSubject"></app-book-filter>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import {MenuItem, MessageService, PrimeTemplate} from 'primeng/api';
|
|||||||
import {LibraryService} from '../../service/library.service';
|
import {LibraryService} from '../../service/library.service';
|
||||||
import {BookService} from '../../service/book.service';
|
import {BookService} from '../../service/book.service';
|
||||||
import {map, switchMap} from 'rxjs/operators';
|
import {map, switchMap} from 'rxjs/operators';
|
||||||
import {BehaviorSubject, combineLatest, Observable, of} from 'rxjs';
|
import {BehaviorSubject, combineLatest, Observable, of, Subject} from 'rxjs';
|
||||||
import {ShelfService} from '../../service/shelf.service';
|
import {ShelfService} from '../../service/shelf.service';
|
||||||
import {ShelfAssignerComponent} from '../shelf-assigner/shelf-assigner.component';
|
import {ShelfAssignerComponent} from '../shelf-assigner/shelf-assigner.component';
|
||||||
import {DialogService, DynamicDialogRef} from 'primeng/dynamicdialog';
|
import {DialogService, DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||||
@@ -83,6 +83,7 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
|
|||||||
|
|
||||||
selectedFilter = new BehaviorSubject<{ type: string; value: any } | null>(null);
|
selectedFilter = new BehaviorSubject<{ type: string; value: any } | null>(null);
|
||||||
|
|
||||||
|
protected userService = inject(UserService);
|
||||||
private activatedRoute = inject(ActivatedRoute);
|
private activatedRoute = inject(ActivatedRoute);
|
||||||
private messageService = inject(MessageService);
|
private messageService = inject(MessageService);
|
||||||
private libraryService = inject(LibraryService);
|
private libraryService = inject(LibraryService);
|
||||||
@@ -90,9 +91,11 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
|
|||||||
private shelfService = inject(ShelfService);
|
private shelfService = inject(ShelfService);
|
||||||
private dialogService = inject(DialogService);
|
private dialogService = inject(DialogService);
|
||||||
private sortService = inject(SortService);
|
private sortService = inject(SortService);
|
||||||
protected userService = inject(UserService);
|
|
||||||
private libraryShelfMenuService = inject(LibraryShelfMenuService);
|
private libraryShelfMenuService = inject(LibraryShelfMenuService);
|
||||||
|
|
||||||
|
protected resetFilterSubject = new Subject<void>();
|
||||||
|
|
||||||
|
|
||||||
sortOptions: any[] = [
|
sortOptions: any[] = [
|
||||||
{label: 'Title', icon: '', field: 'title', command: () => this.sortBooks('title')},
|
{label: 'Title', icon: '', field: 'title', command: () => this.sortBooks('title')},
|
||||||
{label: 'Author', icon: '', field: 'author', command: () => this.sortBooks('author')},
|
{label: 'Author', icon: '', field: 'author', command: () => this.sortBooks('author')},
|
||||||
@@ -390,6 +393,11 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
|
|||||||
clearSearch(): void {
|
clearSearch(): void {
|
||||||
this.bookTitle = '';
|
this.bookTitle = '';
|
||||||
this.onBookTitleChange('');
|
this.onBookTitleChange('');
|
||||||
|
this.resetFilters();
|
||||||
|
}
|
||||||
|
|
||||||
|
resetFilters() {
|
||||||
|
this.resetFilterSubject.next();
|
||||||
}
|
}
|
||||||
|
|
||||||
openShelfAssigner() {
|
openShelfAssigner() {
|
||||||
|
|||||||
+10
-2
@@ -1,5 +1,5 @@
|
|||||||
import {Component, EventEmitter, inject, Input, OnInit, Output} from '@angular/core';
|
import {Component, EventEmitter, inject, Input, OnInit, Output} from '@angular/core';
|
||||||
import {combineLatest, Observable, of} from 'rxjs';
|
import {combineLatest, Observable, of, Subject} from 'rxjs';
|
||||||
import {map} from 'rxjs/operators';
|
import {map} from 'rxjs/operators';
|
||||||
import {BookService} from '../../../service/book.service';
|
import {BookService} from '../../../service/book.service';
|
||||||
import {Library} from '../../../model/library.model';
|
import {Library} from '../../../model/library.model';
|
||||||
@@ -37,6 +37,7 @@ export class BookFilterComponent implements OnInit {
|
|||||||
@Input() showFilters: boolean = true;
|
@Input() showFilters: boolean = true;
|
||||||
@Input() entity$!: Observable<Library | Shelf | null> | undefined;
|
@Input() entity$!: Observable<Library | Shelf | null> | undefined;
|
||||||
@Input() entityType$!: Observable<EntityType> | undefined;
|
@Input() entityType$!: Observable<EntityType> | undefined;
|
||||||
|
@Input() resetFilter$!: Subject<void>;
|
||||||
|
|
||||||
activeFilter: { type: string; value: any | null } = {type: '', value: null};
|
activeFilter: { type: string; value: any | null } = {type: '', value: null};
|
||||||
filterStreams: Record<string, Observable<Filter<any>[]>> = {};
|
filterStreams: Record<string, Observable<Filter<any>[]>> = {};
|
||||||
@@ -44,7 +45,6 @@ export class BookFilterComponent implements OnInit {
|
|||||||
|
|
||||||
bookService = inject(BookService);
|
bookService = inject(BookService);
|
||||||
|
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
if (this.entity$ && this.entityType$) {
|
if (this.entity$ && this.entityType$) {
|
||||||
this.filterStreams = {
|
this.filterStreams = {
|
||||||
@@ -56,6 +56,9 @@ export class BookFilterComponent implements OnInit {
|
|||||||
};
|
};
|
||||||
this.filterTypes = Object.keys(this.filterStreams);
|
this.filterTypes = Object.keys(this.filterStreams);
|
||||||
}
|
}
|
||||||
|
if (this.resetFilter$) {
|
||||||
|
this.resetFilter$.subscribe(() => this.clearActiveFilter());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private getFilterStream<T>(extractor: (book: Book) => T[] | undefined, idKey: keyof T, nameKey: keyof T): Observable<Filter<T[keyof T]>[]> {
|
private getFilterStream<T>(extractor: (book: Book) => T[] | undefined, idKey: keyof T, nameKey: keyof T): Observable<Filter<T[keyof T]>[]> {
|
||||||
@@ -97,4 +100,9 @@ export class BookFilterComponent implements OnInit {
|
|||||||
this.filterSelected.emit({type: filterType, value});
|
this.filterSelected.emit({type: filterType, value});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clearActiveFilter() {
|
||||||
|
this.activeFilter = { type: '', value: null };
|
||||||
|
this.filterSelected.emit(null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user