fix(ui): restore frontend verification after eslint cleanup

- Reader and metadata typing:
  - align ebook and cbx reader event, progress, dialog, and helper types with the stricter checks surfaced by the ESLint cleanup
  - replace unsafe non-null assertions and broad event assumptions with guarded access in reader, metadata, and shelf flows
- Template and component compatibility:
  - tighten menu item typing for Angular template checking and normalize overlay and card click handlers to use explicit DOM event types
  - repair chart, preferences, and websocket factory typings that broke standalone typecheck and production build validation
- Tests:
  - fix the magic shelf form-array assertion so the frontend test suite compiles cleanly under the stricter checker
- Validation:
  - `just ui check`
  - `just ui typecheck`
  - `just ui test`
This commit is contained in:
James Cox
2026-04-22 17:26:51 -04:00
committed by Zach Yale
parent 782bd63664
commit 43389c8dc4
30 changed files with 115 additions and 87 deletions
@@ -172,7 +172,7 @@ export class ReaderEventService {
const overlayerStyle = this.annotationService.getOverlayerDrawFunction(storedStyle.style);
draw(overlayerStyle, {color: storedStyle.color});
}
this.eventSubject.next({type: 'draw-annotation', detail: {annotation, doc, range}});
this.eventSubject.next({type: 'draw-annotation', detail: {draw, annotation, doc, range}});
});
this.view.addEventListener('show-annotation', (event: Event) => {
@@ -28,7 +28,7 @@ export interface BookMetadata {
publisher?: string;
description?: string;
identifier?: string;
coverUrl?: string;
coverUrl?: string | null;
[key: string]: unknown;
}
@@ -84,6 +84,8 @@ interface FoliateViewElement extends HTMLElement {
getCFI(index: number, range: Range): string | null;
deselect(): void;
addAnnotation(annotation: { value: string }): void;
deleteAnnotation(annotation: { value: string }): Promise<void>;
showAnnotation(annotation: { value: string }): Promise<void>;
getSectionFractions?(): number[];
search?(opts: { query: string; matchCase?: boolean; matchWholeWords?: boolean }): AsyncGenerator<FoliateSearchResult>;
clearSearch?(): void;
@@ -122,7 +124,7 @@ export class ReaderViewManagerService {
this.eventService.initialize(this.view, {
prev: () => this.prev(),
next: () => this.next(),
getCFI: (index: number, range: Range) => this.view?.getCFI(index, range),
getCFI: (index: number, range: Range) => this.view?.getCFI(index, range) ?? null,
getContents: () => this.view?.renderer?.getContents() ?? null
});
}
@@ -132,6 +134,7 @@ export class ReaderViewManagerService {
return throwError(() => new Error('View not created'));
}
const view = this.view;
return timer(100).pipe(
switchMap(() => from(fetch(epubPath))),
switchMap(response => {
@@ -144,7 +147,7 @@ export class ReaderViewManagerService {
const file = new File([blob], epubPath.split('/').pop() || 'book.epub', {
type: 'application/epub+zip'
});
return from(this.view.open(file) as Promise<void>);
return from(view.open(file) as Promise<void>);
}),
map(() => undefined),
catchError(err => throwError(() => err))
@@ -171,7 +174,11 @@ export class ReaderViewManagerService {
const baseUrl = this.epubStreamingService.getBaseUrl();
const authToken = this.epubStreamingService.getAuthToken();
const book = await makeStreamingBook(bookId, baseUrl, bookInfo, authToken, bookType);
await this.view.open(book);
const view = this.view;
if (!view) {
throw new Error('View not created');
}
await view.open(book);
}
destroy(): void {
@@ -185,8 +192,9 @@ export class ReaderViewManagerService {
if (!this.view) {
return of(undefined);
}
const view = this.view;
return defer(() =>
from(this.view.goTo(resolvedTarget) as Promise<void>)
from(view.goTo(resolvedTarget) as Promise<void>)
).pipe(
map(() => undefined)
);
@@ -200,7 +208,8 @@ export class ReaderViewManagerService {
if (!this.view) {
return of(undefined);
}
return defer(() => from(this.view.goToFraction(fraction) as Promise<void>)).pipe(
const view = this.view;
return defer(() => from(view.goToFraction(fraction) as Promise<void>)).pipe(
map(() => undefined)
);
}
@@ -304,8 +313,9 @@ export class ReaderViewManagerService {
if (!this.view?.book?.getCover) {
return of(null);
}
const book = this.view.book;
return defer(() => {
const coverPromise = this.view.book.getCover();
const coverPromise = book.getCover?.();
return coverPromise ? from(coverPromise as Promise<Blob | null>) : of(null);
});
}
@@ -317,8 +327,9 @@ export class ReaderViewManagerService {
}
async* search(opts: { query: string; matchCase?: boolean; matchWholeWords?: boolean }): AsyncGenerator<FoliateSearchResult> {
if (!this.view?.search) return;
yield* this.view.search(opts);
const search = this.view?.search;
if (!search) return;
yield* search.call(this.view, opts);
}
clearSearch(): void {
@@ -1,9 +1,9 @@
<ng-container *transloco="let t; prefix: 'readerEbook.metadataDialog'">
<div class="dialog-overlay" role="button" tabindex="0" (click)="close.emit()" (keydown.enter)="close.emit()">
<div class="dialog-overlay" role="button" tabindex="0" (click)="closed.emit()" (keydown.enter)="closed.emit()">
<div class="dialog" tabindex="0" (click)="$event.stopPropagation()" (keydown.enter)="$event.stopPropagation()">
<div class="dialog-header">
<h2>{{ t('title') }}</h2>
<button class="close-btn" (click)="close.emit()">&#10005;</button>
<button class="close-btn" (click)="closed.emit()">&#10005;</button>
</div>
<div class="dialog-body">
@@ -70,7 +70,7 @@ export class ReaderNoteDialogComponent implements OnChanges {
this.selectedColor = color;
}
onOverlayClick(event: MouseEvent): void {
onOverlayClick(event: Event): void {
if ((event.target as HTMLElement).classList.contains('dialog-overlay')) {
this.onCancel();
}
@@ -1,5 +1,5 @@
<ng-container *transloco="let t; prefix: 'readerEbook.settingsDialog'">
<div class="dialog-overlay" role="button" tabindex="0" (click)="close.emit()" (keydown.enter)="close.emit()">
<div class="dialog-overlay" role="button" tabindex="0" (click)="closed.emit()" (keydown.enter)="closed.emit()">
<div class="dialog" tabindex="0" (click)="$event.stopPropagation()" (keydown.enter)="$event.stopPropagation()">
<div class="tabs-row">
<div class="tabs">
@@ -22,7 +22,7 @@
{{ t('layoutTab') }}
</button>
</div>
<button class="close-btn" (click)="close.emit()">&#10005;</button>
<button class="close-btn" (click)="closed.emit()">&#10005;</button>
</div>
<div class="dialog-body">
@@ -71,7 +71,7 @@ export class EbookShortcutsHelpComponent {
this.closed.emit();
}
onOverlayClick(event: MouseEvent): void {
onOverlayClick(event: Event): void {
if ((event.target as HTMLElement).classList.contains('dialog-overlay')) {
this.onClose();
}
@@ -424,12 +424,12 @@ export class EbookReaderComponent implements OnInit, OnDestroy {
this.visibilityManager.handleMouseMove(event.clientY);
}
@HostListener('document:mouseleave', ['$event'])
@HostListener('document:mouseleave')
onMouseLeave(): void {
this.visibilityManager.handleMouseLeave();
}
@HostListener('window:resize', ['$event'])
@HostListener('window:resize')
onWindowResize(): void {
this.visibilityManager.updateWindowHeight(window.innerHeight);
}
@@ -11,7 +11,7 @@ export interface Annotation {
}
interface AnnotationView {
addAnnotation(annotation: { value: string }): Promise<{ index: number; label: string } | undefined>;
addAnnotation(annotation: { value: string }): Promise<{ index: number; label: string } | undefined> | void;
deleteAnnotation(annotation: { value: string }): Promise<void>;
showAnnotation(annotation: { value: string }): Promise<void>;
}
@@ -2,31 +2,7 @@ import {Component, EventEmitter, HostListener, inject, Input, Output} from '@ang
import {TranslocoDirective} from '@jsverse/transloco';
import {ReaderViewManagerService} from '../../core/view-manager.service';
import {ReaderIconComponent} from '../../shared/icon.component';
interface TocItem {
label: string;
href: string;
subitems?: TocItem[];
id: number;
}
interface PageItem {
label: string;
href: string;
subitems?: PageItem[];
id: number;
}
interface RelocateEventDetail {
fraction: number;
section: { current: number; total: number };
location: { current: number; next: number; total: number };
time: { section: number; total: number };
tocItem: TocItem;
pageItem: PageItem;
cfi: string;
range: Range | null;
}
import {RelocateProgressData} from '../../state/progress.service';
@Component({
selector: 'app-reader-navbar',
@@ -36,7 +12,7 @@ interface RelocateEventDetail {
styleUrls: ['./footer.component.scss']
})
export class ReaderNavbarComponent {
@Input() progressData: RelocateEventDetail | null = null;
@Input() progressData: RelocateProgressData | null = null;
@Input() forceVisible = false;
@Input() set sectionFractions(value: number[]) {
this._sectionFractions = value.filter(f => f > 0.001 && f < 0.999);
@@ -82,19 +58,19 @@ export class ReaderNavbarComponent {
}
get timeTotal(): string {
return this.formatDuration((this.progressData?.time.total ?? 0) * 60);
return this.formatDuration((this.progressData?.time?.total ?? 0) * 60);
}
get timeSection(): string {
return this.formatDuration((this.progressData?.time.section ?? 0) * 60);
return this.formatDuration((this.progressData?.time?.section ?? 0) * 60);
}
get sectionCurrent(): number {
return this.progressData?.section.current ?? 0;
return this.progressData?.section?.current ?? 0;
}
get sectionTotal(): number {
return this.progressData?.section.total ?? 0;
return this.progressData?.section?.total ?? 0;
}
get currentChapter(): string {
@@ -51,10 +51,11 @@ export class PageDecorator {
}
const footerStyle = this.buildStyle(theme);
const feet = renderer.feet;
renderer.feet.forEach((footElement: HTMLElement, index: number) => {
feet.forEach((footElement: HTMLElement, index: number) => {
if (footElement) {
const footerContent = this.createFooterContent(pageInfo, isSingleColumn, index, renderer.feet.length, footerStyle, timeRemainingLabel);
const footerContent = this.createFooterContent(pageInfo, isSingleColumn, index, feet.length, footerStyle, timeRemainingLabel);
footElement.replaceChildren(footerContent);
}
});
@@ -128,7 +128,7 @@ export class TextSelectionPopupComponent {
this.hasPreview = false;
}
onDismiss(event: MouseEvent): void {
onDismiss(event: Event): void {
event.stopPropagation();
event.preventDefault();
@@ -108,7 +108,7 @@ export class ReaderProgressService {
}
if (cfi && percentage !== null) {
this.bookPatchService.saveEpubProgress(this.bookId, cfi, href, percentage, this.bookFileId);
this.bookPatchService.saveEpubProgress(this.bookId, cfi, href ?? '', percentage, this.bookFileId);
this.readingSessionService.updateProgress(cfi, percentage);
}
@@ -123,7 +123,7 @@ export class ReaderProgressService {
}
if (detail?.section) {
const percentCompleted = Math.round((detail.fraction * 100) * 10) / 10;
const percentCompleted = Math.round(((detail.fraction ?? 0) * 100) * 10) / 10;
const totalMinutes = detail.time?.section ?? 0;
const hours = Math.floor(totalMinutes / 60);