Auto-expand first active filter panel or default to first
This commit is contained in:
committed by
Aditya Chandel
parent
7053cfa963
commit
68dce9bd23
@@ -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(':');
|
||||
|
||||
+6
-6
@@ -9,9 +9,9 @@
|
||||
optionValue="value"
|
||||
class="text-sm"
|
||||
allowEmpty="false"
|
||||
styleClass="h-8"></p-selectButton>
|
||||
styleClass="h-8"></p-selectButton>
|
||||
</div>
|
||||
<p-accordion [value]="0">
|
||||
<p-accordion [value]="expandedPanels">
|
||||
@for (filterType of filterTypes; track filterType; let i = $index) {
|
||||
<p-accordion-panel [value]="i">
|
||||
<p-accordion-header>
|
||||
@@ -31,10 +31,10 @@
|
||||
<div>
|
||||
<div
|
||||
class="cursor-pointer transition-colors duration-200 ease-in-out pb-1 flex items-center gap-2"
|
||||
[ngClass]="{
|
||||
'text-[var(--primary-color)]':
|
||||
activeFilters[filterType]?.includes(filter.value?.id || filter.value)
|
||||
}"
|
||||
[ngClass]="{
|
||||
'text-[var(--primary-color)]':
|
||||
activeFilters[filterType]?.includes(filter.value?.id || filter.value)
|
||||
}"
|
||||
(click)="handleFilterClick(filterType, filter.value?.id || filter.value)">
|
||||
<p-badge [value]="filter.bookCount"></p-badge>
|
||||
@if (filterType === 'amazonRating') {
|
||||
|
||||
+20
-8
@@ -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<Record<string, any> | null>();
|
||||
@@ -131,11 +131,11 @@ export class BookFilterComponent implements OnInit {
|
||||
filterStreams: Record<string, Observable<Filter<any>[]>> = {};
|
||||
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<string, string> = {
|
||||
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<T>(
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user