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.selectedFilter.next(parsedFilters);
|
||||||
this.bookFilterComponent.setFilters?.(parsedFilters);
|
this.bookFilterComponent.setFilters?.(parsedFilters);
|
||||||
|
this.bookFilterComponent.onFiltersChanged?.();
|
||||||
|
|
||||||
const firstFilter = filterParams.split(',')[0];
|
const firstFilter = filterParams.split(',')[0];
|
||||||
const [key, ...values] = firstFilter.split(':');
|
const [key, ...values] = firstFilter.split(':');
|
||||||
|
|||||||
+6
-6
@@ -9,9 +9,9 @@
|
|||||||
optionValue="value"
|
optionValue="value"
|
||||||
class="text-sm"
|
class="text-sm"
|
||||||
allowEmpty="false"
|
allowEmpty="false"
|
||||||
styleClass="h-8"></p-selectButton>
|
styleClass="h-8"></p-selectButton>
|
||||||
</div>
|
</div>
|
||||||
<p-accordion [value]="0">
|
<p-accordion [value]="expandedPanels">
|
||||||
@for (filterType of filterTypes; track filterType; let i = $index) {
|
@for (filterType of filterTypes; track filterType; let i = $index) {
|
||||||
<p-accordion-panel [value]="i">
|
<p-accordion-panel [value]="i">
|
||||||
<p-accordion-header>
|
<p-accordion-header>
|
||||||
@@ -31,10 +31,10 @@
|
|||||||
<div>
|
<div>
|
||||||
<div
|
<div
|
||||||
class="cursor-pointer transition-colors duration-200 ease-in-out pb-1 flex items-center gap-2"
|
class="cursor-pointer transition-colors duration-200 ease-in-out pb-1 flex items-center gap-2"
|
||||||
[ngClass]="{
|
[ngClass]="{
|
||||||
'text-[var(--primary-color)]':
|
'text-[var(--primary-color)]':
|
||||||
activeFilters[filterType]?.includes(filter.value?.id || filter.value)
|
activeFilters[filterType]?.includes(filter.value?.id || filter.value)
|
||||||
}"
|
}"
|
||||||
(click)="handleFilterClick(filterType, filter.value?.id || filter.value)">
|
(click)="handleFilterClick(filterType, filter.value?.id || filter.value)">
|
||||||
<p-badge [value]="filter.bookCount"></p-badge>
|
<p-badge [value]="filter.bookCount"></p-badge>
|
||||||
@if (filterType === 'amazonRating') {
|
@if (filterType === 'amazonRating') {
|
||||||
|
|||||||
+20
-8
@@ -7,7 +7,7 @@ import {Shelf} from '../../../model/shelf.model';
|
|||||||
import {EntityType} from '../book-browser.component';
|
import {EntityType} from '../book-browser.component';
|
||||||
import {Book} from '../../../model/book.model';
|
import {Book} from '../../../model/book.model';
|
||||||
import {Accordion, AccordionContent, AccordionHeader, AccordionPanel} from 'primeng/accordion';
|
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 {Badge} from 'primeng/badge';
|
||||||
import {FormsModule} from '@angular/forms';
|
import {FormsModule} from '@angular/forms';
|
||||||
import {SelectButton} from 'primeng/selectbutton';
|
import {SelectButton} from 'primeng/selectbutton';
|
||||||
@@ -116,7 +116,7 @@ function getPageCountRangeFilters(pageCount?: number) {
|
|||||||
TitleCasePipe,
|
TitleCasePipe,
|
||||||
FormsModule,
|
FormsModule,
|
||||||
SelectButton
|
SelectButton
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
export class BookFilterComponent implements OnInit {
|
export class BookFilterComponent implements OnInit {
|
||||||
@Output() filterSelected = new EventEmitter<Record<string, any> | null>();
|
@Output() filterSelected = new EventEmitter<Record<string, any> | null>();
|
||||||
@@ -131,11 +131,11 @@ export class BookFilterComponent implements OnInit {
|
|||||||
filterStreams: Record<string, Observable<Filter<any>[]>> = {};
|
filterStreams: Record<string, Observable<Filter<any>[]>> = {};
|
||||||
filterTypes: string[] = [];
|
filterTypes: string[] = [];
|
||||||
filterModeOptions = [
|
filterModeOptions = [
|
||||||
{ label: 'AND', value: 'and' },
|
{label: 'AND', value: 'and'},
|
||||||
{ label: 'OR', value: 'or' }
|
{label: 'OR', value: 'or'}
|
||||||
];
|
];
|
||||||
private _selectedFilterMode: 'and' | 'or' = 'and';
|
private _selectedFilterMode: 'and' | 'or' = 'and';
|
||||||
|
expandedPanels: number = 0;
|
||||||
readonly filterLabels: Record<string, string> = {
|
readonly filterLabels: Record<string, string> = {
|
||||||
author: 'Author',
|
author: 'Author',
|
||||||
category: 'Category',
|
category: 'Category',
|
||||||
@@ -175,6 +175,8 @@ export class BookFilterComponent implements OnInit {
|
|||||||
if (this.resetFilter$) {
|
if (this.resetFilter$) {
|
||||||
this.resetFilter$.subscribe(() => this.clearActiveFilter());
|
this.resetFilter$.subscribe(() => this.clearActiveFilter());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.setExpandedPanels();
|
||||||
}
|
}
|
||||||
|
|
||||||
private getFilterStream<T>(
|
private getFilterStream<T>(
|
||||||
@@ -241,7 +243,7 @@ export class BookFilterComponent implements OnInit {
|
|||||||
if (Object.keys(this.activeFilters).length === 0) {
|
if (Object.keys(this.activeFilters).length === 0) {
|
||||||
this.filterSelected.emit(null);
|
this.filterSelected.emit(null);
|
||||||
} else {
|
} 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.activeFilters[key] = [value];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this.filterSelected.emit({...this.activeFilters});
|
||||||
this.filterSelected.emit({ ...this.activeFilters });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
clearActiveFilter() {
|
clearActiveFilter() {
|
||||||
this.activeFilters = {};
|
this.activeFilters = {};
|
||||||
this.filterSelected.emit(null);
|
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