From 1f5f99d958a7128bce51894bc49502b93b6a7948 Mon Sep 17 00:00:00 2001 From: brios <127139797+balazs-szucs@users.noreply.github.com> Date: Fri, 17 Apr 2026 13:25:20 +0200 Subject: [PATCH] refactor(ebook-reader): optimize destruction handling and improve reactive subscriptions (#478) --- .../author-detail.component.html | 4 +- .../author-detail.component.spec.ts | 4 +- .../author-detail/author-detail.component.ts | 6 +- .../book-browser/book-browser.component.html | 28 +- .../book-browser.component.spec.ts | 76 +- .../book-browser/book-browser.component.ts | 125 +- .../series-page/series-page.component.ts | 11 +- .../dashboard-scroller.component.html | 20 +- .../dashboard-scroller.component.ts | 18 +- .../dashboard-settings.component.html | 6 +- .../dashboard-settings.component.ts | 84 +- .../main-dashboard.component.ts | 175 +-- .../services/dashboard-book.service.ts | 168 +++ .../cbx-reader/cbx-reader.component.html | 94 +- .../cbx-reader/cbx-reader.component.ts | 1033 ++++++++--------- .../sidebar/cbx-sidebar.service.spec.ts | 15 +- .../layout/sidebar/cbx-sidebar.service.ts | 25 +- .../ebook-reader/ebook-reader.component.ts | 182 ++- .../features/notes/note.service.spec.ts | 6 +- .../features/notes/note.service.ts | 16 +- .../selection/selection.service.spec.ts | 5 +- .../features/selection/selection.service.ts | 22 +- .../layout/panel/panel.service.spec.ts | 8 +- .../layout/panel/panel.service.ts | 17 +- .../layout/sidebar/sidebar.service.spec.ts | 3 +- .../layout/sidebar/sidebar.service.ts | 29 +- 26 files changed, 1112 insertions(+), 1068 deletions(-) create mode 100644 frontend/src/app/features/dashboard/services/dashboard-book.service.ts diff --git a/frontend/src/app/features/author-browser/components/author-detail/author-detail.component.html b/frontend/src/app/features/author-browser/components/author-detail/author-detail.component.html index 15cbb2cc0..0f43e7218 100644 --- a/frontend/src/app/features/author-browser/components/author-detail/author-detail.component.html +++ b/frontend/src/app/features/author-browser/components/author-detail/author-detail.component.html @@ -1,5 +1,5 @@ - @if (loading) { + @if (loading()) {
@@ -7,7 +7,7 @@
} - @if (!loading && author(); as author) { + @if (!loading() && author(); as author) {
diff --git a/frontend/src/app/features/author-browser/components/author-detail/author-detail.component.spec.ts b/frontend/src/app/features/author-browser/components/author-detail/author-detail.component.spec.ts index 1a9c71257..6124bd4c2 100644 --- a/frontend/src/app/features/author-browser/components/author-detail/author-detail.component.spec.ts +++ b/frontend/src/app/features/author-browser/components/author-detail/author-detail.component.spec.ts @@ -144,7 +144,7 @@ describe('AuthorDetailComponent', () => { expect(getAuthorDetails).toHaveBeenCalledWith(42); expect(component.tab).toBe('series'); - expect(component.loading).toBe(false); + expect(component.loading()).toBe(false); expect(component.author()).toEqual({...baseAuthor, id: 42, name: 'Grace Hopper'}); expect(setPageTitle).toHaveBeenCalledWith('Grace Hopper'); }); @@ -158,7 +158,7 @@ describe('AuthorDetailComponent', () => { component.ngOnInit(); expect(component.tab).toBe('books'); - expect(component.loading).toBe(false); + expect(component.loading()).toBe(false); expect(component.author()).toBeNull(); expect(setPageTitle).not.toHaveBeenCalled(); }); diff --git a/frontend/src/app/features/author-browser/components/author-detail/author-detail.component.ts b/frontend/src/app/features/author-browser/components/author-detail/author-detail.component.ts index d20967be3..15f637764 100644 --- a/frontend/src/app/features/author-browser/components/author-detail/author-detail.component.ts +++ b/frontend/src/app/features/author-browser/components/author-detail/author-detail.component.ts @@ -85,7 +85,7 @@ export class AuthorDetailComponent implements OnInit, AfterViewChecked { private readonly viewportWidth = signal(0); private viewportResizeObserver: ResizeObserver | undefined; - loading = true; + loading = signal(true); tab = 'books'; isExpanded = false; isOverflowing = false; @@ -199,11 +199,11 @@ export class AuthorDetailComponent implements OnInit, AfterViewChecked { this.authorService.getAuthorDetails(authorId).subscribe({ next: (author) => { this.authorState.set(author); - this.loading = false; + this.loading.set(false); this.pageTitle.setPageTitle(author.name); }, error: () => { - this.loading = false; + this.loading.set(false); } }); } diff --git a/frontend/src/app/features/book/components/book-browser/book-browser.component.html b/frontend/src/app/features/book/components/book-browser/book-browser.component.html index 4d7d9068a..e31ace2db 100644 --- a/frontend/src/app/features/book/components/book-browser/book-browser.component.html +++ b/frontend/src/app/features/book/components/book-browser/book-browser.component.html @@ -8,7 +8,7 @@

@if (entityType === EntityType.ALL_BOOKS) { - @if (currentFilterLabel() && rawFilterParamFromUrl) { + @if (currentFilterLabel() && rawFilterParamFromUrl()) { {{ currentFilterLabel() }} } @else if (isFilterActive() || hasSearchTerm()) { {{ computedFilterLabel() }} @@ -70,7 +70,7 @@ + (click)="columnPreferenceService.saveVisibleColumns(visibleColumns())">

} @@ -180,14 +180,14 @@ [pTooltip]="t('tooltip.selectSorting')" tooltipPosition="top"> - @if (sortCriteriaCount > 1) { - + @if (sortCriteriaCount() > 1) { + } @@ -215,7 +215,7 @@ type="text" pInputText [placeholder]="t('placeholder.search')" - [(ngModel)]="bookTitle" + [ngModel]="bookTitle()" (ngModelChange)="onSearchTermChange($event)" class="search-input-full" /> @@ -237,11 +237,11 @@ type="text" pInputText [placeholder]="t('placeholder.search')" - [(ngModel)]="bookTitle" + [ngModel]="bookTitle()" (ngModelChange)="onSearchTermChange($event)" class="search-input" /> - @if (bookTitle) { + @if (bookTitle()) { } @if (currentViewMode() === 'grid') { @@ -330,7 +330,7 @@ [index]="i" [book]="book" [isCheckboxEnabled]="true" - [seriesViewEnabled]="seriesViewEnabled" + [seriesViewEnabled]="seriesViewEnabled()" [onBookSelect]="onBookCardSelect" [isSeriesCollapsed]="seriesCollapseFilter.seriesCollapsed()" (checkboxClick)="onCheckboxClicked($event)" @@ -358,7 +358,7 @@