refactor(frontend): resolve linting errors, and EPUB reader lifecycle errors (#2127)
* refactor(types): improve type safety by replacing 'any' with specific types in various components Signed-off-by: Balázs Szücs <bszucs1209@gmail.com> * fix(filters): handle undefined values in filter streams and update type for selected filters Signed-off-by: Balázs Szücs <bszucs1209@gmail.com> * refactor(epub-reader): improve rendition cleanup and enhance debug logging in helper functions Signed-off-by: Balázs Szücs <bszucs1209@gmail.com> * fix(epub-reader): handle errors during rendition and book destruction in ngOnDestroy Signed-off-by: Balázs Szücs <bszucs1209@gmail.com> --------- Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>
This commit is contained in:
+11
-3
@@ -1,4 +1,4 @@
|
||||
import {Component, inject, Input, OnInit, OnChanges, SimpleChanges} from '@angular/core';
|
||||
import {Component, inject, Input, OnInit, OnChanges, SimpleChanges, ChangeDetectorRef} from '@angular/core';
|
||||
import {CommonModule} from '@angular/common';
|
||||
import {ReadingSessionApiService, ReadingSessionResponse} from '../../../../../shared/service/reading-session-api.service';
|
||||
import {TableModule} from 'primeng/table';
|
||||
@@ -16,6 +16,7 @@ export class BookReadingSessionsComponent implements OnInit, OnChanges {
|
||||
@Input() bookId!: number;
|
||||
|
||||
private readonly readingSessionService = inject(ReadingSessionApiService);
|
||||
private readonly cdr = inject(ChangeDetectorRef);
|
||||
|
||||
sessions: ReadingSessionResponse[] = [];
|
||||
totalRecords = 0;
|
||||
@@ -24,7 +25,7 @@ export class BookReadingSessionsComponent implements OnInit, OnChanges {
|
||||
loading = false;
|
||||
|
||||
ngOnInit() {
|
||||
this.loadSessions();
|
||||
// Rely on p-table onLazyLoad to trigger the initial load
|
||||
}
|
||||
|
||||
ngOnChanges(changes: SimpleChanges) {
|
||||
@@ -35,16 +36,23 @@ export class BookReadingSessionsComponent implements OnInit, OnChanges {
|
||||
}
|
||||
|
||||
loadSessions(page: number = 0) {
|
||||
this.loading = true;
|
||||
// Prevent ExpressionChangedAfterItHasBeenCheckedError
|
||||
setTimeout(() => {
|
||||
this.loading = true;
|
||||
this.cdr.markForCheck();
|
||||
});
|
||||
|
||||
this.readingSessionService.getSessionsByBookId(this.bookId, page, this.rows)
|
||||
.subscribe({
|
||||
next: (response) => {
|
||||
this.sessions = response.content;
|
||||
this.totalRecords = response.totalElements;
|
||||
this.loading = false;
|
||||
this.cdr.markForCheck();
|
||||
},
|
||||
error: () => {
|
||||
this.loading = false;
|
||||
this.cdr.markForCheck();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+1
-1
@@ -600,7 +600,7 @@ export class MetadataEditorComponent implements OnInit {
|
||||
}
|
||||
|
||||
private updateMetadata(shouldLockAllFields: boolean | undefined): void {
|
||||
let metadataUpdateWrapper = this.buildMetadataWrapper(shouldLockAllFields);
|
||||
const metadataUpdateWrapper = this.buildMetadataWrapper(shouldLockAllFields);
|
||||
this.bookService
|
||||
.updateBookMetadata(this.currentBookId, metadataUpdateWrapper, false)
|
||||
.subscribe({
|
||||
|
||||
+1
-1
@@ -677,7 +677,7 @@ export class MetadataPickerComponent implements OnInit {
|
||||
this.goBack.emit(true);
|
||||
}
|
||||
|
||||
hoveredFields: { [key: string]: boolean } = {};
|
||||
hoveredFields: Record<string, boolean> = {};
|
||||
|
||||
onMouseEnter(controlName: string): void {
|
||||
if (this.isValueCopied(controlName) && !this.isValueSaved(controlName)) {
|
||||
|
||||
+1
-1
@@ -439,7 +439,7 @@ export class MetadataViewerComponent implements OnInit, OnChanges {
|
||||
}
|
||||
|
||||
assignShelf(bookId: number) {
|
||||
this.bookDialogHelperService.openShelfAssignerDialog(<Book>this.bookService.getBookByIdFromState(bookId), null);
|
||||
this.bookDialogHelperService.openShelfAssignerDialog((this.bookService.getBookByIdFromState(bookId) as Book), null);
|
||||
}
|
||||
|
||||
updateReadStatus(status: ReadStatus): void {
|
||||
|
||||
+1
-1
@@ -47,7 +47,7 @@ export class CoverSearchComponent implements OnInit {
|
||||
|
||||
ngOnInit() {
|
||||
this.bookId = this.dynamicDialogConfig.data.bookId;
|
||||
let book = this.bookService.getBookByIdFromState(this.bookId);
|
||||
const book = this.bookService.getBookByIdFromState(this.bookId);
|
||||
|
||||
if (book) {
|
||||
this.searchForm.patchValue({
|
||||
|
||||
Reference in New Issue
Block a user