From 2a2dee8e8fe162ea923f210f4730cba86f4fa981 Mon Sep 17 00:00:00 2001
From: Alex <25013571+alexhb1@users.noreply.github.com>
Date: Mon, 30 Mar 2026 18:28:23 +0100
Subject: [PATCH] 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>
---
.../book-filter/book-filter.component.html | 32 +++++++--------
.../book-filter/book-filter.component.ts | 8 ++--
.../book-browser/filters/sidebar-filter.ts | 41 +++++++++++++++----
3 files changed, 54 insertions(+), 27 deletions(-)
diff --git a/frontend/src/app/features/book/components/book-browser/book-filter/book-filter.component.html b/frontend/src/app/features/book/components/book-browser/book-filter/book-filter.component.html
index 9af2c0667..c26d61d10 100644
--- a/frontend/src/app/features/book/components/book-browser/book-filter/book-filter.component.html
+++ b/frontend/src/app/features/book/components/book-browser/book-filter/book-filter.component.html
@@ -16,10 +16,8 @@
@for (filterType of visibleFilterTypes; track trackByFilterType(i, filterType); let i = $index) {
- @if (filterSignals[filterType](); as filters) {
- @if (filters.length > 0) {
-
-
+
+
{{ getFilterLabel(filterType) }}
@@ -30,10 +28,12 @@
}
-
+
-
- @if (expandedPanels.includes(i)) {
+
+ @if (expandedPanels.includes(i)) {
+ @if (filterSignals[filterType](); as filters) {
+ @if (filters.length > 0) {
- @if (truncatedFilters[filterType]) {
-
- {{ t('showingFirst100') }}
-
- }
}
-
-
- }
- }
+ @if (truncatedFilters[filterType]) {
+
+ {{ t('showingFirst100') }}
+
+ }
+ }
+ }
+
+
}
diff --git a/frontend/src/app/features/book/components/book-browser/book-filter/book-filter.component.ts b/frontend/src/app/features/book/components/book-browser/book-filter/book-filter.component.ts
index f22f76aff..f624e7e0d 100644
--- a/frontend/src/app/features/book/components/book-browser/book-filter/book-filter.component.ts
+++ b/frontend/src/app/features/book/components/book-browser/book-filter/book-filter.component.ts
@@ -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 = {};
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();
this.visibleFilterTypes.forEach((type, i) => {
if (this.activeFilters[type]?.length) panels.add(i);
});
- this.expandedPanels = panels.size > 0 ? [...panels] : [0];
+ this.expandedPanels = [...panels];
}
}
diff --git a/frontend/src/app/features/book/components/book-browser/filters/sidebar-filter.ts b/frontend/src/app/features/book/components/book-browser/filters/sidebar-filter.ts
index bf87a7455..db060635f 100644
--- a/frontend/src/app/features/book/components/book-browser/filters/sidebar-filter.ts
+++ b/frontend/src/app/features/book/components/book-browser/filters/sidebar-filter.ts
@@ -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;
+}