From c6cbdcfa11eb6c93b53418af61f74ff73917b291 Mon Sep 17 00:00:00 2001 From: brios <127139797+balazs-szucs@users.noreply.github.com> Date: Mon, 18 May 2026 23:05:10 +0200 Subject: [PATCH] perf(frontend): optimize initial bundle size with lazy-loaded dialogs and localized chart providers (#1110) --- .../book-browser/book-browser.component.ts | 28 +- .../book-card/book-card.component.spec.ts | 10 +- .../book-card/book-card.component.ts | 12 +- .../book-dialog-helper.service.spec.ts | 20 +- .../book-dialog-helper.service.ts | 315 ++++++++++-------- .../series-page/series-page.component.ts | 24 +- .../library-shelf-menu.service.spec.ts | 14 +- .../service/library-shelf-menu.service.ts | 24 +- .../bookdrop-file-review.component.spec.ts | 6 +- .../command-palette.service.spec.ts | 10 +- .../command-palette.service.ts | 13 +- .../main-dashboard.component.ts | 4 +- .../library-creator.component.ts | 4 +- .../metadata-editor.component.ts | 8 +- .../metadata-viewer.component.spec.ts | 10 +- .../metadata-viewer.component.ts | 20 +- .../email-v2-provider.component.ts | 4 +- .../email-v2-recipient.component.ts | 4 +- .../user-management.component.ts | 4 +- .../library-stats/library-stats.component.ts | 4 + .../user-stats/user-stats.component.ts | 4 + ...metadata-progress-widget-component.spec.ts | 2 +- .../metadata-progress-widget-component.ts | 2 +- .../app.sidebar.component.spec.ts | 10 +- .../layout-sidebar/app.sidebar.component.ts | 73 ++-- .../service/icon-picker.service.spec.ts | 2 +- .../app/shared/service/icon-picker.service.ts | 12 +- .../services/dialog-launcher.service.spec.ts | 16 +- .../services/dialog-launcher.service.ts | 269 +++++++++------ frontend/src/i18n/en/book.json | 3 +- frontend/src/i18n/en/common.json | 3 +- frontend/src/main.ts | 3 - 32 files changed, 532 insertions(+), 405 deletions(-) diff --git a/frontend/src/app/features/book/components/book-browser/book-browser.component.ts b/frontend/src/app/features/book/components/book-browser/book-browser.component.ts index a2d6dde70..0724359e9 100644 --- a/frontend/src/app/features/book/components/book-browser/book-browser.component.ts +++ b/frontend/src/app/features/book/components/book-browser/book-browser.component.ts @@ -895,8 +895,8 @@ export class BookBrowserComponent implements AfterViewInit { }); } - openShelfAssigner(): void { - this.dynamicDialogRef = this.dialogHelperService.openShelfAssignerDialog(null, this.selectedBooks()); + async openShelfAssigner() { + this.dynamicDialogRef = await this.dialogHelperService.openShelfAssignerDialog(null, this.selectedBooks()); if (this.dynamicDialogRef) { this.dynamicDialogRef.onClose.pipe(take(1)).subscribe(result => { if (result?.assigned) { @@ -906,8 +906,8 @@ export class BookBrowserComponent implements AfterViewInit { } } - lockUnlockMetadata(): void { - this.dynamicDialogRef = this.dialogHelperService.openLockUnlockMetadataDialog(this.selectedBooks()); + async lockUnlockMetadata() { + this.dynamicDialogRef = await this.dialogHelperService.openLockUnlockMetadataDialog(this.selectedBooks()); if (this.dynamicDialogRef) { this.dynamicDialogRef.onClose.pipe(take(1)).subscribe(() => { this.bookSelectionService.deselectAll(); @@ -924,12 +924,12 @@ export class BookBrowserComponent implements AfterViewInit { }).subscribe(); } - fetchMetadata(): void { - this.dialogHelperService.openMetadataRefreshDialog(this.selectedBooks()); + async fetchMetadata() { + await this.dialogHelperService.openMetadataRefreshDialog(this.selectedBooks()); } - bulkEditMetadata(): void { - this.dynamicDialogRef = this.dialogHelperService.openBulkMetadataEditDialog(this.selectedBooks()); + async bulkEditMetadata() { + this.dynamicDialogRef = await this.dialogHelperService.openBulkMetadataEditDialog(this.selectedBooks()); if (this.dynamicDialogRef) { this.dynamicDialogRef.onClose.pipe(take(1)).subscribe(() => { this.bookSelectionService.deselectAll(); @@ -937,8 +937,8 @@ export class BookBrowserComponent implements AfterViewInit { } } - multiBookEditMetadata(): void { - this.dynamicDialogRef = this.dialogHelperService.openMultibookMetadataEditorDialog(this.selectedBooks()); + async multiBookEditMetadata() { + this.dynamicDialogRef = await this.dialogHelperService.openMultibookMetadataEditorDialog(this.selectedBooks()); if (this.dynamicDialogRef) { this.dynamicDialogRef.onClose.pipe(take(1)).subscribe(() => { this.bookSelectionService.deselectAll(); @@ -1028,11 +1028,11 @@ export class BookBrowserComponent implements AfterViewInit { }); } - moveFiles(): void { - this.dialogHelperService.openFileMoverDialog(this.selectedBooks()); + async moveFiles() { + await this.dialogHelperService.openFileMoverDialog(this.selectedBooks()); } - attachFilesToBook(): void { + async attachFilesToBook() { const selectedBookIds = Array.from(this.selectedBooks()); const sourceBooks = this.books().filter(book => selectedBookIds.includes(book.id) @@ -1058,7 +1058,7 @@ export class BookBrowserComponent implements AfterViewInit { return; } - this.dynamicDialogRef = this.dialogHelperService.openBulkBookFileAttacherDialog(sourceBooks); + this.dynamicDialogRef = await this.dialogHelperService.openBulkBookFileAttacherDialog(sourceBooks); if (this.dynamicDialogRef) { this.dynamicDialogRef.onClose.pipe(take(1)).subscribe(result => { if (result?.success) { diff --git a/frontend/src/app/features/book/components/book-browser/book-card/book-card.component.spec.ts b/frontend/src/app/features/book/components/book-browser/book-card/book-card.component.spec.ts index e4f0a2669..a961536d1 100644 --- a/frontend/src/app/features/book/components/book-browser/book-card/book-card.component.spec.ts +++ b/frontend/src/app/features/book/components/book-browser/book-card/book-card.component.spec.ts @@ -187,11 +187,11 @@ describe('BookCardComponent', () => { confirm: vi.fn(), }; bookDialogHelperService = { - openShelfAssignerDialog: vi.fn(), - openBookDetailsDialog: vi.fn(), - openCustomSendDialog: vi.fn(), - openMetadataRefreshDialog: vi.fn(), - openFileMoverDialog: vi.fn(), + openShelfAssignerDialog: vi.fn(() => Promise.resolve(null)), + openBookDetailsDialog: vi.fn(() => Promise.resolve(null)), + openCustomSendDialog: vi.fn(() => Promise.resolve(null)), + openMetadataRefreshDialog: vi.fn(() => Promise.resolve(null)), + openFileMoverDialog: vi.fn(() => Promise.resolve(null)), }; bookNavigationService = { availableBookIds: vi.fn(() => []), diff --git a/frontend/src/app/features/book/components/book-browser/book-card/book-card.component.ts b/frontend/src/app/features/book/components/book-browser/book-card/book-card.component.ts index 264a9892e..cb5419bd8 100644 --- a/frontend/src/app/features/book/components/book-browser/book-card/book-card.component.ts +++ b/frontend/src/app/features/book/components/book-browser/book-card/book-card.component.ts @@ -419,7 +419,7 @@ export class BookCardComponent { { label: this.t.translate('book.card.menu.customSend'), icon: 'pi pi-envelope', - command: () => this.bookDialogHelperService.openCustomSendDialog(this.book()) + command: () => void this.bookDialogHelperService.openCustomSendDialog(this.book()).catch(() => undefined) } ] }); @@ -452,7 +452,7 @@ export class BookCardComponent { { label: this.t.translate('book.card.menu.customFetch'), icon: 'pi pi-sync', - command: () => this.bookDialogHelperService.openMetadataRefreshDialog(new Set([this.book().id])), + command: () => void this.bookDialogHelperService.openMetadataRefreshDialog(new Set([this.book().id])).catch(() => undefined), }, { label: this.t.translate('book.card.menu.regenerateCover'), @@ -505,7 +505,7 @@ export class BookCardComponent { moreActions.push({ label: this.t.translate('book.card.menu.organizeFile'), icon: 'pi pi-arrows-h', - command: () => this.bookDialogHelperService.openFileMoverDialog(new Set([this.book().id])) + command: () => void this.bookDialogHelperService.openFileMoverDialog(new Set([this.book().id])).catch(() => undefined) }); } @@ -597,7 +597,7 @@ export class BookCardComponent { } private openShelfDialog(): void { - this.bookDialogHelperService.openShelfAssignerDialog(this.book(), null); + void this.bookDialogHelperService.openShelfAssignerDialog(this.book(), null).catch(() => undefined); } openSeriesInfo(): void { @@ -610,7 +610,7 @@ export class BookCardComponent { } } - openBookInfo(book: Book): void { + async openBookInfo(book: Book) { const allBookIds = this.bookNavigationService.availableBookIds(); if (allBookIds.length > 0) { this.bookNavigationService.setNavigationContext(allBookIds, book.id); @@ -621,7 +621,7 @@ export class BookCardComponent { queryParams: {tab: 'view'} }); } else { - this.bookDialogHelperService.openBookDetailsDialog(book.id); + await this.bookDialogHelperService.openBookDetailsDialog(book.id).catch(() => undefined); } } diff --git a/frontend/src/app/features/book/components/book-browser/book-dialog-helper.service.spec.ts b/frontend/src/app/features/book/components/book-browser/book-dialog-helper.service.spec.ts index 93bc7f2cd..c984d1f61 100644 --- a/frontend/src/app/features/book/components/book-browser/book-dialog-helper.service.spec.ts +++ b/frontend/src/app/features/book/components/book-browser/book-dialog-helper.service.spec.ts @@ -6,11 +6,15 @@ import {BookDialogHelperService} from './book-dialog-helper.service'; describe('BookDialogHelperService', () => { let service: BookDialogHelperService; - let dialogLauncherService: {openDialog: ReturnType}; + let dialogLauncherService: { + openDialog: ReturnType, + launchLazyDialog: ReturnType + }; beforeEach(() => { dialogLauncherService = { - openDialog: vi.fn(() => ({id: 'dialog-ref'})), + openDialog: vi.fn().mockResolvedValue({id: 'dialog-ref'}), + launchLazyDialog: vi.fn((fn) => fn()), }; TestBed.configureTestingModule({ @@ -27,8 +31,8 @@ describe('BookDialogHelperService', () => { TestBed.resetTestingModule(); }); - it('opens the book details dialog with the expected payload', () => { - const dialogRef = service.openBookDetailsDialog(42); + it('opens the book details dialog with the expected payload', async () => { + const dialogRef = await service.openBookDetailsDialog(42); expect(dialogLauncherService.openDialog).toHaveBeenCalledWith( expect.any(Function), @@ -40,17 +44,17 @@ describe('BookDialogHelperService', () => { expect(dialogRef).toEqual({id: 'dialog-ref'}); }); - it('returns null instead of opening the shelf assigner when no inputs are provided', () => { - const dialogRef = service.openShelfAssignerDialog(null, null); + it('returns null instead of opening the shelf assigner when no inputs are provided', async () => { + const dialogRef = await service.openShelfAssignerDialog(null, null); expect(dialogRef).toBeNull(); expect(dialogLauncherService.openDialog).not.toHaveBeenCalled(); }); - it('opens the bulk file attacher with the provided source books', () => { + it('opens the bulk file attacher with the provided source books', async () => { const sourceBooks = [{id: 1}, {id: 2}] as never[]; - service.openBulkBookFileAttacherDialog(sourceBooks); + await service.openBulkBookFileAttacherDialog(sourceBooks); expect(dialogLauncherService.openDialog).toHaveBeenCalledWith( expect.any(Function), diff --git a/frontend/src/app/features/book/components/book-browser/book-dialog-helper.service.ts b/frontend/src/app/features/book/components/book-browser/book-dialog-helper.service.ts index cb78ee73c..9cce35744 100644 --- a/frontend/src/app/features/book/components/book-browser/book-dialog-helper.service.ts +++ b/frontend/src/app/features/book/components/book-browser/book-dialog-helper.service.ts @@ -1,23 +1,8 @@ import {inject, Injectable} from '@angular/core'; import {DynamicDialogRef} from 'primeng/dynamicdialog'; import {DialogLauncherService, DialogSize, DialogStyle} from '../../../../shared/services/dialog-launcher.service'; -import {ShelfAssignerComponent} from '../shelf-assigner/shelf-assigner.component'; -import {LockUnlockMetadataDialogComponent} from './lock-unlock-metadata-dialog/lock-unlock-metadata-dialog.component'; import {MetadataRefreshType} from '../../../metadata/model/request/metadata-refresh-type.enum'; -import {BulkMetadataUpdateComponent} from '../../../metadata/component/bulk-metadata-update/bulk-metadata-update-component'; -import {MultiBookMetadataEditorComponent} from '../../../metadata/component/multi-book-metadata-editor/multi-book-metadata-editor-component'; -import {MultiBookMetadataFetchComponent} from '../../../metadata/component/multi-book-metadata-fetch/multi-book-metadata-fetch-component'; -import {FileMoverComponent} from '../../../../shared/components/file-mover/file-mover-component'; -import {ShelfCreatorComponent} from '../shelf-creator/shelf-creator.component'; -import {BookSenderComponent} from '../book-sender/book-sender.component'; -import {BookMetadataCenterComponent} from '../../../metadata/component/book-metadata-center/book-metadata-center.component'; -import {CoverSearchComponent} from '../../../metadata/component/cover-search/cover-search.component'; import {Book} from '../../model/book.model'; -import {AdditionalFileUploaderComponent} from '../additional-file-uploader/additional-file-uploader.component'; -import {BookFileAttacherComponent} from '../book-file-attacher/book-file-attacher.component'; -import {AddPhysicalBookDialogComponent} from '../add-physical-book-dialog/add-physical-book-dialog.component'; -import {BulkIsbnImportDialogComponent} from '../bulk-isbn-import-dialog/bulk-isbn-import-dialog.component'; -import {DuplicateMergerComponent} from '../duplicate-merger/duplicate-merger.component'; interface MetadataRefreshDialogContext { metadataRefreshType: MetadataRefreshType; @@ -34,180 +19,228 @@ export class BookDialogHelperService { return this.dialogLauncherService.openDialog(component, options); } - openBookDetailsDialog(bookId: number): DynamicDialogRef | null { - return this.openDialog(BookMetadataCenterComponent, { - showHeader: false, - styleClass: `book-details-dialog ${DialogSize.FULL} ${DialogStyle.MINIMAL}`, - data: { - bookId: bookId, - }, + async openBookDetailsDialog(bookId: number): Promise { + return this.dialogLauncherService.launchLazyDialog(async () => { + const {BookMetadataCenterComponent} = await import('../../../metadata/component/book-metadata-center/book-metadata-center.component'); + return this.openDialog(BookMetadataCenterComponent, { + showHeader: false, + styleClass: `book-details-dialog ${DialogSize.FULL} ${DialogStyle.MINIMAL}`, + data: { + bookId: bookId, + }, + }); }); } - openShelfAssignerDialog(book: Book | null, bookIds: Set | null): DynamicDialogRef | null { - const data: { isMultiBooks: boolean; book?: Book; bookIds?: Set } = { - isMultiBooks: false - }; - if (book !== null) { - data.book = book; - } else if (bookIds !== null) { - data.isMultiBooks = true; - data.bookIds = bookIds; - } else { - return null; - } - return this.openDialog(ShelfAssignerComponent, { - showHeader: false, - data: data, - styleClass: `${DialogSize.SM} ${DialogStyle.MINIMAL}`, + async openShelfAssignerDialog(book: Book | null, bookIds: Set | null): Promise { + return this.dialogLauncherService.launchLazyDialog(async () => { + const data: { isMultiBooks: boolean; book?: Book; bookIds?: Set } = { + isMultiBooks: false + }; + if (book !== null) { + data.book = book; + } else if (bookIds !== null) { + data.isMultiBooks = true; + data.bookIds = bookIds; + } else { + return null; + } + const {ShelfAssignerComponent} = await import('../shelf-assigner/shelf-assigner.component'); + return this.openDialog(ShelfAssignerComponent, { + showHeader: false, + data: data, + styleClass: `${DialogSize.SM} ${DialogStyle.MINIMAL}`, + }); }); } - openShelfCreatorDialog(): DynamicDialogRef { - return this.openDialog(ShelfCreatorComponent, { - showHeader: false, - styleClass: `${DialogSize.MD} ${DialogStyle.MINIMAL}`, - })!; - } - - openLockUnlockMetadataDialog(bookIds: Set): DynamicDialogRef | null { - return this.openDialog(LockUnlockMetadataDialogComponent, { - showHeader: false, - styleClass: `${DialogSize.LG} ${DialogStyle.MINIMAL}`, - data: { - bookIds: Array.from(bookIds), - }, + async openShelfCreatorDialog(): Promise { + return this.dialogLauncherService.launchLazyDialog(async () => { + const {ShelfCreatorComponent} = await import('../shelf-creator/shelf-creator.component'); + return this.openDialog(ShelfCreatorComponent, { + showHeader: false, + styleClass: `${DialogSize.MD} ${DialogStyle.MINIMAL}`, + }); }); } - openMetadataRefreshDialog(bookIds: Set): DynamicDialogRef | null { + async openLockUnlockMetadataDialog(bookIds: Set): Promise { + return this.dialogLauncherService.launchLazyDialog(async () => { + const {LockUnlockMetadataDialogComponent} = await import('./lock-unlock-metadata-dialog/lock-unlock-metadata-dialog.component'); + return this.openDialog(LockUnlockMetadataDialogComponent, { + showHeader: false, + styleClass: `${DialogSize.LG} ${DialogStyle.MINIMAL}`, + data: { + bookIds: Array.from(bookIds), + }, + }); + }); + } + + async openMetadataRefreshDialog(bookIds: Set): Promise { return this.openMetadataRefreshDialogWithContext({ metadataRefreshType: MetadataRefreshType.BOOKS, bookIds: Array.from(bookIds) }); } - openMetadataRefreshDialogWithContext(context: MetadataRefreshDialogContext): DynamicDialogRef | null { - return this.openDialog(MultiBookMetadataFetchComponent, { - showHeader: false, - styleClass: `${DialogSize.FULL} ${DialogStyle.MINIMAL}`, - data: { - bookIds: context.bookIds ?? [], - libraryId: context.libraryId, - metadataRefreshType: context.metadataRefreshType, - }, + async openMetadataRefreshDialogWithContext(context: MetadataRefreshDialogContext): Promise { + return this.dialogLauncherService.launchLazyDialog(async () => { + const {MultiBookMetadataFetchComponent} = await import('../../../metadata/component/multi-book-metadata-fetch/multi-book-metadata-fetch-component'); + return this.openDialog(MultiBookMetadataFetchComponent, { + showHeader: false, + styleClass: `${DialogSize.FULL} ${DialogStyle.MINIMAL}`, + data: { + bookIds: context.bookIds ?? [], + libraryId: context.libraryId, + metadataRefreshType: context.metadataRefreshType, + }, + }); }); } - openBulkMetadataEditDialog(bookIds: Set): DynamicDialogRef | null { - return this.openDialog(BulkMetadataUpdateComponent, { - showHeader: false, - styleClass: `${DialogSize.XL} ${DialogStyle.MINIMAL}`, - data: { - bookIds: Array.from(bookIds), - }, + async openBulkMetadataEditDialog(bookIds: Set): Promise { + return this.dialogLauncherService.launchLazyDialog(async () => { + const {BulkMetadataUpdateComponent} = await import('../../../metadata/component/bulk-metadata-update/bulk-metadata-update-component'); + return this.openDialog(BulkMetadataUpdateComponent, { + showHeader: false, + styleClass: `${DialogSize.XL} ${DialogStyle.MINIMAL}`, + data: { + bookIds: Array.from(bookIds), + }, + }); }); } - openMultibookMetadataEditorDialog(bookIds: Set): DynamicDialogRef | null { - return this.openDialog(MultiBookMetadataEditorComponent, { - showHeader: false, - styleClass: `${DialogSize.FULL} ${DialogStyle.MINIMAL}`, - data: { - bookIds: Array.from(bookIds), - }, + async openMultibookMetadataEditorDialog(bookIds: Set): Promise { + return this.dialogLauncherService.launchLazyDialog(async () => { + const {MultiBookMetadataEditorComponent} = await import('../../../metadata/component/multi-book-metadata-editor/multi-book-metadata-editor-component'); + return this.openDialog(MultiBookMetadataEditorComponent, { + showHeader: false, + styleClass: `${DialogSize.FULL} ${DialogStyle.MINIMAL}`, + data: { + bookIds: Array.from(bookIds), + }, + }); }); } - openFileMoverDialog(bookIds: Set): DynamicDialogRef | null { - return this.openDialog(FileMoverComponent, { - showHeader: false, - styleClass: `${DialogSize.FULL} ${DialogStyle.MINIMAL}`, - maximizable: true, - data: { - bookIds: Array.from(bookIds), - }, + async openFileMoverDialog(bookIds: Set): Promise { + return this.dialogLauncherService.launchLazyDialog(async () => { + const {FileMoverComponent} = await import('../../../../shared/components/file-mover/file-mover-component'); + return this.openDialog(FileMoverComponent, { + showHeader: false, + styleClass: `${DialogSize.FULL} ${DialogStyle.MINIMAL}`, + maximizable: true, + data: { + bookIds: Array.from(bookIds), + }, + }); }); } - openCustomSendDialog(book: Book): DynamicDialogRef | null { - return this.openDialog(BookSenderComponent, { - showHeader: false, - styleClass: `${DialogSize.SM} ${DialogStyle.MINIMAL}`, - data: { - book: book, - }, + async openCustomSendDialog(book: Book): Promise { + return this.dialogLauncherService.launchLazyDialog(async () => { + const {BookSenderComponent} = await import('../book-sender/book-sender.component'); + return this.openDialog(BookSenderComponent, { + showHeader: false, + styleClass: `${DialogSize.SM} ${DialogStyle.MINIMAL}`, + data: { + book: book, + }, + }); }); } - openCoverSearchDialog(bookId: number, coverType?: 'ebook' | 'audiobook'): DynamicDialogRef | null { - return this.openDialog(CoverSearchComponent, { - showHeader: false, - styleClass: `${DialogSize.FULL} ${DialogStyle.MINIMAL}`, - data: { - bookId: bookId, - coverType: coverType, - }, + async openCoverSearchDialog(bookId: number, coverType?: 'ebook' | 'audiobook'): Promise { + return this.dialogLauncherService.launchLazyDialog(async () => { + const {CoverSearchComponent} = await import('../../../metadata/component/cover-search/cover-search.component'); + return this.openDialog(CoverSearchComponent, { + showHeader: false, + styleClass: `${DialogSize.FULL} ${DialogStyle.MINIMAL}`, + data: { + bookId: bookId, + coverType: coverType, + }, + }); }); } - openAdditionalFileUploaderDialog(book: Book): DynamicDialogRef | null { - return this.openDialog(AdditionalFileUploaderComponent, { - showHeader: false, - styleClass: `${DialogSize.MD} ${DialogStyle.MINIMAL}`, - data: { - book: book, - }, + async openAdditionalFileUploaderDialog(book: Book): Promise { + return this.dialogLauncherService.launchLazyDialog(async () => { + const {AdditionalFileUploaderComponent} = await import('../additional-file-uploader/additional-file-uploader.component'); + return this.openDialog(AdditionalFileUploaderComponent, { + showHeader: false, + styleClass: `${DialogSize.MD} ${DialogStyle.MINIMAL}`, + data: { + book: book, + }, + }); }); } - openBookFileAttacherDialog(sourceBook: Book): DynamicDialogRef | null { - return this.openDialog(BookFileAttacherComponent, { - showHeader: false, - styleClass: `${DialogSize.MD} ${DialogStyle.MINIMAL}`, - data: { - sourceBook: sourceBook, - }, + async openBookFileAttacherDialog(sourceBook: Book): Promise { + return this.dialogLauncherService.launchLazyDialog(async () => { + const {BookFileAttacherComponent} = await import('../book-file-attacher/book-file-attacher.component'); + return this.openDialog(BookFileAttacherComponent, { + showHeader: false, + styleClass: `${DialogSize.MD} ${DialogStyle.MINIMAL}`, + data: { + sourceBook: sourceBook, + }, + }); }); } - openBulkBookFileAttacherDialog(sourceBooks: Book[]): DynamicDialogRef | null { - return this.openDialog(BookFileAttacherComponent, { - showHeader: false, - styleClass: `${DialogSize.MD} ${DialogStyle.MINIMAL}`, - data: { - sourceBooks: sourceBooks, - }, + async openBulkBookFileAttacherDialog(sourceBooks: Book[]): Promise { + return this.dialogLauncherService.launchLazyDialog(async () => { + const {BookFileAttacherComponent} = await import('../book-file-attacher/book-file-attacher.component'); + return this.openDialog(BookFileAttacherComponent, { + showHeader: false, + styleClass: `${DialogSize.MD} ${DialogStyle.MINIMAL}`, + data: { + sourceBooks: sourceBooks, + }, + }); }); } - openDuplicateMergerDialog(libraryId: number): DynamicDialogRef | null { - return this.openDialog(DuplicateMergerComponent, { - showHeader: false, - styleClass: `${DialogSize.XL} ${DialogStyle.MINIMAL}`, - data: { - libraryId: libraryId, - }, + async openDuplicateMergerDialog(libraryId: number): Promise { + return this.dialogLauncherService.launchLazyDialog(async () => { + const {DuplicateMergerComponent} = await import('../duplicate-merger/duplicate-merger.component'); + return this.openDialog(DuplicateMergerComponent, { + showHeader: false, + styleClass: `${DialogSize.XL} ${DialogStyle.MINIMAL}`, + data: { + libraryId: libraryId, + }, + }); }); } - openAddPhysicalBookDialog(libraryId?: number): DynamicDialogRef | null { - return this.openDialog(AddPhysicalBookDialogComponent, { - showHeader: false, - styleClass: `${DialogSize.LG} ${DialogStyle.MINIMAL}`, - data: { - libraryId: libraryId, - }, + async openAddPhysicalBookDialog(libraryId?: number): Promise { + return this.dialogLauncherService.launchLazyDialog(async () => { + const {AddPhysicalBookDialogComponent} = await import('../add-physical-book-dialog/add-physical-book-dialog.component'); + return this.openDialog(AddPhysicalBookDialogComponent, { + showHeader: false, + styleClass: `${DialogSize.LG} ${DialogStyle.MINIMAL}`, + data: { + libraryId: libraryId, + }, + }); }); } - openBulkIsbnImportDialog(libraryId?: number): DynamicDialogRef | null { - return this.openDialog(BulkIsbnImportDialogComponent, { - showHeader: false, - styleClass: `${DialogSize.LG} ${DialogStyle.MINIMAL}`, - data: { - libraryId: libraryId, - }, + async openBulkIsbnImportDialog(libraryId?: number): Promise { + return this.dialogLauncherService.launchLazyDialog(async () => { + const {BulkIsbnImportDialogComponent} = await import('../bulk-isbn-import-dialog/bulk-isbn-import-dialog.component'); + return this.openDialog(BulkIsbnImportDialogComponent, { + showHeader: false, + styleClass: `${DialogSize.LG} ${DialogStyle.MINIMAL}`, + data: { + libraryId: libraryId, + }, + }); }); } } diff --git a/frontend/src/app/features/book/components/series-page/series-page.component.ts b/frontend/src/app/features/book/components/series-page/series-page.component.ts index 2c78087ee..dc3277743 100644 --- a/frontend/src/app/features/book/components/series-page/series-page.component.ts +++ b/frontend/src/app/features/book/components/series-page/series-page.component.ts @@ -684,8 +684,8 @@ export class SeriesPageComponent implements AfterViewChecked { }); } - openShelfAssigner(): void { - this.dialogRef = this.dialogHelperService.openShelfAssignerDialog(null, this.selectedBooks()); + async openShelfAssigner() { + this.dialogRef = await this.dialogHelperService.openShelfAssignerDialog(null, this.selectedBooks()); if (this.dialogRef) { this.dialogRef.onClose.pipe(take(1)).subscribe(result => { if (result?.assigned) { @@ -695,8 +695,8 @@ export class SeriesPageComponent implements AfterViewChecked { } } - lockUnlockMetadata(): void { - this.dialogRef = this.dialogHelperService.openLockUnlockMetadataDialog(this.selectedBooks()); + async lockUnlockMetadata() { + this.dialogRef = await this.dialogHelperService.openLockUnlockMetadataDialog(this.selectedBooks()); if (this.dialogRef) { this.dialogRef.onClose.pipe(take(1)).subscribe(() => { this.deselectAllBooks(); @@ -713,12 +713,12 @@ export class SeriesPageComponent implements AfterViewChecked { }).subscribe(); } - fetchMetadata(): void { - this.dialogHelperService.openMetadataRefreshDialog(this.selectedBooks()); + async fetchMetadata() { + await this.dialogHelperService.openMetadataRefreshDialog(this.selectedBooks()); } - bulkEditMetadata(): void { - this.dialogRef = this.dialogHelperService.openBulkMetadataEditDialog(this.selectedBooks()); + async bulkEditMetadata() { + this.dialogRef = await this.dialogHelperService.openBulkMetadataEditDialog(this.selectedBooks()); if (this.dialogRef) { this.dialogRef.onClose.pipe(take(1)).subscribe(() => { this.deselectAllBooks(); @@ -726,8 +726,8 @@ export class SeriesPageComponent implements AfterViewChecked { } } - multiBookEditMetadata(): void { - this.dialogRef = this.dialogHelperService.openMultibookMetadataEditorDialog(this.selectedBooks()); + async multiBookEditMetadata() { + this.dialogRef = await this.dialogHelperService.openMultibookMetadataEditorDialog(this.selectedBooks()); if (this.dialogRef) { this.dialogRef.onClose.pipe(take(1)).subscribe(() => { this.deselectAllBooks(); @@ -817,8 +817,8 @@ export class SeriesPageComponent implements AfterViewChecked { }); } - moveFiles() { - this.dialogHelperService.openFileMoverDialog(this.selectedBooks()); + async moveFiles() { + await this.dialogHelperService.openFileMoverDialog(this.selectedBooks()); } user() { diff --git a/frontend/src/app/features/book/service/library-shelf-menu.service.spec.ts b/frontend/src/app/features/book/service/library-shelf-menu.service.spec.ts index e5d9de490..71b876081 100644 --- a/frontend/src/app/features/book/service/library-shelf-menu.service.spec.ts +++ b/frontend/src/app/features/book/service/library-shelf-menu.service.spec.ts @@ -87,9 +87,9 @@ describe('LibraryShelfMenuService', () => { navigate: vi.fn(), }; const dialogLauncherService = { - openLibraryEditDialog: vi.fn(), - openShelfEditDialog: vi.fn(), - openMagicShelfEditDialog: vi.fn(), + openLibraryEditDialog: vi.fn(() => Promise.resolve(null)), + openShelfEditDialog: vi.fn(() => Promise.resolve(null)), + openMagicShelfEditDialog: vi.fn(() => Promise.resolve(null)), }; const magicShelfService = { deleteShelf: vi.fn(() => of(undefined)), @@ -99,10 +99,10 @@ describe('LibraryShelfMenuService', () => { hide: vi.fn(), }; const bookDialogHelperService = { - openAddPhysicalBookDialog: vi.fn(), - openBulkIsbnImportDialog: vi.fn(), - openDuplicateMergerDialog: vi.fn(), - openMetadataRefreshDialogWithContext: vi.fn(), + openAddPhysicalBookDialog: vi.fn(() => Promise.resolve(null)), + openBulkIsbnImportDialog: vi.fn(() => Promise.resolve(null)), + openDuplicateMergerDialog: vi.fn(() => Promise.resolve(null)), + openMetadataRefreshDialogWithContext: vi.fn(() => Promise.resolve(null)), }; const translocoService = { translate: vi.fn((key: string) => key), diff --git a/frontend/src/app/features/book/service/library-shelf-menu.service.ts b/frontend/src/app/features/book/service/library-shelf-menu.service.ts index eeb5c9ca1..77c7c5576 100644 --- a/frontend/src/app/features/book/service/library-shelf-menu.service.ts +++ b/frontend/src/app/features/book/service/library-shelf-menu.service.ts @@ -45,22 +45,22 @@ export class LibraryShelfMenuService { label: this.t.translate('book.shelfMenuService.library.addPhysicalBook'), icon: 'pi pi-book', disabled: libraryId == null, - command: () => { + command: async () => { if (libraryId == null) { return; } - this.bookDialogHelperService.openAddPhysicalBookDialog(libraryId); + await this.bookDialogHelperService.openAddPhysicalBookDialog(libraryId).catch(() => undefined); } }, { label: this.t.translate('book.shelfMenuService.library.bulkIsbnImport'), icon: 'pi pi-barcode', disabled: libraryId == null, - command: () => { + command: async () => { if (libraryId == null) { return; } - this.bookDialogHelperService.openBulkIsbnImportDialog(libraryId); + await this.bookDialogHelperService.openBulkIsbnImportDialog(libraryId).catch(() => undefined); } }, { @@ -74,7 +74,7 @@ export class LibraryShelfMenuService { if (libraryId == null) { return; } - this.dialogLauncherService.openLibraryEditDialog(libraryId); + void this.dialogLauncherService.openLibraryEditDialog(libraryId).catch(() => undefined); } }, { @@ -124,14 +124,14 @@ export class LibraryShelfMenuService { label: this.t.translate('book.shelfMenuService.library.customFetchMetadata'), icon: 'pi pi-sync', disabled: libraryId == null, - command: () => { + command: async () => { if (libraryId == null) { return; } - this.bookDialogHelperService.openMetadataRefreshDialogWithContext({ + await this.bookDialogHelperService.openMetadataRefreshDialogWithContext({ metadataRefreshType: MetadataRefreshType.LIBRARY, libraryId - }); + }).catch(() => undefined); } }, { @@ -152,11 +152,11 @@ export class LibraryShelfMenuService { label: this.t.translate('book.shelfMenuService.library.findDuplicates'), icon: 'pi pi-copy', disabled: libraryId == null, - command: () => { + command: async () => { if (libraryId == null) { return; } - this.bookDialogHelperService.openDuplicateMergerDialog(libraryId); + await this.bookDialogHelperService.openDuplicateMergerDialog(libraryId).catch(() => undefined); } }, { @@ -227,7 +227,7 @@ export class LibraryShelfMenuService { return; } - this.dialogLauncherService.openShelfEditDialog(shelfId); + void this.dialogLauncherService.openShelfEditDialog(shelfId).catch(() => undefined); } }, { @@ -303,7 +303,7 @@ export class LibraryShelfMenuService { return; } - this.dialogLauncherService.openMagicShelfEditDialog(magicShelfId); + void this.dialogLauncherService.openMagicShelfEditDialog(magicShelfId).catch(() => undefined); } }, { diff --git a/frontend/src/app/features/bookdrop/component/bookdrop-file-review/bookdrop-file-review.component.spec.ts b/frontend/src/app/features/bookdrop/component/bookdrop-file-review/bookdrop-file-review.component.spec.ts index a30bbe938..dc81c1709 100644 --- a/frontend/src/app/features/bookdrop/component/bookdrop-file-review/bookdrop-file-review.component.spec.ts +++ b/frontend/src/app/features/bookdrop/component/bookdrop-file-review/bookdrop-file-review.component.spec.ts @@ -23,9 +23,9 @@ describe('BookdropFileReviewComponent', () => { const discardFiles = vi.fn(); const finalizeImport = vi.fn(); const rescan = vi.fn(); - const openBookdropFinalizeResultDialog = vi.fn(); - const openDialog = vi.fn(); - const openDirectoryPickerDialog = vi.fn(); + const openBookdropFinalizeResultDialog = vi.fn(() => Promise.resolve(null)); + const openDialog = vi.fn(() => Promise.resolve(null)); + const openDirectoryPickerDialog = vi.fn(() => Promise.resolve(null)); const setPageTitle = vi.fn(); const translate = vi.fn((key: string, params?: Record) => { if (!params) { diff --git a/frontend/src/app/features/command-palette/command-palette.service.spec.ts b/frontend/src/app/features/command-palette/command-palette.service.spec.ts index 007ec4177..8b40ac400 100644 --- a/frontend/src/app/features/command-palette/command-palette.service.spec.ts +++ b/frontend/src/app/features/command-palette/command-palette.service.spec.ts @@ -4,6 +4,7 @@ import { Router } from '@angular/router'; import { of } from 'rxjs'; import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; +import { MessageService } from 'primeng/api'; import { getTranslocoModule } from '../../core/testing/transloco-testing'; import { BookDialogHelperService } from '../book/components/book-browser/book-dialog-helper.service'; import { Book } from '../book/model/book.model'; @@ -65,20 +66,21 @@ describe('CommandPaletteService', () => { { provide: MagicShelfService, useValue: { shelves: signal([]) } }, { provide: LibraryService, useValue: { libraries: signal([]) } }, { provide: UserService, useValue: { currentUser: signal({ permissions: {} }) } }, + { provide: MessageService, useValue: { add: vi.fn() } }, { provide: UrlHelperService, useValue: urlHelper }, { provide: IconService, useValue: { getSvgIconContent: vi.fn(() => of('')) } }, { provide: DialogLauncherService, useValue: { - openLibraryCreateDialog: vi.fn(), - openMagicShelfCreateDialog: vi.fn(), - openFileUploadDialog: vi.fn(), + openLibraryCreateDialog: vi.fn(() => Promise.resolve(null)), + openMagicShelfCreateDialog: vi.fn(() => Promise.resolve(null)), + openFileUploadDialog: vi.fn(() => Promise.resolve(null)), }, }, { provide: BookDialogHelperService, useValue: { - openShelfCreatorDialog: vi.fn(), + openShelfCreatorDialog: vi.fn(() => Promise.resolve(null)), }, }, ], diff --git a/frontend/src/app/features/command-palette/command-palette.service.ts b/frontend/src/app/features/command-palette/command-palette.service.ts index c4c9a1966..03f59a2f4 100644 --- a/frontend/src/app/features/command-palette/command-palette.service.ts +++ b/frontend/src/app/features/command-palette/command-palette.service.ts @@ -1,4 +1,5 @@ import { computed, inject, Injectable, signal } from '@angular/core'; +import { MessageService } from 'primeng/api'; import { toObservable, toSignal } from '@angular/core/rxjs-interop'; import { Router } from '@angular/router'; import { TranslocoService } from '@jsverse/transloco'; @@ -50,6 +51,7 @@ export class CommandPaletteService { private readonly bookDialogHelperService = inject(BookDialogHelperService); private readonly iconService = inject(IconService); private readonly urlHelper = inject(UrlHelperService); + private readonly messageService = inject(MessageService); private readonly _isOpen = signal(false); readonly isOpen = this._isOpen.asReadonly(); @@ -131,7 +133,7 @@ export class CommandPaletteService { this.hide(); queueMicrotask(() => { if (item.command) { - item.command(); + void Promise.resolve(item.command()).catch(() => undefined); return; } if (item.route) { @@ -211,10 +213,10 @@ export class CommandPaletteService { const user = this.userService.currentUser(); if (!user) return []; return buildQuickActionNavItems(this.translate, user.permissions, { - createLibrary: () => this.dialogLauncherService.openLibraryCreateDialog(), - createShelf: () => this.bookDialogHelperService.openShelfCreatorDialog(), - createMagicShelf: () => this.dialogLauncherService.openMagicShelfCreateDialog(), - uploadBook: () => this.dialogLauncherService.openFileUploadDialog(), + createLibrary: () => void this.dialogLauncherService.openLibraryCreateDialog().catch(() => undefined), + createShelf: () => void this.bookDialogHelperService.openShelfCreatorDialog().catch(() => undefined), + createMagicShelf: () => void this.dialogLauncherService.openMagicShelfCreateDialog().catch(() => undefined), + uploadBook: () => void this.dialogLauncherService.openFileUploadDialog().catch(() => undefined), }).map((item) => this.toPaletteNavItem(item, 'action')); }); @@ -320,5 +322,4 @@ export class CommandPaletteService { command: item.action, }; } - } diff --git a/frontend/src/app/features/dashboard/components/main-dashboard/main-dashboard.component.ts b/frontend/src/app/features/dashboard/components/main-dashboard/main-dashboard.component.ts index fc3e227e1..925294e12 100644 --- a/frontend/src/app/features/dashboard/components/main-dashboard/main-dashboard.component.ts +++ b/frontend/src/app/features/dashboard/components/main-dashboard/main-dashboard.component.ts @@ -62,10 +62,10 @@ export class MainDashboardComponent { } openDashboardSettings(): void { - this.dialogLauncher.openDashboardSettingsDialog(); + void this.dialogLauncher.openDashboardSettingsDialog().catch(() => undefined); } createNewLibrary() { - this.dialogLauncher.openLibraryCreateDialog(); + void this.dialogLauncher.openLibraryCreateDialog().catch(() => undefined); } } diff --git a/frontend/src/app/features/library-creator/library-creator.component.ts b/frontend/src/app/features/library-creator/library-creator.component.ts index 34a835e20..d826a280c 100644 --- a/frontend/src/app/features/library-creator/library-creator.component.ts +++ b/frontend/src/app/features/library-creator/library-creator.component.ts @@ -215,8 +215,8 @@ export class LibraryCreatorComponent { return this.allBookFormats.some(f => this.getFormatWarning(f.type) !== null); } - openDirectoryPicker(): void { - const ref = this.dialogLauncherService.openDirectoryPickerDialog(); + async openDirectoryPicker(): Promise { + const ref = await this.dialogLauncherService.openDirectoryPickerDialog().catch(() => null); ref?.onClose.subscribe((selectedFolders: string[] | null) => { if (selectedFolders && selectedFolders.length > 0) { this.folders.update(current => { diff --git a/frontend/src/app/features/metadata/component/book-metadata-center/metadata-editor/metadata-editor.component.ts b/frontend/src/app/features/metadata/component/book-metadata-center/metadata-editor/metadata-editor.component.ts index a84086241..502a055b0 100644 --- a/frontend/src/app/features/metadata/component/book-metadata-center/metadata-editor/metadata-editor.component.ts +++ b/frontend/src/app/features/metadata/component/book-metadata-center/metadata-editor/metadata-editor.component.ts @@ -1114,8 +1114,8 @@ export class MetadataEditorComponent implements OnInit { this.closeDialogButtonClicked.emit(); } - openCoverSearch() { - const ref = this.bookDialogHelperService.openCoverSearchDialog(this.currentBookId, 'ebook'); + async openCoverSearch() { + const ref = await this.bookDialogHelperService.openCoverSearchDialog(this.currentBookId, 'ebook'); ref?.onClose.pipe( take(1), filter(result => !!result), @@ -1204,8 +1204,8 @@ export class MetadataEditorComponent implements OnInit { return this.bookMetadataManageService.getUploadAudiobookCoverUrl(this.currentBookId); } - openAudiobookCoverSearch() { - const ref = this.bookDialogHelperService.openCoverSearchDialog(this.currentBookId, 'audiobook'); + async openAudiobookCoverSearch() { + const ref = await this.bookDialogHelperService.openCoverSearchDialog(this.currentBookId, 'audiobook'); ref?.onClose.pipe( take(1), filter(result => !!result), diff --git a/frontend/src/app/features/metadata/component/book-metadata-center/metadata-viewer/metadata-viewer.component.spec.ts b/frontend/src/app/features/metadata/component/book-metadata-center/metadata-viewer/metadata-viewer.component.spec.ts index f92a89d3f..ac6703fa3 100644 --- a/frontend/src/app/features/metadata/component/book-metadata-center/metadata-viewer/metadata-viewer.component.spec.ts +++ b/frontend/src/app/features/metadata/component/book-metadata-center/metadata-viewer/metadata-viewer.component.spec.ts @@ -67,11 +67,11 @@ describe('MetadataViewerComponent', () => { const deleteBookFile = vi.fn(() => of(void 0)); const detachBookFile = vi.fn(() => of(void 0)); - const openAdditionalFileUploaderDialog = vi.fn(); - const openCustomSendDialog = vi.fn(); - const openBookFileAttacherDialog = vi.fn(); - const openFileMoverDialog = vi.fn(); - const openShelfAssignerDialog = vi.fn(); + const openAdditionalFileUploaderDialog = vi.fn(() => Promise.resolve(null)); + const openCustomSendDialog = vi.fn(() => Promise.resolve(null)); + const openBookFileAttacherDialog = vi.fn(() => Promise.resolve(null)); + const openFileMoverDialog = vi.fn(() => Promise.resolve(null)); + const openShelfAssignerDialog = vi.fn(() => Promise.resolve(null)); const emailBookQuick = vi.fn(() => of(void 0)); const refreshMetadataTask = vi.fn(() => of(void 0)); diff --git a/frontend/src/app/features/metadata/component/book-metadata-center/metadata-viewer/metadata-viewer.component.ts b/frontend/src/app/features/metadata/component/book-metadata-center/metadata-viewer/metadata-viewer.component.ts index 38d758663..cfc371458 100644 --- a/frontend/src/app/features/metadata/component/book-metadata-center/metadata-viewer/metadata-viewer.component.ts +++ b/frontend/src/app/features/metadata/component/book-metadata-center/metadata-viewer/metadata-viewer.component.ts @@ -214,7 +214,9 @@ export class MetadataViewerComponent implements OnInit, OnChanges, AfterViewChec items.push({ label: this.t.translate('metadata.viewer.menuShelf'), icon: 'pi pi-folder', - command: () => this.assignShelf(book.id) + command: () => { + void this.assignShelf(book).catch(() => undefined); + } }); if (permissions?.canManageLibrary || permissions?.admin) { @@ -235,7 +237,7 @@ export class MetadataViewerComponent implements OnInit, OnChanges, AfterViewChec label: this.t.translate('metadata.viewer.menuUploadFile'), icon: 'pi pi-upload', command: () => { - this.bookDialogHelperService.openAdditionalFileUploaderDialog(book); + void this.bookDialogHelperService.openAdditionalFileUploaderDialog(book).catch(() => undefined); }, }); } @@ -247,7 +249,7 @@ export class MetadataViewerComponent implements OnInit, OnChanges, AfterViewChec label: this.t.translate('metadata.viewer.menuOrganizeFiles'), icon: 'pi pi-arrows-h', command: () => { - this.openFileMoverDialog(book.id); + void this.openFileMoverDialog(book.id).catch(() => undefined); }, }); } @@ -266,7 +268,7 @@ export class MetadataViewerComponent implements OnInit, OnChanges, AfterViewChec label: this.t.translate('metadata.viewer.menuCustomSend'), icon: 'pi pi-cog', command: () => { - this.bookDialogHelperService.openCustomSendDialog(book); + void this.bookDialogHelperService.openCustomSendDialog(book).catch(() => undefined); } } ] @@ -281,7 +283,7 @@ export class MetadataViewerComponent implements OnInit, OnChanges, AfterViewChec label: this.t.translate('metadata.viewer.menuAttachToAnotherBook'), icon: 'pi pi-link', command: () => { - this.bookDialogHelperService.openBookFileAttacherDialog(book); + void this.bookDialogHelperService.openBookFileAttacherDialog(book).catch(() => undefined); }, }); } @@ -687,8 +689,8 @@ export class MetadataViewerComponent implements OnInit, OnChanges, AfterViewChec } } - assignShelf(bookId: number) { - this.bookDialogHelperService.openShelfAssignerDialog((this.bookService.findBookById(bookId) as Book), null); + async assignShelf(book: Book) { + await this.bookDialogHelperService.openShelfAssignerDialog(book, null); } updateReadStatus(status: ReadStatus): void { @@ -1251,8 +1253,8 @@ export class MetadataViewerComponent implements OnInit, OnChanges, AfterViewChec this.editDateFinished = null; } - openFileMoverDialog(bookId: number): void { - this.bookDialogHelperService.openFileMoverDialog(new Set([bookId])); + async openFileMoverDialog(bookId: number) { + await this.bookDialogHelperService.openFileMoverDialog(new Set([bookId])); } protected readonly ResetProgressTypes = ResetProgressTypes; diff --git a/frontend/src/app/features/settings/email-v2/email-v2-provider/email-v2-provider.component.ts b/frontend/src/app/features/settings/email-v2/email-v2-provider/email-v2-provider.component.ts index a635c63cf..a2f459a28 100644 --- a/frontend/src/app/features/settings/email-v2/email-v2-provider/email-v2-provider.component.ts +++ b/frontend/src/app/features/settings/email-v2/email-v2-provider/email-v2-provider.component.ts @@ -153,8 +153,8 @@ export class EmailV2ProviderComponent implements OnInit { } } - openCreateProviderDialog() { - this.ref = this.dialogLauncherService.openEmailProviderDialog(); + async openCreateProviderDialog() { + this.ref = await this.dialogLauncherService.openEmailProviderDialog().catch(() => null); this.ref?.onClose.pipe(takeUntilDestroyed(this.destroyRef)).subscribe((result) => { if (result) { this.loadEmailProviders(); diff --git a/frontend/src/app/features/settings/email-v2/email-v2-recipient/email-v2-recipient.component.ts b/frontend/src/app/features/settings/email-v2/email-v2-recipient/email-v2-recipient.component.ts index a1ada2939..6487f0680 100644 --- a/frontend/src/app/features/settings/email-v2/email-v2-recipient/email-v2-recipient.component.ts +++ b/frontend/src/app/features/settings/email-v2/email-v2-recipient/email-v2-recipient.component.ts @@ -140,8 +140,8 @@ export class EmailV2RecipientComponent implements OnInit { } } - openAddRecipientDialog() { - this.ref = this.dialogLauncherService.openEmailRecipientDialog(); + async openAddRecipientDialog() { + this.ref = await this.dialogLauncherService.openEmailRecipientDialog().catch(() => null); this.ref?.onClose.pipe(takeUntilDestroyed(this.destroyRef)).subscribe((result) => { if (result) { this.loadRecipientEmails(); diff --git a/frontend/src/app/features/settings/user-management/user-management.component.ts b/frontend/src/app/features/settings/user-management/user-management.component.ts index f3cb92931..0f0fb99d0 100644 --- a/frontend/src/app/features/settings/user-management/user-management.component.ts +++ b/frontend/src/app/features/settings/user-management/user-management.component.ts @@ -100,8 +100,8 @@ export class UserManagementComponent implements OnInit { }); } - openCreateUserDialog() { - this.ref = this.dialogLauncherService.openCreateUserDialog(); + async openCreateUserDialog() { + this.ref = await this.dialogLauncherService.openCreateUserDialog().catch(() => null); this.ref?.onClose.pipe(takeUntilDestroyed(this.destroyRef)).subscribe((result) => { if (result) { this.loadUsers(); diff --git a/frontend/src/app/features/stats/component/library-stats/library-stats.component.ts b/frontend/src/app/features/stats/component/library-stats/library-stats.component.ts index a3fa3bbb4..9164c6fce 100644 --- a/frontend/src/app/features/stats/component/library-stats/library-stats.component.ts +++ b/frontend/src/app/features/stats/component/library-stats/library-stats.component.ts @@ -25,6 +25,9 @@ interface ChartConfig { category: string; } +import {provideCharts, withDefaultRegisterables} from 'ng2-charts'; +import ChartDataLabels from 'chartjs-plugin-datalabels'; + @Component({ selector: 'app-library-stats', standalone: true, @@ -44,6 +47,7 @@ interface ChartConfig { ReadingJourneyChartComponent, TranslocoDirective ], + providers: [provideCharts(withDefaultRegisterables(ChartDataLabels))], templateUrl: './library-stats.component.html', styleUrls: ['./library-stats.component.scss'] }) diff --git a/frontend/src/app/features/stats/component/user-stats/user-stats.component.ts b/frontend/src/app/features/stats/component/user-stats/user-stats.component.ts index e593a97d9..678db84e0 100644 --- a/frontend/src/app/features/stats/component/user-stats/user-stats.component.ts +++ b/frontend/src/app/features/stats/component/user-stats/user-stats.component.ts @@ -29,6 +29,9 @@ import {PublicationEraChartComponent} from './charts/publication-era-chart/publi import {SessionArchetypesChartComponent} from './charts/session-archetypes-chart/session-archetypes-chart.component'; import {UserChartConfig, UserChartConfigService} from './service/user-chart-config.service'; +import {provideCharts, withDefaultRegisterables} from 'ng2-charts'; +import ChartDataLabels from 'chartjs-plugin-datalabels'; + @Component({ selector: 'app-user-stats', standalone: true, @@ -61,6 +64,7 @@ import {UserChartConfig, UserChartConfigService} from './service/user-chart-conf SessionArchetypesChartComponent, TranslocoDirective ], + providers: [provideCharts(withDefaultRegisterables(ChartDataLabels))], templateUrl: './user-stats.component.html', styleUrls: ['./user-stats.component.scss'] }) diff --git a/frontend/src/app/shared/components/metadata-progress-widget/metadata-progress-widget-component.spec.ts b/frontend/src/app/shared/components/metadata-progress-widget/metadata-progress-widget-component.spec.ts index 1a50d3663..33d1d0211 100644 --- a/frontend/src/app/shared/components/metadata-progress-widget/metadata-progress-widget-component.spec.ts +++ b/frontend/src/app/shared/components/metadata-progress-widget/metadata-progress-widget-component.spec.ts @@ -48,7 +48,7 @@ describe('MetadataProgressWidgetComponent', () => { cancelTask: vi.fn(() => of({cancelled: true})), }; dialogLauncherService = { - openMetadataReviewDialog: vi.fn(), + openMetadataReviewDialog: vi.fn(() => Promise.resolve(null)), }; messageService = { add: vi.fn(), diff --git a/frontend/src/app/shared/components/metadata-progress-widget/metadata-progress-widget-component.ts b/frontend/src/app/shared/components/metadata-progress-widget/metadata-progress-widget-component.ts index bdbc25d9f..3cba3d433 100644 --- a/frontend/src/app/shared/components/metadata-progress-widget/metadata-progress-widget-component.ts +++ b/frontend/src/app/shared/components/metadata-progress-widget/metadata-progress-widget-component.ts @@ -102,7 +102,7 @@ export class MetadataProgressWidgetComponent implements OnInit, OnDestroy { } reviewTask(taskId: string): void { - this.dialogLauncherService.openMetadataReviewDialog(taskId); + void this.dialogLauncherService.openMetadataReviewDialog(taskId).catch(() => undefined); } cancelTask(taskId: string): void { diff --git a/frontend/src/app/shared/layout/layout-sidebar/app.sidebar.component.spec.ts b/frontend/src/app/shared/layout/layout-sidebar/app.sidebar.component.spec.ts index 9799a313e..024ba0d7d 100644 --- a/frontend/src/app/shared/layout/layout-sidebar/app.sidebar.component.spec.ts +++ b/frontend/src/app/shared/layout/layout-sidebar/app.sidebar.component.spec.ts @@ -2,6 +2,7 @@ import { computed, signal, WritableSignal } from '@angular/core'; import { ComponentFixture, TestBed } from '@angular/core/testing'; import { BehaviorSubject } from 'rxjs'; import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; +import { MessageService } from 'primeng/api'; import { getTranslocoModule } from '../../../core/testing/transloco-testing'; import { BookDialogHelperService } from '../../../features/book/components/book-browser/book-dialog-helper.service'; @@ -104,13 +105,13 @@ describe('AppSidebarComponent', () => { { provide: DialogLauncherService, useValue: { - openLibraryCreateDialog: vi.fn(), - openMagicShelfCreateDialog: vi.fn(), - openFileUploadDialog: vi.fn(), + openLibraryCreateDialog: vi.fn(() => Promise.resolve(null)), + openMagicShelfCreateDialog: vi.fn(() => Promise.resolve(null)), + openFileUploadDialog: vi.fn(() => Promise.resolve(null)), }, }, { provide: CommandPaletteService, useValue: commandPaletteService }, - { provide: BookDialogHelperService, useValue: { openShelfCreatorDialog: vi.fn() } }, + { provide: BookDialogHelperService, useValue: { openShelfCreatorDialog: vi.fn(() => Promise.resolve(null)) } }, { provide: AuthService, useValue: { logout: vi.fn() } }, { provide: MetadataProgressService, useValue: { activeTasks$, progressUpdates$ } }, { provide: BookdropFileService, useValue: { hasPendingFiles$ } }, @@ -120,6 +121,7 @@ describe('AppSidebarComponent', () => { { provide: MagicShelfService, useValue: { shelves: signal([]), bookCountByMagicShelfId: signal(new Map()) } }, { provide: SeriesDataService, useValue: { allSeries: signal([]) } }, { provide: AuthorService, useValue: { allAuthors: signal([]) } }, + { provide: MessageService, useValue: { add: vi.fn() } }, ], }); diff --git a/frontend/src/app/shared/layout/layout-sidebar/app.sidebar.component.ts b/frontend/src/app/shared/layout/layout-sidebar/app.sidebar.component.ts index 69dc36671..cbcbe37f8 100644 --- a/frontend/src/app/shared/layout/layout-sidebar/app.sidebar.component.ts +++ b/frontend/src/app/shared/layout/layout-sidebar/app.sidebar.component.ts @@ -30,6 +30,8 @@ import { AuthService } from '../../service/auth.service'; import { LayoutService } from '../layout.service'; import { TranslocoDirective, TranslocoPipe, TranslocoService } from '@jsverse/transloco'; import { Tooltip } from 'primeng/tooltip'; +import { MessageService } from 'primeng/api'; +import { VersionService } from '../../service/version.service'; import { takeUntilDestroyed, toSignal } from '@angular/core/rxjs-interop'; import { NavItem, SidebarSection } from '../navigation/nav-item.model'; import { buildCreateActionNavItems } from '../navigation/nav-catalog'; @@ -40,7 +42,6 @@ import { buildShelfSection, buildToolsSection, } from './sidebar-sections'; -import { VersionService } from '../../service/version.service'; import { MetadataProgressService } from '../../service/metadata-progress.service'; import { BookdropFileService } from '../../../features/bookdrop/service/bookdrop-file.service'; import { MetadataBatchProgressNotification, MetadataBatchStatus } from '../../model/metadata-batch-progress.model'; @@ -119,7 +120,6 @@ export class AppSidebarComponent { private readonly commandPaletteService = inject(CommandPaletteService); private readonly bookDialogHelperService = inject(BookDialogHelperService); private readonly authService = inject(AuthService); - private readonly router = inject(Router); readonly layoutService = inject(LayoutService); private readonly userService = inject(UserService); private readonly versionService = inject(VersionService); @@ -128,9 +128,11 @@ export class AppSidebarComponent { private readonly authorService = inject(AuthorService); private readonly t = inject(TranslocoService); private readonly renderer = inject(Renderer2); - private readonly destroyRef = inject(DestroyRef); - private readonly metadataProgressService = inject(MetadataProgressService); - private readonly bookdropFileService = inject(BookdropFileService); +private readonly router = inject(Router); +private readonly messageService = inject(MessageService); +private readonly destroyRef = inject(DestroyRef); +private readonly metadataProgressService = inject(MetadataProgressService); +private readonly bookdropFileService = inject(BookdropFileService); readonly currentUser = this.userService.currentUser; private readonly allAuthors = this.authorService.allAuthors; @@ -199,10 +201,10 @@ export class AppSidebarComponent { if (!user) return []; const actions = buildCreateActionNavItems(this.translate, user.permissions, { - createLibrary: () => this.dialogLauncherService.openLibraryCreateDialog(), - createShelf: () => this.bookDialogHelperService.openShelfCreatorDialog(), - createMagicShelf: () => this.dialogLauncherService.openMagicShelfCreateDialog(), - uploadBook: () => this.dialogLauncherService.openFileUploadDialog(), + createLibrary: () => void this.dialogLauncherService.openLibraryCreateDialog().catch(() => undefined), + createShelf: () => void this.bookDialogHelperService.openShelfCreatorDialog().catch(() => undefined), + createMagicShelf: () => void this.dialogLauncherService.openMagicShelfCreateDialog().catch(() => undefined), + uploadBook: () => void this.dialogLauncherService.openFileUploadDialog().catch(() => undefined), }); return this.toMenuEntries(actions); }); @@ -274,29 +276,28 @@ export class AppSidebarComponent { } protected openAccountSettings(): void { - this.dialogLauncherService.openUserProfileDialog(); - this.closeUserPopover(); + void this.dialogLauncherService.openUserProfileDialog().catch(() => undefined); + this.closeUserPopover(); } protected openSettings(): void { - this.router.navigate(['/settings']); - this.closeUserPopover(); + this.router.navigate(['/settings']); + this.closeUserPopover(); } protected openChangelogDialog(): void { - this.dialogLauncherService.openVersionChangelogDialog(); - this.closeUserPopover(); + void this.dialogLauncherService.openVersionChangelogDialog().catch(() => undefined); + this.closeUserPopover(); } protected openReadingStats(): void { - this.router.navigate(['/reading-stats']); - this.closeUserPopover(); + this.router.navigate(['/reading-stats']); + this.closeUserPopover(); } protected openUploadDialog(): void { - this.dialogLauncherService.openFileUploadDialog(); + void this.dialogLauncherService.openFileUploadDialog().catch(() => undefined); } - protected logout(): void { this.authService.logout(); this.closeUserPopover(); @@ -366,24 +367,24 @@ export class AppSidebarComponent { overlay.toggle(event); } - private subscribeToMetadataProgress(): void { - this.metadataProgressService.progressUpdates$ - .pipe(takeUntilDestroyed(this.destroyRef)) - .subscribe((progress) => { - this.progressHighlight = progress.status === MetadataBatchStatus.IN_PROGRESS; - }); - } +private subscribeToMetadataProgress(): void { + this.metadataProgressService.progressUpdates$ + .pipe(takeUntilDestroyed(this.destroyRef)) + .subscribe((progress) => { + this.progressHighlight = progress.status === MetadataBatchStatus.IN_PROGRESS; + }); +} - private replaceLatestTasks(tasks: Record): void { - for (const key of Object.keys(this.latestTasks)) { - delete this.latestTasks[key]; - } - Object.assign(this.latestTasks, tasks); +private replaceLatestTasks(tasks: Record): void { + for (const key of Object.keys(this.latestTasks)) { + delete this.latestTasks[key]; } + Object.assign(this.latestTasks, tasks); +} - private updateCompletedTaskCount(): void { - const metadataTaskCount = Object.keys(this.latestTasks).length; - const bookdropFileTaskCount = this.hasPendingBookdropFiles ? 1 : 0; - this.completedTaskCount = metadataTaskCount + bookdropFileTaskCount; - } +private updateCompletedTaskCount(): void { + const metadataTaskCount = Object.keys(this.latestTasks).length; + const bookdropFileTaskCount = this.hasPendingBookdropFiles ? 1 : 0; + this.completedTaskCount = metadataTaskCount + bookdropFileTaskCount; +} } diff --git a/frontend/src/app/shared/service/icon-picker.service.spec.ts b/frontend/src/app/shared/service/icon-picker.service.spec.ts index a79904a67..b021206fd 100644 --- a/frontend/src/app/shared/service/icon-picker.service.spec.ts +++ b/frontend/src/app/shared/service/icon-picker.service.spec.ts @@ -28,7 +28,7 @@ describe('IconPickerService', () => { }); it('returns the icon selected by the dialog', async () => { - dialogLauncherService.openIconPickerDialog.mockReturnValue({ + dialogLauncherService.openIconPickerDialog.mockResolvedValue({ onClose: of({type: 'PRIME_NG', value: 'pi pi-book'}), }); diff --git a/frontend/src/app/shared/service/icon-picker.service.ts b/frontend/src/app/shared/service/icon-picker.service.ts index 056db3ba2..baab793dc 100644 --- a/frontend/src/app/shared/service/icon-picker.service.ts +++ b/frontend/src/app/shared/service/icon-picker.service.ts @@ -1,5 +1,5 @@ import {inject, Injectable} from '@angular/core'; -import {Observable} from 'rxjs'; +import {EMPTY, from, Observable, switchMap} from 'rxjs'; import {DialogLauncherService} from '../services/dialog-launcher.service'; export interface IconSelection { @@ -12,7 +12,13 @@ export class IconPickerService { private dialogLauncherService = inject(DialogLauncherService); open(): Observable { - const ref = this.dialogLauncherService.openIconPickerDialog(); - return ref!.onClose as Observable; + return from(this.dialogLauncherService.openIconPickerDialog()).pipe( + switchMap(ref => { + if (!ref) { + return EMPTY; + } + return ref.onClose as Observable; + }) + ); } } diff --git a/frontend/src/app/shared/services/dialog-launcher.service.spec.ts b/frontend/src/app/shared/services/dialog-launcher.service.spec.ts index 0639f1d45..0a6fee2f2 100644 --- a/frontend/src/app/shared/services/dialog-launcher.service.spec.ts +++ b/frontend/src/app/shared/services/dialog-launcher.service.spec.ts @@ -1,6 +1,8 @@ import {TestBed} from '@angular/core/testing'; import {beforeEach, describe, expect, it, vi} from 'vitest'; import {DialogService} from 'primeng/dynamicdialog'; +import {MessageService} from 'primeng/api'; +import {getTranslocoModule} from '../../core/testing/transloco-testing'; import {DashboardSettingsComponent} from '../../features/dashboard/components/dashboard-settings/dashboard-settings.component'; import {LibraryCreatorComponent} from '../../features/library-creator/library-creator.component'; @@ -20,17 +22,19 @@ describe('DialogLauncherService', () => { TestBed.resetTestingModule(); TestBed.configureTestingModule({ + imports: [getTranslocoModule()], providers: [ DialogLauncherService, {provide: DialogService, useValue: dialogService}, + {provide: MessageService, useValue: {add: vi.fn()}}, ] }); service = TestBed.inject(DialogLauncherService); }); - it('merges the default dialog options with caller overrides', () => { - service.openDialog(LibraryCreatorComponent, { + it('merges the default dialog options with caller overrides', async () => { + await service.openDialog(LibraryCreatorComponent, { showHeader: false, data: {mode: 'create'}, }); @@ -51,8 +55,8 @@ describe('DialogLauncherService', () => { ); }); - it('opens the dashboard settings dialog with the expected style class', () => { - service.openDashboardSettingsDialog(); + it('opens the dashboard settings dialog with the expected style class', async () => { + await service.openDashboardSettingsDialog(); expect(dialogService.open).toHaveBeenCalledWith( DashboardSettingsComponent, @@ -63,8 +67,8 @@ describe('DialogLauncherService', () => { ); }); - it('passes the library id into the library edit dialog', () => { - service.openLibraryEditDialog(12); + it('passes the library id into the library edit dialog', async () => { + await service.openLibraryEditDialog(12); expect(dialogService.open).toHaveBeenCalledWith( LibraryCreatorComponent, diff --git a/frontend/src/app/shared/services/dialog-launcher.service.ts b/frontend/src/app/shared/services/dialog-launcher.service.ts index 46d8aaed4..d5cbfff28 100644 --- a/frontend/src/app/shared/services/dialog-launcher.service.ts +++ b/frontend/src/app/shared/services/dialog-launcher.service.ts @@ -1,20 +1,9 @@ import {inject, Injectable, Type} from '@angular/core'; import {DialogService, DynamicDialogRef} from 'primeng/dynamicdialog'; -import {LibraryCreatorComponent} from '../../features/library-creator/library-creator.component'; -import {BookUploaderComponent} from '../components/book-uploader/book-uploader.component'; -import {UserProfileDialogComponent} from '../../features/settings/user-profile-dialog/user-profile-dialog.component'; -import {MagicShelfComponent} from '../../features/magic-shelf/component/magic-shelf-component'; -import {DashboardSettingsComponent} from '../../features/dashboard/components/dashboard-settings/dashboard-settings.component'; -import {VersionChangelogDialogComponent} from '../layout/layout-sidebar/version-changelog-dialog/version-changelog-dialog.component'; -import {CreateUserDialogComponent} from '../../features/settings/user-management/create-user-dialog/create-user-dialog.component'; -import {CreateEmailRecipientDialogComponent} from '../../features/settings/email-v2/create-email-recipient-dialog/create-email-recipient-dialog.component'; -import {CreateEmailProviderDialogComponent} from '../../features/settings/email-v2/create-email-provider-dialog/create-email-provider-dialog.component'; -import {DirectoryPickerComponent} from '../components/directory-picker/directory-picker.component'; -import {BookdropFinalizeResultDialogComponent} from '../../features/bookdrop/component/bookdrop-finalize-result-dialog/bookdrop-finalize-result-dialog.component'; +import {TranslocoService} from '@jsverse/transloco'; +import {MessageService} from 'primeng/api'; +import {MetadataRefreshType} from '../../features/metadata/model/request/metadata-refresh-type.enum'; import {BookdropFinalizeResult} from '../../features/bookdrop/service/bookdrop.service'; -import {MetadataReviewDialogComponent} from '../../features/metadata/component/metadata-review-dialog/metadata-review-dialog-component'; -import {ShelfEditDialogComponent} from '../../features/book/components/shelf-edit-dialog/shelf-edit-dialog.component'; -import {IconPickerComponent} from '../components/icon-picker/icon-picker-component'; /** * Dialog size classes - use these to control dialog dimensions @@ -40,7 +29,9 @@ export const DialogStyle = { }) export class DialogLauncherService { - dialogService = inject(DialogService); + private readonly dialogService = inject(DialogService); + private readonly messageService = inject(MessageService); + private readonly t = inject(TranslocoService); private defaultDialogOptions = { baseZIndex: 10, @@ -60,132 +51,206 @@ export class DialogLauncherService { }); } - openDashboardSettingsDialog(): DynamicDialogRef | null { - return this.openDialog(DashboardSettingsComponent, { - showHeader: false, - styleClass: `${DialogSize.XL} ${DialogStyle.MINIMAL}`, + launchLazyDialog(dialogFn: () => Promise): Promise { + return dialogFn().catch(err => { + console.error('Failed to load dialog', err); + this.messageService.add({ + severity: 'error', + summary: this.t.translate('common.error'), + detail: this.t.translate('common.dialogLoadError') + }); + return null; }); } - openLibraryCreateDialog(): DynamicDialogRef | null { - return this.openDialog(LibraryCreatorComponent, { - showHeader: false, - styleClass: `${DialogSize.MD} ${DialogStyle.MINIMAL}`, + async openDashboardSettingsDialog(): Promise { + return this.launchLazyDialog(async () => { + const {DashboardSettingsComponent} = await import('../../features/dashboard/components/dashboard-settings/dashboard-settings.component'); + return this.openDialog(DashboardSettingsComponent, { + showHeader: false, + styleClass: `${DialogSize.XL} ${DialogStyle.MINIMAL}`, + }); }); } - openDirectoryPickerDialog(): DynamicDialogRef | null { - return this.openDialog(DirectoryPickerComponent, { - showHeader: false, - styleClass: `${DialogSize.MD} ${DialogStyle.MINIMAL}`, + async openLibraryCreateDialog(): Promise { + return this.launchLazyDialog(async () => { + const {LibraryCreatorComponent} = await import('../../features/library-creator/library-creator.component'); + return this.openDialog(LibraryCreatorComponent, { + showHeader: false, + styleClass: `${DialogSize.MD} ${DialogStyle.MINIMAL}`, + }); }); } - openLibraryEditDialog(libraryId: number): DynamicDialogRef | null { - return this.openDialog(LibraryCreatorComponent, { - showHeader: false, - styleClass: `${DialogSize.MD} ${DialogStyle.MINIMAL}`, - data: { - mode: 'edit', - libraryId: libraryId - } + async openDirectoryPickerDialog(): Promise { + return this.launchLazyDialog(async () => { + const {DirectoryPickerComponent} = await import('../components/directory-picker/directory-picker.component'); + return this.openDialog(DirectoryPickerComponent, { + showHeader: false, + styleClass: `${DialogSize.MD} ${DialogStyle.MINIMAL}`, + }); }); } - openShelfEditDialog(shelfId: number): DynamicDialogRef | null { - return this.openDialog(ShelfEditDialogComponent, { - showHeader: false, - styleClass: `${DialogSize.SM} ${DialogStyle.MINIMAL}`, - data: { - shelfId: shelfId - }, - }) - } - - openFileUploadDialog(): DynamicDialogRef | null { - return this.openDialog(BookUploaderComponent, { - showHeader: false, - styleClass: `${DialogSize.MD} ${DialogStyle.MINIMAL}`, + async openLibraryEditDialog(libraryId: number): Promise { + return this.launchLazyDialog(async () => { + const {LibraryCreatorComponent} = await import('../../features/library-creator/library-creator.component'); + return this.openDialog(LibraryCreatorComponent, { + showHeader: false, + styleClass: `${DialogSize.MD} ${DialogStyle.MINIMAL}`, + data: { + mode: 'edit', + libraryId: libraryId + } + }); }); } - openCreateUserDialog(): DynamicDialogRef | null { - return this.openDialog(CreateUserDialogComponent, { - showHeader: false, - styleClass: `${DialogSize.LG} ${DialogStyle.MINIMAL}`, + async openLibraryMetadataFetchDialog(libraryId: number): Promise { + return this.launchLazyDialog(async () => { + const {MetadataFetchOptionsComponent} = await import('../../features/metadata/component/metadata-options-dialog/metadata-fetch-options/metadata-fetch-options.component'); + return this.openDialog(MetadataFetchOptionsComponent, { + showHeader: false, + styleClass: `${DialogSize.SM} ${DialogStyle.MINIMAL}`, + data: { + libraryId: libraryId, + metadataRefreshType: MetadataRefreshType.LIBRARY, + }, + }); }); } - openUserProfileDialog(): DynamicDialogRef | null { - return this.openDialog(UserProfileDialogComponent, { - showHeader: false, - styleClass: `${DialogSize.SM} ${DialogStyle.MINIMAL}`, + async openShelfEditDialog(shelfId: number): Promise { + return this.launchLazyDialog(async () => { + const {ShelfEditDialogComponent} = await import('../../features/book/components/shelf-edit-dialog/shelf-edit-dialog.component'); + return this.openDialog(ShelfEditDialogComponent, { + showHeader: false, + styleClass: `${DialogSize.SM} ${DialogStyle.MINIMAL}`, + data: { + shelfId: shelfId + }, + }); }); } - openMagicShelfCreateDialog(): DynamicDialogRef | null { - return this.openDialog(MagicShelfComponent, { - showHeader: false, - styleClass: `${DialogSize.XL} ${DialogStyle.MINIMAL}`, + async openFileUploadDialog(): Promise { + return this.launchLazyDialog(async () => { + const {BookUploaderComponent} = await import('../components/book-uploader/book-uploader.component'); + return this.openDialog(BookUploaderComponent, { + showHeader: false, + styleClass: `${DialogSize.MD} ${DialogStyle.MINIMAL}`, + }); }); } - openMagicShelfEditDialog(shelfId: number): DynamicDialogRef | null { - return this.openDialog(MagicShelfComponent, { - showHeader: false, - styleClass: `${DialogSize.XL} ${DialogStyle.MINIMAL}`, - data: { - id: shelfId, - editMode: true, - } - }) - } - - openVersionChangelogDialog(): DynamicDialogRef | null { - return this.openDialog(VersionChangelogDialogComponent, { - showHeader: false, - styleClass: `${DialogSize.LG} ${DialogStyle.MINIMAL}`, + async openCreateUserDialog(): Promise { + return this.launchLazyDialog(async () => { + const {CreateUserDialogComponent} = await import('../../features/settings/user-management/create-user-dialog/create-user-dialog.component'); + return this.openDialog(CreateUserDialogComponent, { + showHeader: false, + styleClass: `${DialogSize.LG} ${DialogStyle.MINIMAL}`, + }); }); } - openEmailRecipientDialog(): DynamicDialogRef | null { - return this.openDialog(CreateEmailRecipientDialogComponent, { - showHeader: false, - styleClass: `${DialogSize.MD} ${DialogStyle.MINIMAL}`, + async openUserProfileDialog(): Promise { + return this.launchLazyDialog(async () => { + const {UserProfileDialogComponent} = await import('../../features/settings/user-profile-dialog/user-profile-dialog.component'); + return this.openDialog(UserProfileDialogComponent, { + showHeader: false, + styleClass: `${DialogSize.SM} ${DialogStyle.MINIMAL}`, + }); }); } - openEmailProviderDialog(): DynamicDialogRef | null { - return this.openDialog(CreateEmailProviderDialogComponent, { - showHeader: false, - styleClass: `${DialogSize.MD} ${DialogStyle.MINIMAL}`, + async openMagicShelfCreateDialog(): Promise { + return this.launchLazyDialog(async () => { + const {MagicShelfComponent} = await import('../../features/magic-shelf/component/magic-shelf-component'); + return this.openDialog(MagicShelfComponent, { + showHeader: false, + styleClass: `${DialogSize.XL} ${DialogStyle.MINIMAL}`, + }); }); } - openBookdropFinalizeResultDialog(result: BookdropFinalizeResult): DynamicDialogRef | null { - return this.openDialog(BookdropFinalizeResultDialogComponent, { - showHeader: false, - styleClass: `${DialogSize.MD} ${DialogStyle.MINIMAL}`, - data: { - result: result, - }, + async openMagicShelfEditDialog(shelfId: number): Promise { + return this.launchLazyDialog(async () => { + const {MagicShelfComponent} = await import('../../features/magic-shelf/component/magic-shelf-component'); + return this.openDialog(MagicShelfComponent, { + showHeader: false, + styleClass: `${DialogSize.XL} ${DialogStyle.MINIMAL}`, + data: { + id: shelfId, + editMode: true, + } + }); }); } - openMetadataReviewDialog(taskId: string): DynamicDialogRef | null { - return this.openDialog(MetadataReviewDialogComponent, { - showHeader: false, - styleClass: `${DialogSize.FULL} ${DialogStyle.MINIMAL}`, - data: { - taskId, - }, + async openVersionChangelogDialog(): Promise { + return this.launchLazyDialog(async () => { + const {VersionChangelogDialogComponent} = await import('../layout/layout-sidebar/version-changelog-dialog/version-changelog-dialog.component'); + return this.openDialog(VersionChangelogDialogComponent, { + showHeader: false, + styleClass: `${DialogSize.LG} ${DialogStyle.MINIMAL}`, + }); }); } - openIconPickerDialog(): DynamicDialogRef | null { - return this.openDialog(IconPickerComponent, { - showHeader: false, - styleClass: `${DialogSize.LG} ${DialogStyle.MINIMAL}`, + async openEmailRecipientDialog(): Promise { + return this.launchLazyDialog(async () => { + const {CreateEmailRecipientDialogComponent} = await import('../../features/settings/email-v2/create-email-recipient-dialog/create-email-recipient-dialog.component'); + return this.openDialog(CreateEmailRecipientDialogComponent, { + showHeader: false, + styleClass: `${DialogSize.MD} ${DialogStyle.MINIMAL}`, + }); + }); + } + + async openEmailProviderDialog(): Promise { + return this.launchLazyDialog(async () => { + const {CreateEmailProviderDialogComponent} = await import('../../features/settings/email-v2/create-email-provider-dialog/create-email-provider-dialog.component'); + return this.openDialog(CreateEmailProviderDialogComponent, { + showHeader: false, + styleClass: `${DialogSize.MD} ${DialogStyle.MINIMAL}`, + }); + }); + } + + async openBookdropFinalizeResultDialog(result: BookdropFinalizeResult): Promise { + return this.launchLazyDialog(async () => { + const {BookdropFinalizeResultDialogComponent} = await import('../../features/bookdrop/component/bookdrop-finalize-result-dialog/bookdrop-finalize-result-dialog.component'); + return this.openDialog(BookdropFinalizeResultDialogComponent, { + showHeader: false, + styleClass: `${DialogSize.MD} ${DialogStyle.MINIMAL}`, + data: { + result: result, + }, + }); + }); + } + + async openMetadataReviewDialog(taskId: string): Promise { + return this.launchLazyDialog(async () => { + const {MetadataReviewDialogComponent} = await import('../../features/metadata/component/metadata-review-dialog/metadata-review-dialog-component'); + return this.openDialog(MetadataReviewDialogComponent, { + showHeader: false, + styleClass: `${DialogSize.FULL} ${DialogStyle.MINIMAL}`, + data: { + taskId, + }, + }); + }); + } + + async openIconPickerDialog(): Promise { + return this.launchLazyDialog(async () => { + const {IconPickerComponent} = await import('../components/icon-picker/icon-picker-component'); + return this.openDialog(IconPickerComponent, { + showHeader: false, + styleClass: `${DialogSize.LG} ${DialogStyle.MINIMAL}`, + }); }); } } diff --git a/frontend/src/i18n/en/book.json b/frontend/src/i18n/en/book.json index 7521fc1bb..c882688ff 100644 --- a/frontend/src/i18n/en/book.json +++ b/frontend/src/i18n/en/book.json @@ -300,7 +300,8 @@ "magicShelfDeletedDetail": "Magic shelf was deleted", "magicShelfDeleteFailedDetail": "Failed to delete shelf", "magicShelfJsonCopiedDetail": "Magic shelf JSON copied to clipboard", - "failedSummary": "Failed" + "failedSummary": "Failed", + "dialogLoadFailedDetail": "An error occurred while loading the dialog. Please try again." }, "loading": { "deletingLibrary": "Deleting library '{{ name }}'..." diff --git a/frontend/src/i18n/en/common.json b/frontend/src/i18n/en/common.json index f0b52efef..3f8cca537 100644 --- a/frontend/src/i18n/en/common.json +++ b/frontend/src/i18n/en/common.json @@ -30,5 +30,6 @@ "cardSizeControls": "Card size controls", "on": "On", "off": "Off", - "moreActionsFor": "More actions for {{label}}" + "moreActionsFor": "More actions for {{label}}", + "dialogLoadError": "An error occurred while loading the dialog. Please try again." } diff --git a/frontend/src/main.ts b/frontend/src/main.ts index 99747ff3b..adbccfda1 100644 --- a/frontend/src/main.ts +++ b/frontend/src/main.ts @@ -17,8 +17,6 @@ import { GlobalErrorHandler } from './app/core/errors/global-error-handler'; import { PwaUpdateService } from './app/core/services/pwa-update.service'; import { initializeAuthFactory } from './app/core/security/auth-initializer'; import { StartupService } from './app/shared/service/startup.service'; -import { provideCharts, withDefaultRegisterables } from 'ng2-charts'; -import ChartDataLabels from 'chartjs-plugin-datalabels'; import { provideServiceWorker } from '@angular/service-worker'; import { provideTransloco } from '@jsverse/transloco'; import { AVAILABLE_LANGS, TranslocoInlineLoader } from './app/core/config/transloco-loader'; @@ -28,7 +26,6 @@ import { provideTanStackQuery, QueryClient } from '@tanstack/angular-query-exper bootstrapApplication(AppComponent, { providers: [ provideZonelessChangeDetection(), - provideCharts(withDefaultRegisterables(), ChartDataLabels), provideTanStackQuery(new QueryClient({ defaultOptions: { queries: {