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:
@@ -94,7 +94,12 @@
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div [@children]="expanded ? 'expanded' : 'collapsed'" class="submenu-container">
|
||||
<div
|
||||
class="submenu-container"
|
||||
[class.expanded]="expanded"
|
||||
[attr.aria-hidden]="!expanded"
|
||||
[attr.inert]="expanded ? null : ''"
|
||||
>
|
||||
@if (item.items) {
|
||||
<ul>
|
||||
@for (child of item.items; track child.routerLink?.join('/') ?? child.label; let i = $index) {
|
||||
|
||||
@@ -154,7 +154,23 @@
|
||||
}
|
||||
|
||||
.submenu-container {
|
||||
display: grid;
|
||||
grid-template-rows: 0fr;
|
||||
transition: grid-template-rows 400ms cubic-bezier(0.86, 0, 0.07, 1);
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
transition: none;
|
||||
}
|
||||
|
||||
overflow: hidden;
|
||||
|
||||
> * {
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
&.expanded {
|
||||
grid-template-rows: 1fr;
|
||||
}
|
||||
}
|
||||
|
||||
.library-health-dot {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { ChangeDetectionStrategy, Component, computed, HostBinding, inject, Input, OnInit } from '@angular/core';
|
||||
import { RouterLink } from '@angular/router';
|
||||
import { animate, state, style, transition, trigger } from '@angular/animations';
|
||||
import { MenuService } from './app.menu.service';
|
||||
import { NgClass } from '@angular/common';
|
||||
import { Menu } from 'primeng/menu';
|
||||
@@ -25,18 +24,7 @@ import { NavItem } from './app.menu.component';
|
||||
Menu,
|
||||
IconDisplayComponent,
|
||||
Tooltip,
|
||||
TranslocoPipe
|
||||
],
|
||||
animations: [
|
||||
trigger('children', [
|
||||
state('collapsed', style({
|
||||
height: '0'
|
||||
})),
|
||||
state('expanded', style({
|
||||
height: '*'
|
||||
})),
|
||||
transition('collapsed <=> expanded', animate('400ms cubic-bezier(0.86, 0, 0.07, 1)'))
|
||||
])
|
||||
TranslocoPipe,
|
||||
],
|
||||
changeDetection: ChangeDetectionStrategy.OnPush
|
||||
})
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { Component, effect, inject, OnDestroy, ViewChild } from '@angular/core';
|
||||
import { Component, DestroyRef, effect, inject, OnDestroy, ViewChild } from '@angular/core';
|
||||
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
||||
import { LayoutService } from '../layout.service';
|
||||
import { Router, RouterLink } from '@angular/router';
|
||||
import { TooltipModule } from 'primeng/tooltip';
|
||||
import { Tooltip } from 'primeng/tooltip';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import { InputTextModule } from 'primeng/inputtext';
|
||||
|
||||
import { BookSearcherComponent } from '../../../features/book/components/book-searcher/book-searcher.component';
|
||||
import { NgClass, NgStyle } from '@angular/common';
|
||||
import { NotificationEventService } from '../../websocket/notification-event.service';
|
||||
@@ -14,8 +15,7 @@ import { AuthService } from '../../service/auth.service';
|
||||
import { UserService } from '../../../features/settings/user-management/user.service';
|
||||
import { Popover } from 'primeng/popover';
|
||||
import { MetadataProgressService } from '../../service/metadata-progress.service';
|
||||
import { takeUntil } from 'rxjs/operators';
|
||||
import { Subject } from 'rxjs';
|
||||
|
||||
import { MetadataBatchProgressNotification } from '../../model/metadata-batch-progress.model';
|
||||
import { BookdropFileService } from '../../../features/bookdrop/service/bookdrop-file.service';
|
||||
import { DialogLauncherService } from '../../services/dialog-launcher.service';
|
||||
@@ -33,9 +33,8 @@ import type { MenuItem } from 'primeng/api';
|
||||
styleUrls: ['./app.topbar.component.scss'],
|
||||
imports: [
|
||||
RouterLink,
|
||||
TooltipModule,
|
||||
Tooltip,
|
||||
FormsModule,
|
||||
InputTextModule,
|
||||
BookSearcherComponent,
|
||||
ThemeConfiguratorComponent,
|
||||
StyleClass,
|
||||
@@ -71,7 +70,7 @@ export class AppTopBarComponent implements OnDestroy {
|
||||
hasPendingBookdropFiles = false;
|
||||
|
||||
private eventTimer: number | undefined;
|
||||
private destroy$ = new Subject<void>();
|
||||
private readonly destroyRef = inject(DestroyRef);
|
||||
|
||||
private latestTasks: Record<string, MetadataBatchProgressNotification> = {};
|
||||
private latestHasPendingFiles = false;
|
||||
@@ -87,7 +86,7 @@ export class AppTopBarComponent implements OnDestroy {
|
||||
this.subscribeToNotifications();
|
||||
|
||||
this.metadataProgressService.activeTasks$
|
||||
.pipe(takeUntil(this.destroy$))
|
||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||
.subscribe((tasks) => {
|
||||
this.latestTasks = tasks;
|
||||
this.hasAnyTasks = Object.keys(tasks).length > 0;
|
||||
@@ -96,7 +95,7 @@ export class AppTopBarComponent implements OnDestroy {
|
||||
});
|
||||
|
||||
this.bookdropFileService.hasPendingFiles$
|
||||
.pipe(takeUntil(this.destroy$))
|
||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||
.subscribe((hasPending) => {
|
||||
this.latestHasPendingFiles = hasPending;
|
||||
this.hasPendingBookdropFiles = hasPending;
|
||||
@@ -110,7 +109,7 @@ export class AppTopBarComponent implements OnDestroy {
|
||||
});
|
||||
|
||||
this.translocoService.langChanges$
|
||||
.pipe(takeUntil(this.destroy$))
|
||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||
.subscribe(() => {
|
||||
this.initializeStatsMenu();
|
||||
});
|
||||
@@ -118,8 +117,6 @@ export class AppTopBarComponent implements OnDestroy {
|
||||
|
||||
ngOnDestroy(): void {
|
||||
clearTimeout(this.eventTimer);
|
||||
this.destroy$.next();
|
||||
this.destroy$.complete();
|
||||
}
|
||||
|
||||
toggleMenu() {
|
||||
@@ -185,7 +182,7 @@ export class AppTopBarComponent implements OnDestroy {
|
||||
|
||||
private subscribeToMetadataProgress() {
|
||||
this.metadataProgressService.progressUpdates$
|
||||
.pipe(takeUntil(this.destroy$))
|
||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||
.subscribe((progress) => {
|
||||
this.progressHighlight = progress.status === 'IN_PROGRESS';
|
||||
});
|
||||
@@ -193,7 +190,7 @@ export class AppTopBarComponent implements OnDestroy {
|
||||
|
||||
private subscribeToNotifications() {
|
||||
this.notificationService.latestNotification$
|
||||
.pipe(takeUntil(this.destroy$))
|
||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||
.subscribe((notification: LogNotification) => {
|
||||
this.latestNotificationSeverity = notification.severity;
|
||||
this.triggerPulseEffect();
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
import {CommonModule} from '@angular/common';
|
||||
import {ChangeDetectionStrategy, Component, computed, effect, inject} from '@angular/core';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {ButtonModule} from 'primeng/button';
|
||||
import {RadioButtonModule} from 'primeng/radiobutton';
|
||||
import {ToggleSwitchModule} from 'primeng/toggleswitch';
|
||||
|
||||
|
||||
import Aura from '../theme-palette-extend';
|
||||
|
||||
import {AppConfigService} from '../../service/app-config.service';
|
||||
import {TranslocoDirective} from '@jsverse/transloco';
|
||||
import {FaviconService} from './favicon-service';
|
||||
import {NgClass} from '@angular/common';
|
||||
|
||||
type ColorPalette = Record<string, string>;
|
||||
|
||||
@@ -27,11 +25,8 @@ interface Palette {
|
||||
class: 'config-panel hidden'
|
||||
},
|
||||
imports: [
|
||||
CommonModule,
|
||||
NgClass,
|
||||
FormsModule,
|
||||
ButtonModule,
|
||||
RadioButtonModule,
|
||||
ToggleSwitchModule,
|
||||
TranslocoDirective
|
||||
]
|
||||
})
|
||||
|
||||
+8
-10
@@ -1,11 +1,10 @@
|
||||
import {Component, inject} from '@angular/core';
|
||||
import {CommonModule} from '@angular/common';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
import {ButtonModule} from 'primeng/button';
|
||||
import {InputTextModule} from 'primeng/inputtext';
|
||||
import {DividerModule} from 'primeng/divider';
|
||||
import {MessageModule} from 'primeng/message';
|
||||
import {Button} from 'primeng/button';
|
||||
import {InputText} from 'primeng/inputtext';
|
||||
import {Divider} from 'primeng/divider';
|
||||
import {Message} from 'primeng/message';
|
||||
import {BackgroundUploadService} from '../background-upload.service';
|
||||
import {take} from 'rxjs';
|
||||
import {TranslocoDirective, TranslocoPipe, TranslocoService} from '@jsverse/transloco';
|
||||
@@ -16,12 +15,11 @@ import {TranslocoDirective, TranslocoPipe, TranslocoService} from '@jsverse/tran
|
||||
templateUrl: './upload-dialog.component.html',
|
||||
styleUrls: ['./upload-dialog.component.scss'],
|
||||
imports: [
|
||||
CommonModule,
|
||||
FormsModule,
|
||||
ButtonModule,
|
||||
InputTextModule,
|
||||
DividerModule,
|
||||
MessageModule,
|
||||
Button,
|
||||
InputText,
|
||||
Divider,
|
||||
Message,
|
||||
TranslocoDirective,
|
||||
TranslocoPipe
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user