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:
+4
-4
@@ -16,8 +16,6 @@
|
|||||||
<div class="filter-content">
|
<div class="filter-content">
|
||||||
<p-accordion [value]="expandedPanels" [multiple]="true" (valueChange)="onExpandedPanelsChange($event)">
|
<p-accordion [value]="expandedPanels" [multiple]="true" (valueChange)="onExpandedPanelsChange($event)">
|
||||||
@for (filterType of visibleFilterTypes; track trackByFilterType(i, filterType); let i = $index) {
|
@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-panel [value]="i">
|
||||||
<p-accordion-header>
|
<p-accordion-header>
|
||||||
<span class="filter-type-label">
|
<span class="filter-type-label">
|
||||||
@@ -34,6 +32,8 @@
|
|||||||
|
|
||||||
<p-accordion-content>
|
<p-accordion-content>
|
||||||
@if (expandedPanels.includes(i)) {
|
@if (expandedPanels.includes(i)) {
|
||||||
|
@if (filterSignals[filterType](); as filters) {
|
||||||
|
@if (filters.length > 0) {
|
||||||
<cdk-virtual-scroll-viewport
|
<cdk-virtual-scroll-viewport
|
||||||
[itemSize]="28"
|
[itemSize]="28"
|
||||||
[style.height.px]="getVirtualScrollHeight(filters.length)"
|
[style.height.px]="getVirtualScrollHeight(filters.length)"
|
||||||
@@ -53,17 +53,17 @@
|
|||||||
<p-badge class="filter-value-badge" [value]="filter.bookCount"></p-badge>
|
<p-badge class="filter-value-badge" [value]="filter.bookCount"></p-badge>
|
||||||
</div>
|
</div>
|
||||||
</cdk-virtual-scroll-viewport>
|
</cdk-virtual-scroll-viewport>
|
||||||
|
}
|
||||||
@if (truncatedFilters[filterType]) {
|
@if (truncatedFilters[filterType]) {
|
||||||
<div class="truncation-notice">
|
<div class="truncation-notice">
|
||||||
{{ t('showingFirst100') }}
|
{{ t('showingFirst100') }}
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
</p-accordion-content>
|
</p-accordion-content>
|
||||||
</p-accordion-panel>
|
</p-accordion-panel>
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
</p-accordion>
|
</p-accordion>
|
||||||
|
|
||||||
<div class="footer-notice">
|
<div class="footer-notice">
|
||||||
|
|||||||
+4
-4
@@ -65,7 +65,7 @@ export class BookFilterComponent implements OnInit, OnDestroy {
|
|||||||
);
|
);
|
||||||
filterTypes: FilterType[] = Object.keys(this.filterSignals) as FilterType[];
|
filterTypes: FilterType[] = Object.keys(this.filterSignals) as FilterType[];
|
||||||
visibleFilterTypes: FilterType[] = [];
|
visibleFilterTypes: FilterType[] = [];
|
||||||
expandedPanels: number[] = [0];
|
expandedPanels: number[] = [];
|
||||||
truncatedFilters: Record<string, boolean> = {};
|
truncatedFilters: Record<string, boolean> = {};
|
||||||
|
|
||||||
private _selectedFilterMode: BookFilterMode = 'and';
|
private _selectedFilterMode: BookFilterMode = 'and';
|
||||||
@@ -128,7 +128,7 @@ export class BookFilterComponent implements OnInit, OnDestroy {
|
|||||||
|
|
||||||
clearActiveFilter(): void {
|
clearActiveFilter(): void {
|
||||||
this.activeFilters = {};
|
this.activeFilters = {};
|
||||||
this.expandedPanels = [0];
|
this.expandedPanels = [];
|
||||||
this.activeFiltersSignal.set(null);
|
this.activeFiltersSignal.set(null);
|
||||||
this.filterSelected.emit(null);
|
this.filterSelected.emit(null);
|
||||||
}
|
}
|
||||||
@@ -227,10 +227,10 @@ export class BookFilterComponent implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private updateExpandedPanels(): void {
|
private updateExpandedPanels(): void {
|
||||||
const panels = new Set(this.expandedPanels);
|
const panels = new Set<number>();
|
||||||
this.visibleFilterTypes.forEach((type, i) => {
|
this.visibleFilterTypes.forEach((type, i) => {
|
||||||
if (this.activeFilters[type]?.length) panels.add(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;
|
if (filterEntries.length === 0) return books;
|
||||||
|
|
||||||
return books.filter(book => {
|
return books.filter(book => matchesAllFilters(book, filterEntries, mode));
|
||||||
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);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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