fix(dashboard): improve performance with OnPush change detection (#440)

* fix(dashboard): improve performance with OnPush change detection

* fix(dashboard): refactor book card component for improved readability and performance

* fix(tests): mock matchMedia for improved test compatibility

* fix(tests): matchMedia mock for better CI compatibility and support

* fix(dashboard): add clearAll method to BookBrowserScrollService and update tests

* fix(dashboard): improve performance with content visibility and refactor styles

* fix(dashboard): improve scroll performance with estimated total height and refactor layout

* fix(tests): add mock for getCurrentUser in userService for improved test coverage

* fix(dashboard): implement infinite scroll for book loading and scroll restoration

* fix(tests): fix lint error

* fix(tests): mock ResizeObserver and IntersectionObserver

* fix(tests): mock ResizeObserver and IntersectionObserver (again)

* fix(dashboard): improve accessibility and performance by updating aria attributes and optimizing animations

* fix(dashboard): improve submenu accessibility and optimize virtual scroller performance

* fix(dashboard): clean up imports and improve component structure

* fix(dashboard): correct mobile check in author browser component

* fix(dashboard): add OnDestroy lifecycle hook to BookBrowserComponent
This commit is contained in:
brios
2026-04-22 17:27:11 -04:00
committed by Zach Yale
parent a779de8f57
commit 85e8d235b6
140 changed files with 1546 additions and 1233 deletions
+34 -1
View File
@@ -1,13 +1,26 @@
import {inject, Injectable} from '@angular/core';
import {ActivatedRouteSnapshot, DetachedRouteHandle, RouteReuseStrategy} from '@angular/router';
import {ActivatedRouteSnapshot, DetachedRouteHandle, destroyDetachedRouteHandle, RouteReuseStrategy} from '@angular/router';
import {BookBrowserScrollService} from '../features/book/components/book-browser/book-browser-scroll.service';
import {BookSelectionService} from '../features/book/components/book-browser/book-selection.service';
/**
* Maximum number of detached BookBrowser routes kept in memory.
* Each cached route retains its full component tree (book cards, images,
* event listeners, virtual-scroller instance) so an unbounded cache leads
* to severe memory growth when the user switches between libraries.
*
* 3 slots is enough for productive back-navigation while keeping memory
* usage under control.
*/
const MAX_STORED_ROUTES = 3;
@Injectable({
providedIn: 'root',
})
export class CustomReuseStrategy implements RouteReuseStrategy {
private storedRoutes = new Map<string, DetachedRouteHandle>();
/** Insertion-order queue so we can evict the oldest entry (LRU). */
private insertionOrder: string[] = [];
private scrollService = inject(BookBrowserScrollService);
private bookSelectionService = inject(BookSelectionService);
@@ -40,8 +53,28 @@ export class CustomReuseStrategy implements RouteReuseStrategy {
store(route: ActivatedRouteSnapshot, handle: DetachedRouteHandle | null): void {
if (handle && this.isBookBrowserRoute(route)) {
const key = this.getRouteKey(route);
// If the key already exists, remove it from insertion order so it
// can be re-appended at the end (most-recently-used).
const existingIdx = this.insertionOrder.indexOf(key);
if (existingIdx !== -1) {
this.insertionOrder.splice(existingIdx, 1);
}
this.storedRoutes.set(key, handle);
this.insertionOrder.push(key);
this.bookSelectionService.deselectAll();
// Evict oldest routes when we exceed the budget.
while (this.insertionOrder.length > MAX_STORED_ROUTES) {
const evictKey = this.insertionOrder.shift()!;
const evictedHandle = this.storedRoutes.get(evictKey);
this.storedRoutes.delete(evictKey);
this.scrollService.clearPosition(evictKey);
if (evictedHandle) {
destroyDetachedRouteHandle(evictedHandle);
}
}
}
}