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:
@@ -7,7 +7,7 @@ import {InputText} from 'primeng/inputtext';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {ProgressSpinner} from 'primeng/progressspinner';
|
||||
import {MenuItem} from 'primeng/api';
|
||||
import {CheckboxModule} from 'primeng/checkbox';
|
||||
import {Checkbox} from 'primeng/checkbox';
|
||||
import {InputIcon} from 'primeng/inputicon';
|
||||
import {Button} from 'primeng/button';
|
||||
import {IconField} from 'primeng/iconfield';
|
||||
@@ -23,7 +23,7 @@ import {TranslocoDirective, TranslocoPipe} from '@jsverse/transloco';
|
||||
InputText,
|
||||
FormsModule,
|
||||
ProgressSpinner,
|
||||
CheckboxModule,
|
||||
Checkbox,
|
||||
InputIcon,
|
||||
Button,
|
||||
InputIcon,
|
||||
|
||||
@@ -9,7 +9,7 @@ import {UrlHelperService} from '../../service/url-helper.service';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {IconCategoriesHelper} from '../../helpers/icon-categories.helper';
|
||||
import {Button} from 'primeng/button';
|
||||
import {TabsModule} from 'primeng/tabs';
|
||||
import {Tab, TabList, TabPanel, TabPanels, Tabs} from 'primeng/tabs';
|
||||
import {UserService} from '../../../features/settings/user-management/user.service';
|
||||
import {from, of} from 'rxjs';
|
||||
import {catchError, mergeMap, toArray} from 'rxjs/operators';
|
||||
@@ -39,7 +39,7 @@ interface SvgIconBatchResponse {
|
||||
imports: [
|
||||
FormsModule,
|
||||
Button,
|
||||
TabsModule
|
||||
Tabs, TabList, Tab, TabPanels, TabPanel
|
||||
],
|
||||
templateUrl: './icon-picker-component.html',
|
||||
styleUrl: './icon-picker-component.scss'
|
||||
|
||||
+7
-10
@@ -1,9 +1,8 @@
|
||||
import {Component, inject, OnDestroy, OnInit} from '@angular/core';
|
||||
import {Subject} from 'rxjs';
|
||||
import {takeUntil} from 'rxjs/operators';
|
||||
import {Component, DestroyRef, inject, OnDestroy, OnInit} from '@angular/core';
|
||||
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
|
||||
import {KeyValuePipe} from '@angular/common';
|
||||
import {ProgressBarModule} from 'primeng/progressbar';
|
||||
import {ButtonModule} from 'primeng/button';
|
||||
import {ProgressBar} from 'primeng/progressbar';
|
||||
import {Button} from 'primeng/button';
|
||||
import {Divider} from 'primeng/divider';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {MessageService} from 'primeng/api';
|
||||
@@ -21,12 +20,12 @@ import {DialogLauncherService} from '../../services/dialog-launcher.service';
|
||||
templateUrl: './metadata-progress-widget-component.html',
|
||||
styleUrls: ['./metadata-progress-widget-component.scss'],
|
||||
standalone: true,
|
||||
imports: [KeyValuePipe, ProgressBarModule, ButtonModule, Divider, Tooltip, Tag, TranslocoDirective]
|
||||
imports: [KeyValuePipe, ProgressBar, Button, Divider, Tooltip, Tag, TranslocoDirective]
|
||||
})
|
||||
export class MetadataProgressWidgetComponent implements OnInit, OnDestroy {
|
||||
activeTasks: Record<string, MetadataBatchProgressNotification> = {};
|
||||
|
||||
private destroy$ = new Subject<void>();
|
||||
private readonly destroyRef = inject(DestroyRef);
|
||||
private dialogLauncherService = inject(DialogLauncherService);
|
||||
private metadataProgressService = inject(MetadataProgressService);
|
||||
private metadataTaskService = inject(MetadataTaskService);
|
||||
@@ -40,7 +39,7 @@ export class MetadataProgressWidgetComponent implements OnInit, OnDestroy {
|
||||
|
||||
ngOnInit(): void {
|
||||
this.metadataProgressService.activeTasks$
|
||||
.pipe(takeUntil(this.destroy$))
|
||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||
.subscribe(tasks => {
|
||||
this.activeTasks = tasks;
|
||||
this.checkForStalledTasks(tasks);
|
||||
@@ -137,8 +136,6 @@ export class MetadataProgressWidgetComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.destroy$.next();
|
||||
this.destroy$.complete();
|
||||
for (const timeout of this.timeoutHandles.values()) {
|
||||
clearTimeout(timeout);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
]
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { chunk } from './array.util';
|
||||
|
||||
describe('ArrayUtils', () => {
|
||||
describe('chunk', () => {
|
||||
it('should split an array into chunks of the specified size', () => {
|
||||
const input = [1, 2, 3, 4, 5];
|
||||
const result = chunk(input, 2);
|
||||
expect(result).toEqual([[1, 2], [3, 4], [5]]);
|
||||
});
|
||||
|
||||
it('should return an empty array if the input array is empty', () => {
|
||||
const input: number[] = [];
|
||||
const result = chunk(input, 2);
|
||||
expect(result).toEqual([]);
|
||||
});
|
||||
|
||||
it('should return the original array in a single chunk if the size is larger than the array length', () => {
|
||||
const input = [1, 2, 3];
|
||||
const result = chunk(input, 5);
|
||||
expect(result).toEqual([[1, 2, 3]]);
|
||||
});
|
||||
|
||||
it('should handle a chunk size of 1', () => {
|
||||
const input = [1, 2, 3];
|
||||
const result = chunk(input, 1);
|
||||
expect(result).toEqual([[1], [2], [3]]);
|
||||
});
|
||||
|
||||
it('should return the entire array in a single chunk if the size is 0 or negative', () => {
|
||||
const input = [1, 2, 3];
|
||||
expect(chunk(input, 0)).toEqual([[1, 2, 3]]);
|
||||
expect(chunk(input, -1)).toEqual([[1, 2, 3]]);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* Splits an array into chunks of a given size.
|
||||
*
|
||||
* @param array The array to split.
|
||||
* @param size The size of each chunk.
|
||||
* @returns An array of chunks.
|
||||
*/
|
||||
export function chunk<T>(array: T[], size: number): T[][] {
|
||||
if (size <= 0) {
|
||||
return array.length > 0 ? [[...array]] : [];
|
||||
}
|
||||
|
||||
const chunks: T[][] = [];
|
||||
for (let i = 0; i < array.length; i += size) {
|
||||
chunks.push(array.slice(i, i + size));
|
||||
}
|
||||
return chunks;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
export function computeGridColumns(containerWidth: number, minColumnWidth: number, gap: number = 21): number {
|
||||
if (containerWidth <= 0 || minColumnWidth <= 0) {
|
||||
return 1;
|
||||
}
|
||||
return Math.max(1, Math.floor((containerWidth + gap) / (minColumnWidth + gap)));
|
||||
}
|
||||
Reference in New Issue
Block a user