diff --git a/booklore-ui/src/app/book/components/book-browser/book-browser.component.ts b/booklore-ui/src/app/book/components/book-browser/book-browser.component.ts index 33bb82f49..ede120a83 100644 --- a/booklore-ui/src/app/book/components/book-browser/book-browser.component.ts +++ b/booklore-ui/src/app/book/components/book-browser/book-browser.component.ts @@ -635,6 +635,7 @@ export class BookBrowserComponent implements OnInit, AfterViewInit { this.selectedFilter.next(parsedFilters); this.bookFilterComponent.setFilters?.(parsedFilters); + this.bookFilterComponent.onFiltersChanged?.(); const firstFilter = filterParams.split(',')[0]; const [key, ...values] = firstFilter.split(':'); diff --git a/booklore-ui/src/app/book/components/book-browser/book-filter/book-filter.component.html b/booklore-ui/src/app/book/components/book-browser/book-filter/book-filter.component.html index 9a605cc2c..b181d48e9 100644 --- a/booklore-ui/src/app/book/components/book-browser/book-filter/book-filter.component.html +++ b/booklore-ui/src/app/book/components/book-browser/book-filter/book-filter.component.html @@ -9,9 +9,9 @@ optionValue="value" class="text-sm" allowEmpty="false" - styleClass="h-8"> + styleClass="h-8"> - + @for (filterType of filterTypes; track filterType; let i = $index) { @@ -31,10 +31,10 @@
@if (filterType === 'amazonRating') { diff --git a/booklore-ui/src/app/book/components/book-browser/book-filter/book-filter.component.ts b/booklore-ui/src/app/book/components/book-browser/book-filter/book-filter.component.ts index 015718866..b33ed2f69 100644 --- a/booklore-ui/src/app/book/components/book-browser/book-filter/book-filter.component.ts +++ b/booklore-ui/src/app/book/components/book-browser/book-filter/book-filter.component.ts @@ -7,7 +7,7 @@ import {Shelf} from '../../../model/shelf.model'; import {EntityType} from '../book-browser.component'; import {Book} from '../../../model/book.model'; import {Accordion, AccordionContent, AccordionHeader, AccordionPanel} from 'primeng/accordion'; -import { AsyncPipe, NgClass, TitleCasePipe } from '@angular/common'; +import {AsyncPipe, NgClass, TitleCasePipe} from '@angular/common'; import {Badge} from 'primeng/badge'; import {FormsModule} from '@angular/forms'; import {SelectButton} from 'primeng/selectbutton'; @@ -116,7 +116,7 @@ function getPageCountRangeFilters(pageCount?: number) { TitleCasePipe, FormsModule, SelectButton -] + ] }) export class BookFilterComponent implements OnInit { @Output() filterSelected = new EventEmitter | null>(); @@ -131,11 +131,11 @@ export class BookFilterComponent implements OnInit { filterStreams: Record[]>> = {}; filterTypes: string[] = []; filterModeOptions = [ - { label: 'AND', value: 'and' }, - { label: 'OR', value: 'or' } + {label: 'AND', value: 'and'}, + {label: 'OR', value: 'or'} ]; private _selectedFilterMode: 'and' | 'or' = 'and'; - + expandedPanels: number = 0; readonly filterLabels: Record = { author: 'Author', category: 'Category', @@ -175,6 +175,8 @@ export class BookFilterComponent implements OnInit { if (this.resetFilter$) { this.resetFilter$.subscribe(() => this.clearActiveFilter()); } + + this.setExpandedPanels(); } private getFilterStream( @@ -241,7 +243,7 @@ export class BookFilterComponent implements OnInit { if (Object.keys(this.activeFilters).length === 0) { this.filterSelected.emit(null); } else { - this.filterSelected.emit({ ...this.activeFilters }); + this.filterSelected.emit({...this.activeFilters}); } } @@ -255,12 +257,22 @@ export class BookFilterComponent implements OnInit { this.activeFilters[key] = [value]; } } - - this.filterSelected.emit({ ...this.activeFilters }); + this.filterSelected.emit({...this.activeFilters}); } clearActiveFilter() { this.activeFilters = {}; this.filterSelected.emit(null); } + + setExpandedPanels(): void { + const firstActiveIndex = this.filterTypes.findIndex( + type => this.activeFilters[type]?.length + ); + this.expandedPanels = firstActiveIndex !== -1 ? firstActiveIndex : 0; + } + + onFiltersChanged(): void { + this.setExpandedPanels(); + } }