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:
+9
-11
@@ -5,7 +5,7 @@ import {PageTitleService} from "../../../../shared/service/page-title.service";
|
||||
import {LibraryService} from '../../service/library.service';
|
||||
import {BookService} from '../../service/book.service';
|
||||
import {catchError, debounceTime, filter, map, switchMap, take} from 'rxjs/operators';
|
||||
import {BehaviorSubject, combineLatest, finalize, forkJoin, Observable, of, Subject} from 'rxjs';
|
||||
import {BehaviorSubject, combineLatest, finalize, Observable, of, Subject} from 'rxjs';
|
||||
import {ShelfService} from '../../service/shelf.service';
|
||||
import {DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
import {Library} from '../../model/library.model';
|
||||
@@ -129,7 +129,7 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
|
||||
entityType$: Observable<EntityType> | undefined;
|
||||
searchTerm$ = new BehaviorSubject<string>('');
|
||||
parsedFilters: Record<string, string[]> = {};
|
||||
selectedFilter = new BehaviorSubject<Record<string, any> | null>(null);
|
||||
selectedFilter = new BehaviorSubject<Record<string, string[]> | null>(null);
|
||||
selectedFilterMode = new BehaviorSubject<BookFilterMode>('and');
|
||||
protected resetFilterSubject = new Subject<void>();
|
||||
entity: Library | Shelf | MagicShelf | null = null;
|
||||
@@ -272,7 +272,7 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
|
||||
this.activatedRoute.paramMap,
|
||||
this.activatedRoute.queryParamMap,
|
||||
this.userService.userState$.pipe(filter(u => !!u?.user && u.loaded))
|
||||
]).subscribe(([paramMap, queryParamMap, user]) => {
|
||||
]).subscribe(([_, queryParamMap, user]) => {
|
||||
|
||||
const viewParam = queryParamMap.get(QUERY_PARAMS.VIEW);
|
||||
const sortParam = queryParamMap.get(QUERY_PARAMS.SORT);
|
||||
@@ -281,9 +281,9 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
|
||||
const filterMode = queryParamMap.get(QUERY_PARAMS.FMODE) || user.user?.userSettings?.filterMode;
|
||||
|
||||
if (filterMode && filterMode !== this.selectedFilterMode.getValue()) {
|
||||
this.selectedFilterMode.next(<BookFilterMode>filterMode);
|
||||
this.selectedFilterMode.next((filterMode as BookFilterMode));
|
||||
if (this.bookFilterComponent) {
|
||||
this.bookFilterComponent.selectedFilterMode = <BookFilterMode>filterMode;
|
||||
this.bookFilterComponent.selectedFilterMode = filterMode as BookFilterMode;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -379,7 +379,7 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
|
||||
this.applySortOption(this.bookSorter.selectedSort);
|
||||
}
|
||||
|
||||
const queryParams: any = {
|
||||
const queryParams: Record<string, string | number | null | undefined> = {
|
||||
[QUERY_PARAMS.VIEW]: this.currentViewMode,
|
||||
[QUERY_PARAMS.SORT]: this.bookSorter.selectedSort.field,
|
||||
[QUERY_PARAMS.DIRECTION]: this.bookSorter.selectedSort.direction === SortDirection.ASCENDING ? SORT_DIRECTION.ASCENDING : SORT_DIRECTION.DESCENDING,
|
||||
@@ -465,7 +465,7 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
|
||||
this.coverScalePreferenceService.setScale(this.coverScalePreferenceService.scaleFactor);
|
||||
}
|
||||
|
||||
onVisibleColumnsChange(selected: any[]) {
|
||||
onVisibleColumnsChange(selected: { field: string; header: string }[]) {
|
||||
const allFields = this.bookTableComponent.allColumns.map(col => col.field);
|
||||
this.visibleColumns = selected.sort(
|
||||
(a, b) => allFields.indexOf(a.field) - allFields.indexOf(b.field)
|
||||
@@ -556,8 +556,6 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
|
||||
.subscribe(() => {
|
||||
this.selectedBooks.clear();
|
||||
});
|
||||
},
|
||||
reject: () => {
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -754,8 +752,8 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
|
||||
return (entity as Library).paths !== undefined;
|
||||
}
|
||||
|
||||
private isMagicShelf(entity: any): entity is MagicShelf {
|
||||
return entity && 'filterJson' in entity;
|
||||
private isMagicShelf(entity: Library | Shelf | MagicShelf | null): entity is MagicShelf {
|
||||
return !!entity && 'filterJson' in entity;
|
||||
}
|
||||
|
||||
private getEntityInfoFromRoute(): Observable<{ entityId: number; entityType: EntityType }> {
|
||||
|
||||
+8
-8
@@ -125,7 +125,7 @@ function extractPublishedYearFilter(book: Book): { id: string; name: string }[]
|
||||
}
|
||||
|
||||
function getShelfStatusFilter(book: Book): { id: string; name: string }[] {
|
||||
const isShelved = book.shelves?.length! > 0;
|
||||
const isShelved = (book.shelves?.length ?? 0) > 0;
|
||||
return [{id: isShelved ? 'shelved' : 'unshelved', name: isShelved ? 'Shelved' : 'Unshelved'}];
|
||||
}
|
||||
|
||||
@@ -285,10 +285,10 @@ export class BookFilterComponent implements OnInit, OnDestroy {
|
||||
bookType: this.getFilterStream(getBookTypeFilter, 'id', 'name'),
|
||||
shelfStatus: this.getFilterStream(getShelfStatusFilter, 'id', 'name'),
|
||||
fileSize: this.getFilterStream((book: Book) => getFileSizeRangeFilters(book.fileSizeKb), 'id', 'name', 'sortIndex'),
|
||||
pageCount: this.getFilterStream((book: Book) => getPageCountRangeFilters(book.metadata?.pageCount!), 'id', 'name', 'sortIndex'),
|
||||
amazonRating: this.getFilterStream((book: Book) => getRatingRangeFilters(book.metadata?.amazonRating!), 'id', 'name', 'sortIndex'),
|
||||
goodreadsRating: this.getFilterStream((book: Book) => getRatingRangeFilters(book.metadata?.goodreadsRating!), 'id', 'name', 'sortIndex'),
|
||||
hardcoverRating: this.getFilterStream((book: Book) => getRatingRangeFilters(book.metadata?.hardcoverRating!), 'id', 'name', 'sortIndex'),
|
||||
pageCount: this.getFilterStream((book: Book) => getPageCountRangeFilters(book.metadata?.pageCount ?? undefined), 'id', 'name', 'sortIndex'),
|
||||
amazonRating: this.getFilterStream((book: Book) => getRatingRangeFilters(book.metadata?.amazonRating ?? undefined), 'id', 'name', 'sortIndex'),
|
||||
goodreadsRating: this.getFilterStream((book: Book) => getRatingRangeFilters(book.metadata?.goodreadsRating ?? undefined), 'id', 'name', 'sortIndex'),
|
||||
hardcoverRating: this.getFilterStream((book: Book) => getRatingRangeFilters(book.metadata?.hardcoverRating ?? undefined), 'id', 'name', 'sortIndex'),
|
||||
};
|
||||
|
||||
this.filterTypes = Object.keys(this.filterStreams) as FilterType[];
|
||||
@@ -469,18 +469,18 @@ export class BookFilterComponent implements OnInit, OnDestroy {
|
||||
|
||||
trackByFilter(_: number, filter: Filter<FilterValue>): unknown {
|
||||
const value = filter.value as { id?: unknown } | unknown;
|
||||
return (typeof value === 'object' && value !== null && 'id' in value) ? (value as any).id : filter.value;
|
||||
return (typeof value === 'object' && value !== null && 'id' in value) ? (value as {id: unknown}).id : filter.value;
|
||||
}
|
||||
|
||||
getFilterValueId(filter: Filter<FilterValue>): unknown {
|
||||
const value = filter.value as { id?: unknown } | unknown;
|
||||
return (typeof value === 'object' && value !== null && 'id' in value) ? (value as any).id : filter.value;
|
||||
return (typeof value === 'object' && value !== null && 'id' in value) ? (value as {id: unknown}).id : filter.value;
|
||||
}
|
||||
|
||||
getFilterValueDisplay(filter: Filter<FilterValue>): string {
|
||||
const value = filter.value as { name?: string } | string | unknown;
|
||||
if (typeof value === 'object' && value !== null && 'name' in value) {
|
||||
return String((value as any).name ?? '');
|
||||
return String((value as {name: string}).name ?? '');
|
||||
}
|
||||
return String(value ?? '');
|
||||
}
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@ import {UrlHelperService} from '../../../../../shared/service/url-helper.service
|
||||
import {Button} from 'primeng/button';
|
||||
import {BookService} from '../../../service/book.service';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {Router, RouterLink} from '@angular/router';
|
||||
import {RouterLink} from '@angular/router';
|
||||
import {filter, Subject} from 'rxjs';
|
||||
import {UserService} from '../../../../settings/user-management/user.service';
|
||||
import {take, takeUntil} from 'rxjs/operators';
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { Component, inject, OnDestroy } from "@angular/core";
|
||||
import { FormsModule } from "@angular/forms";
|
||||
import { Button } from "primeng/button";
|
||||
import { ActivatedRoute } from "@angular/router";
|
||||
|
||||
+1
-1
@@ -34,7 +34,7 @@
|
||||
class="input-full"
|
||||
placeholder="e.g., Favorites, To Read, Currently Reading"
|
||||
[class.filled]="shelfName.trim()"
|
||||
autofocus
|
||||
|
||||
/>
|
||||
@if (shelfName.trim()) {
|
||||
<i class="pi pi-check-circle input-icon success"></i>
|
||||
|
||||
@@ -38,7 +38,7 @@ export class LibraryShelfMenuService {
|
||||
label: 'Edit Library',
|
||||
icon: 'pi pi-pen-to-square',
|
||||
command: () => {
|
||||
this.dialogLauncherService.openLibraryEditDialog(<number>entity?.id);
|
||||
this.dialogLauncherService.openLibraryEditDialog((entity?.id as number));
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -77,7 +77,7 @@ export class LibraryShelfMenuService {
|
||||
label: 'Custom Fetch Metadata',
|
||||
icon: 'pi pi-sync',
|
||||
command: () => {
|
||||
this.dialogLauncherService.openLibraryMetadataFetchDialog(<number>entity?.id);
|
||||
this.dialogLauncherService.openLibraryMetadataFetchDialog((entity?.id as number));
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -144,7 +144,7 @@ export class LibraryShelfMenuService {
|
||||
label: 'Edit Shelf',
|
||||
icon: 'pi pi-pen-to-square',
|
||||
command: () => {
|
||||
this.dialogLauncherService.openShelfEditDialog(<number>entity?.id);
|
||||
this.dialogLauncherService.openShelfEditDialog((entity?.id as number));
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -197,7 +197,7 @@ export class LibraryShelfMenuService {
|
||||
icon: 'pi pi-pen-to-square',
|
||||
disabled: disableOptions,
|
||||
command: () => {
|
||||
this.dialogLauncherService.openMagicShelfEditDialog(<number>entity?.id);
|
||||
this.dialogLauncherService.openMagicShelfEditDialog((entity?.id as number));
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user