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:
+5
-9
@@ -77,14 +77,10 @@
|
||||
<p>{{ t('noSeriesFound') }}</p>
|
||||
</div>
|
||||
} @else {
|
||||
<virtual-scroller
|
||||
#scroll
|
||||
[items]="seriesList"
|
||||
class="virtual-scroller">
|
||||
<div class="series-grid"
|
||||
#container
|
||||
[ngStyle]="{'grid-template-columns': 'repeat(auto-fill, minmax(' + gridColumnMinWidth + ', 1fr))'}">
|
||||
@for (series of scroll.viewPortItems; track series.seriesName) {
|
||||
<cdk-virtual-scroll-viewport autosize [minBufferPx]="600" [maxBufferPx]="1200" class="virtual-scroller">
|
||||
<div *cdkVirtualFor="let row of seriesRows(); let rowIdx = index" class="series-grid"
|
||||
[ngStyle]="{'grid-template-columns': 'repeat(' + gridColumns() + ', 1fr)'}">
|
||||
@for (series of row; track series.seriesName) {
|
||||
<div class="virtual-scroller-item"
|
||||
[ngStyle]="{width: cardWidth + 'px', height: cardHeight + 'px'}"
|
||||
[style.--card-scale]="seriesScaleService.scaleFactor()">
|
||||
@@ -95,7 +91,7 @@
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</virtual-scroller>
|
||||
</cdk-virtual-scroll-viewport>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
-1
@@ -108,7 +108,6 @@
|
||||
height: calc(100dvh - 12.5rem);
|
||||
padding: 1rem;
|
||||
box-sizing: border-box;
|
||||
overflow-y: auto;
|
||||
scrollbar-width: thin;
|
||||
scrollbar-color: var(--primary-color) rgb(20 20 30 / 50%);
|
||||
|
||||
|
||||
+40
-3
@@ -1,4 +1,5 @@
|
||||
import {Component, HostListener, computed, inject, OnInit, signal} from '@angular/core';
|
||||
import {Component, DestroyRef, HostListener, computed, inject, OnInit, signal, ViewChild} from '@angular/core';
|
||||
import {computeGridColumns} from '../../../../shared/util/viewport.util';
|
||||
import {NgStyle} from '@angular/common';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {ProgressSpinner} from 'primeng/progressspinner';
|
||||
@@ -7,10 +8,12 @@ import {Select} from 'primeng/select';
|
||||
import {Slider} from 'primeng/slider';
|
||||
import {Popover} from 'primeng/popover';
|
||||
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
||||
import {VirtualScrollerModule} from '@iharbeck/ngx-virtual-scroller';
|
||||
import {CdkVirtualScrollViewport, CdkVirtualForOf} from '@angular/cdk/scrolling';
|
||||
import {CdkAutoSizeVirtualScroll} from '@angular/cdk-experimental/scrolling';
|
||||
import {SeriesDataService} from '../../service/series-data.service';
|
||||
import {SeriesSummary} from '../../model/series.model';
|
||||
import {SeriesCardComponent} from '../series-card/series-card.component';
|
||||
import {chunk} from '../../../../shared/util/array.util';
|
||||
import {BookService} from '../../../book/service/book.service';
|
||||
import {ReadStatus} from '../../../book/model/book.model';
|
||||
import {PageTitleService} from '../../../../shared/service/page-title.service';
|
||||
@@ -42,7 +45,9 @@ interface SortOption {
|
||||
Popover,
|
||||
TranslocoDirective,
|
||||
SeriesCardComponent,
|
||||
VirtualScrollerModule
|
||||
CdkVirtualScrollViewport,
|
||||
CdkVirtualForOf,
|
||||
CdkAutoSizeVirtualScroll,
|
||||
]
|
||||
})
|
||||
export class SeriesBrowserComponent implements OnInit {
|
||||
@@ -51,14 +56,35 @@ export class SeriesBrowserComponent implements OnInit {
|
||||
private static readonly BASE_HEIGHT = 285;
|
||||
private static readonly MOBILE_BASE_WIDTH = 180;
|
||||
private static readonly MOBILE_BASE_HEIGHT = 250;
|
||||
private static readonly GRID_GAP = 20;
|
||||
|
||||
private seriesDataService = inject(SeriesDataService);
|
||||
private bookService = inject(BookService);
|
||||
private pageTitle = inject(PageTitleService);
|
||||
private t = inject(TranslocoService);
|
||||
private router = inject(Router);
|
||||
private destroyRef = inject(DestroyRef);
|
||||
protected seriesScaleService = inject(SeriesScalePreferenceService);
|
||||
|
||||
virtualScroller: CdkVirtualScrollViewport | undefined;
|
||||
|
||||
@ViewChild(CdkVirtualScrollViewport)
|
||||
set scrollViewport(vp: CdkVirtualScrollViewport | undefined) {
|
||||
this.virtualScroller = vp;
|
||||
this.viewportResizeObserver?.disconnect();
|
||||
if (vp) {
|
||||
const el = vp.elementRef.nativeElement as HTMLElement;
|
||||
this.viewportWidth.set(el.clientWidth);
|
||||
this.viewportResizeObserver = new ResizeObserver(entries => {
|
||||
this.viewportWidth.set(entries[0]?.contentRect.width ?? el.clientWidth);
|
||||
});
|
||||
this.viewportResizeObserver.observe(el);
|
||||
}
|
||||
}
|
||||
|
||||
private readonly viewportWidth = signal(0);
|
||||
private viewportResizeObserver: ResizeObserver | undefined;
|
||||
|
||||
readonly isBooksLoading = this.bookService.isBooksLoading;
|
||||
private readonly searchTerm = signal('');
|
||||
private readonly statusFilter = signal('all');
|
||||
@@ -109,6 +135,14 @@ export class SeriesBrowserComponent implements OnInit {
|
||||
return `${this.cardWidth}px`;
|
||||
}
|
||||
|
||||
readonly gridColumns = computed(() => {
|
||||
return computeGridColumns(this.viewportWidth(), this.cardWidth || 230, SeriesBrowserComponent.GRID_GAP);
|
||||
});
|
||||
|
||||
readonly seriesRows = computed(() => {
|
||||
return chunk(this.filteredSeries(), this.gridColumns());
|
||||
});
|
||||
|
||||
get searchValue(): string {
|
||||
return this.searchTerm();
|
||||
}
|
||||
@@ -123,6 +157,7 @@ export class SeriesBrowserComponent implements OnInit {
|
||||
|
||||
ngOnInit(): void {
|
||||
this.pageTitle.setPageTitle(this.t.translate('seriesBrowser.pageTitle'));
|
||||
this.destroyRef.onDestroy(() => this.viewportResizeObserver?.disconnect());
|
||||
|
||||
this.filterOptions = [
|
||||
{label: this.t.translate('seriesBrowser.filters.all'), value: 'all'},
|
||||
@@ -142,6 +177,8 @@ export class SeriesBrowserComponent implements OnInit {
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
|
||||
onSearchChange(value: string): void {
|
||||
this.searchTerm.set(value);
|
||||
}
|
||||
|
||||
+5
@@ -1,3 +1,8 @@
|
||||
:host {
|
||||
content-visibility: auto;
|
||||
contain-intrinsic-size: auto 230px 285px;
|
||||
}
|
||||
|
||||
.series-card {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
Reference in New Issue
Block a user