chore(ui): lazily load filter sidebar content (#283)
* chore(ui): filter sidebar lazy loading * fix(ui): remove spec --------- Co-authored-by: brios <127139797+balazs-szucs@users.noreply.github.com>
This commit is contained in:
+16
-16
@@ -16,10 +16,8 @@
|
||||
<div class="filter-content">
|
||||
<p-accordion [value]="expandedPanels" [multiple]="true" (valueChange)="onExpandedPanelsChange($event)">
|
||||
@for (filterType of visibleFilterTypes; track trackByFilterType(i, filterType); let i = $index) {
|
||||
@if (filterSignals[filterType](); as filters) {
|
||||
@if (filters.length > 0) {
|
||||
<p-accordion-panel [value]="i">
|
||||
<p-accordion-header>
|
||||
<p-accordion-panel [value]="i">
|
||||
<p-accordion-header>
|
||||
<span class="filter-type-label">
|
||||
<span class="filter-label-text">
|
||||
{{ getFilterLabel(filterType) }}
|
||||
@@ -30,10 +28,12 @@
|
||||
</span>
|
||||
}
|
||||
</span>
|
||||
</p-accordion-header>
|
||||
</p-accordion-header>
|
||||
|
||||
<p-accordion-content>
|
||||
@if (expandedPanels.includes(i)) {
|
||||
<p-accordion-content>
|
||||
@if (expandedPanels.includes(i)) {
|
||||
@if (filterSignals[filterType](); as filters) {
|
||||
@if (filters.length > 0) {
|
||||
<cdk-virtual-scroll-viewport
|
||||
[itemSize]="28"
|
||||
[style.height.px]="getVirtualScrollHeight(filters.length)"
|
||||
@@ -53,16 +53,16 @@
|
||||
<p-badge class="filter-value-badge" [value]="filter.bookCount"></p-badge>
|
||||
</div>
|
||||
</cdk-virtual-scroll-viewport>
|
||||
@if (truncatedFilters[filterType]) {
|
||||
<div class="truncation-notice">
|
||||
{{ t('showingFirst100') }}
|
||||
</div>
|
||||
}
|
||||
}
|
||||
</p-accordion-content>
|
||||
</p-accordion-panel>
|
||||
}
|
||||
}
|
||||
@if (truncatedFilters[filterType]) {
|
||||
<div class="truncation-notice">
|
||||
{{ t('showingFirst100') }}
|
||||
</div>
|
||||
}
|
||||
}
|
||||
}
|
||||
</p-accordion-content>
|
||||
</p-accordion-panel>
|
||||
}
|
||||
</p-accordion>
|
||||
|
||||
|
||||
+4
-4
@@ -65,7 +65,7 @@ export class BookFilterComponent implements OnInit, OnDestroy {
|
||||
);
|
||||
filterTypes: FilterType[] = Object.keys(this.filterSignals) as FilterType[];
|
||||
visibleFilterTypes: FilterType[] = [];
|
||||
expandedPanels: number[] = [0];
|
||||
expandedPanels: number[] = [];
|
||||
truncatedFilters: Record<string, boolean> = {};
|
||||
|
||||
private _selectedFilterMode: BookFilterMode = 'and';
|
||||
@@ -128,7 +128,7 @@ export class BookFilterComponent implements OnInit, OnDestroy {
|
||||
|
||||
clearActiveFilter(): void {
|
||||
this.activeFilters = {};
|
||||
this.expandedPanels = [0];
|
||||
this.expandedPanels = [];
|
||||
this.activeFiltersSignal.set(null);
|
||||
this.filterSelected.emit(null);
|
||||
}
|
||||
@@ -227,10 +227,10 @@ export class BookFilterComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
private updateExpandedPanels(): void {
|
||||
const panels = new Set(this.expandedPanels);
|
||||
const panels = new Set<number>();
|
||||
this.visibleFilterTypes.forEach((type, i) => {
|
||||
if (this.activeFilters[type]?.length) panels.add(i);
|
||||
});
|
||||
this.expandedPanels = panels.size > 0 ? [...panels] : [0];
|
||||
this.expandedPanels = [...panels];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,12 +183,39 @@ export function filterBooksByFilters(
|
||||
|
||||
if (filterEntries.length === 0) return books;
|
||||
|
||||
return books.filter(book => {
|
||||
const matches = filterEntries.map(([filterType, filterValues]) =>
|
||||
doesBookMatchFilter(book, filterType, filterValues, mode)
|
||||
);
|
||||
if (mode === 'not') return matches.every(m => !m);
|
||||
return mode === 'or' ? matches.some(m => m) : matches.every(m => m);
|
||||
});
|
||||
return books.filter(book => matchesAllFilters(book, filterEntries, mode));
|
||||
}
|
||||
|
||||
function matchesAllFilters(
|
||||
book: Book,
|
||||
filterEntries: [string, unknown[]][],
|
||||
mode: BookFilterMode
|
||||
): boolean {
|
||||
if (mode === 'or') {
|
||||
for (const [filterType, filterValues] of filterEntries) {
|
||||
if (doesBookMatchFilter(book, filterType, filterValues, mode)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (mode === 'not') {
|
||||
for (const [filterType, filterValues] of filterEntries) {
|
||||
if (doesBookMatchFilter(book, filterType, filterValues, mode)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
for (const [filterType, filterValues] of filterEntries) {
|
||||
if (!doesBookMatchFilter(book, filterType, filterValues, mode)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user