- 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`
58 lines
2.0 KiB
TypeScript
58 lines
2.0 KiB
TypeScript
import {ChangeDetectionStrategy, Component, EventEmitter, inject, Input, Output} from '@angular/core';
|
|
import {NgClass} from '@angular/common';
|
|
import {ProgressBar} from 'primeng/progressbar';
|
|
import {Button} from 'primeng/button';
|
|
import {Tooltip} from 'primeng/tooltip';
|
|
import {TranslocoPipe} from '@jsverse/transloco';
|
|
import {SeriesSummary} from '../../model/series.model';
|
|
import {BookService} from '../../../book/service/book.service';
|
|
import {UrlHelperService} from '../../../../shared/service/url-helper.service';
|
|
|
|
@Component({
|
|
selector: 'app-series-card',
|
|
standalone: true,
|
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
templateUrl: './series-card.component.html',
|
|
styleUrls: ['./series-card.component.scss'],
|
|
imports: [NgClass, ProgressBar, Button, Tooltip, TranslocoPipe]
|
|
})
|
|
export class SeriesCardComponent {
|
|
|
|
@Input({required: true}) series!: SeriesSummary;
|
|
@Output() cardClick = new EventEmitter<SeriesSummary>();
|
|
|
|
protected urlHelper = inject(UrlHelperService);
|
|
private bookService = inject(BookService);
|
|
|
|
get progressPercent(): number {
|
|
return Math.round(this.series.progress * 100);
|
|
}
|
|
|
|
get authorsDisplay(): string {
|
|
if (!this.series.authors.length) return '';
|
|
if (this.series.authors.length <= 2) return this.series.authors.join(', ');
|
|
return this.series.authors.slice(0, 2).join(', ') + ' +' + (this.series.authors.length - 2);
|
|
}
|
|
|
|
getCoverUrl(index: number): string {
|
|
const book = this.series.coverBooks[index];
|
|
if (!book) return '';
|
|
const isAudiobook = book.primaryFile?.bookType === 'AUDIOBOOK';
|
|
return isAudiobook
|
|
? this.urlHelper.getAudiobookThumbnailUrl(book.id, book.metadata?.audiobookCoverUpdatedOn)
|
|
: this.urlHelper.getThumbnailUrl(book.id, book.metadata?.coverUpdatedOn);
|
|
}
|
|
|
|
onCardClick(event: Event): void {
|
|
event.stopPropagation();
|
|
this.cardClick.emit(this.series);
|
|
}
|
|
|
|
readNext(event: MouseEvent): void {
|
|
event.stopPropagation();
|
|
if (this.series.nextUnread) {
|
|
this.bookService.readBook(this.series.nextUnread.id);
|
|
}
|
|
}
|
|
}
|