From 2fd7310e8186619142b9a4b34c6a12e13d38cd87 Mon Sep 17 00:00:00 2001 From: Alex <25013571+alexhb1@users.noreply.github.com> Date: Tue, 31 Mar 2026 20:26:42 +0100 Subject: [PATCH] refactor(ui): replace SVG artwork placeholders with CSS (#292) * chore(ui): replace SVG placeholders with CSS alternative * fix(ui): Placeholder review followup --- .../book-card/book-card.component.html | 18 +- .../book-card/book-card.component.ts | 7 +- .../book-table/book-table.component.html | 34 +- .../book-table/book-table.component.ts | 4 +- .../book-card-lite-component.html | 14 +- .../book-card-lite-component.ts | 6 +- .../book-searcher.component.html | 14 +- .../book-searcher/book-searcher.component.ts | 2 + .../duplicate-merger.component.html | 12 +- .../duplicate-merger.component.ts | 2 + .../series-page/series-page.component.html | 40 ++- .../series-page/series-page.component.ts | 8 +- .../metadata-editor.component.html | 42 ++- .../metadata-editor.component.ts | 2 + .../metadata-tabs.component.html | 38 +- .../metadata-tabs/metadata-tabs.component.ts | 4 +- .../metadata-viewer.component.html | 18 +- .../metadata-viewer.component.ts | 5 +- .../notebook/notebook.component.html | 6 +- .../components/notebook/notebook.component.ts | 6 +- .../layout/sidebar/cbx-sidebar.component.html | 2 + .../layout/sidebar/cbx-sidebar.component.ts | 3 +- .../dialogs/metadata-dialog.component.html | 4 +- .../dialogs/metadata-dialog.component.scss | 8 - .../dialogs/metadata-dialog.component.ts | 6 +- .../layout/sidebar/sidebar.component.html | 10 + .../layout/sidebar/sidebar.component.ts | 3 +- .../series-card/series-card.component.html | 23 +- .../series-card/series-card.component.spec.ts | 2 +- .../series-card/series-card.component.ts | 7 +- .../cover-generator.component.spec.ts | 87 +++-- .../cover-generator.component.ts | 326 ++++++------------ .../shared/service/url-helper.service.spec.ts | 63 +--- .../app/shared/service/url-helper.service.ts | 77 +---- 34 files changed, 392 insertions(+), 511 deletions(-) diff --git a/frontend/src/app/features/book/components/book-browser/book-card/book-card.component.html b/frontend/src/app/features/book/components/book-browser/book-card/book-card.component.html index 2872a95ad..8cc8f2c57 100644 --- a/frontend/src/app/features/book/components/book-browser/book-card/book-card.component.html +++ b/frontend/src/app/features/book/components/book-browser/book-card/book-card.component.html @@ -6,13 +6,17 @@ (keydown.enter)="onCardClick($event)">
- + @if (coverImageUrl) { + + } @else { + + }
@if ((overlayPreferenceService?.showBookTypePill() ?? true) && getDisplayFormat(); as displayFormat) { diff --git a/frontend/src/app/features/book/components/book-browser/book-card/book-card.component.ts b/frontend/src/app/features/book/components/book-browser/book-card/book-card.component.ts index 11c66eee8..341eac65d 100644 --- a/frontend/src/app/features/book/components/book-browser/book-card/book-card.component.ts +++ b/frontend/src/app/features/book/components/book-browser/book-card/book-card.component.ts @@ -11,6 +11,7 @@ import {CheckboxChangeEvent, CheckboxModule} from 'primeng/checkbox'; import {FormsModule} from '@angular/forms'; import {MetadataRefreshType} from '../../../../metadata/model/request/metadata-refresh-type.enum'; import {UrlHelperService} from '../../../../../shared/service/url-helper.service'; +import {CoverPlaceholderComponent} from '../../../../../shared/components/cover-generator/cover-generator.component'; import {NgClass} from '@angular/common'; import {User, UserService} from '../../../../settings/user-management/user.service'; import {EmailService} from '../../../../settings/email-v2/email.service'; @@ -33,7 +34,7 @@ import {QueryClient} from '@tanstack/angular-query-experimental'; selector: 'app-book-card', templateUrl: './book-card.component.html', styleUrls: ['./book-card.component.scss'], - imports: [Button, MenuModule, CheckboxModule, FormsModule, NgClass, TieredMenu, ProgressBar, TooltipModule, RouterLink, TranslocoPipe], + imports: [Button, MenuModule, CheckboxModule, FormsModule, NgClass, TieredMenu, ProgressBar, TooltipModule, RouterLink, TranslocoPipe, CoverPlaceholderComponent], standalone: true, changeDetection: ChangeDetectionStrategy.OnPush }) @@ -82,7 +83,7 @@ export class BookCardComponent implements OnInit, OnChanges { protected _koboProgressPercentage: number | null = null; protected _displayTitle: string | undefined = undefined; protected _isSeriesViewActive: boolean = false; - protected _coverImageUrl: string = ''; + protected _coverImageUrl: string | null = null; protected _readStatusIcon: string = ''; protected _readStatusClass: string = ''; protected _readStatusTooltip: string = ''; @@ -214,7 +215,7 @@ export class BookCardComponent implements OnInit, OnChanges { return this._displayTitle; } - get coverImageUrl(): string { + get coverImageUrl(): string | null { return this._coverImageUrl; } diff --git a/frontend/src/app/features/book/components/book-browser/book-table/book-table.component.html b/frontend/src/app/features/book/components/book-browser/book-table/book-table.component.html index 970353fc1..764bcb405 100644 --- a/frontend/src/app/features/book/components/book-browser/book-table/book-table.component.html +++ b/frontend/src/app/features/book/components/book-browser/book-table/book-table.component.html @@ -51,22 +51,30 @@ - + @if (urlHelper.getThumbnailUrl(metadata.bookId, metadata.coverUpdatedOn); as coverUrl) { + + } @else { + + }
- + @if (urlHelper.getThumbnailUrl(metadata.bookId, metadata.coverUpdatedOn); as coverUrl) { + + } @else { + + } {{ metadata.title }}
diff --git a/frontend/src/app/features/book/components/book-browser/book-table/book-table.component.ts b/frontend/src/app/features/book/components/book-browser/book-table/book-table.component.ts index 144ab123a..314e2655c 100644 --- a/frontend/src/app/features/book/components/book-browser/book-table/book-table.component.ts +++ b/frontend/src/app/features/book/components/book-browser/book-table/book-table.component.ts @@ -7,6 +7,7 @@ import {TooltipModule} from "primeng/tooltip"; import {Book, BookMetadata, ReadStatus} from '../../../model/book.model'; import {SortOption} from '../../../model/sort.model'; import {UrlHelperService} from '../../../../../shared/service/url-helper.service'; +import {CoverPlaceholderComponent} from '../../../../../shared/components/cover-generator/cover-generator.component'; import {Button} from 'primeng/button'; import {BookService} from '../../../service/book.service'; import {BookMetadataManageService} from '../../../service/book-metadata-manage.service'; @@ -29,7 +30,8 @@ import {TranslocoDirective, TranslocoService} from '@jsverse/transloco'; TooltipModule, NgClass, RouterLink, - TranslocoDirective + TranslocoDirective, + CoverPlaceholderComponent ], styleUrls: ['./book-table.component.scss'], providers: [DatePipe] diff --git a/frontend/src/app/features/book/components/book-card-lite/book-card-lite-component.html b/frontend/src/app/features/book/components/book-card-lite/book-card-lite-component.html index 26e730bdf..d8d2ecf9f 100644 --- a/frontend/src/app/features/book/components/book-card-lite/book-card-lite-component.html +++ b/frontend/src/app/features/book/components/book-card-lite/book-card-lite-component.html @@ -1,9 +1,13 @@
- Cover of {{ book.metadata?.title }} + @if (getThumbnailUrl(); as coverUrl) { + Cover of {{ book.metadata?.title }} + } @else { + + } @if (showSeriesNumber && !book.seriesCount && book.metadata?.seriesNumber !== null && book.metadata?.seriesNumber !== undefined) {
diff --git a/frontend/src/app/features/book/components/book-card-lite/book-card-lite-component.ts b/frontend/src/app/features/book/components/book-card-lite/book-card-lite-component.ts index ec0bb8655..51efd2d1c 100644 --- a/frontend/src/app/features/book/components/book-card-lite/book-card-lite-component.ts +++ b/frontend/src/app/features/book/components/book-card-lite/book-card-lite-component.ts @@ -1,6 +1,7 @@ import {ChangeDetectionStrategy, Component, computed, inject, Input} from '@angular/core'; import {Book} from '../../model/book.model'; import {UrlHelperService} from '../../../../shared/service/url-helper.service'; +import {CoverPlaceholderComponent} from '../../../../shared/components/cover-generator/cover-generator.component'; import {Button} from 'primeng/button'; import {UserService} from '../../../settings/user-management/user.service'; import {Router} from '@angular/router'; @@ -14,7 +15,8 @@ import {TooltipModule} from 'primeng/tooltip'; imports: [ Button, NgClass, - TooltipModule + TooltipModule, + CoverPlaceholderComponent ], templateUrl: './book-card-lite-component.html', styleUrl: './book-card-lite-component.scss' @@ -40,7 +42,7 @@ export class BookCardLiteComponent { return primaryIsAudiobook && !hasEbookAlternative; } - getThumbnailUrl(): string { + getThumbnailUrl(): string | null { if (this.isAudiobookOnly()) { return this.urlHelper.getAudiobookThumbnailUrl(this.book.id, this.book.metadata?.audiobookCoverUpdatedOn); } diff --git a/frontend/src/app/features/book/components/book-searcher/book-searcher.component.html b/frontend/src/app/features/book/components/book-searcher/book-searcher.component.html index 37c90d7e0..e4f3699cd 100644 --- a/frontend/src/app/features/book/components/book-searcher/book-searcher.component.html +++ b/frontend/src/app/features/book/components/book-searcher/book-searcher.component.html @@ -49,11 +49,15 @@ (click)="onBookClick(book)" (keydown.enter)="onBookClick(book)">
- + @if (urlHelper.getThumbnailUrl(book.id, book.metadata?.coverUpdatedOn); as coverUrl) { + + } @else { + + }

diff --git a/frontend/src/app/features/book/components/book-searcher/book-searcher.component.ts b/frontend/src/app/features/book/components/book-searcher/book-searcher.component.ts index 5afab5093..cc91989dd 100644 --- a/frontend/src/app/features/book/components/book-searcher/book-searcher.component.ts +++ b/frontend/src/app/features/book/components/book-searcher/book-searcher.component.ts @@ -9,6 +9,7 @@ import {Button} from 'primeng/button'; import {SlicePipe} from '@angular/common'; import {Skeleton} from 'primeng/skeleton'; import {UrlHelperService} from '../../../../shared/service/url-helper.service'; +import {CoverPlaceholderComponent} from '../../../../shared/components/cover-generator/cover-generator.component'; import {Router} from '@angular/router'; import {IconField} from 'primeng/iconfield'; import {InputIcon} from 'primeng/inputicon'; @@ -27,6 +28,7 @@ import {TranslocoDirective, TranslocoService} from '@jsverse/transloco'; IconField, InputIcon, TranslocoDirective, + CoverPlaceholderComponent, ], styleUrls: ['./book-searcher.component.scss'], standalone: true diff --git a/frontend/src/app/features/book/components/duplicate-merger/duplicate-merger.component.html b/frontend/src/app/features/book/components/duplicate-merger/duplicate-merger.component.html index 64df81bc8..9339fd48e 100644 --- a/frontend/src/app/features/book/components/duplicate-merger/duplicate-merger.component.html +++ b/frontend/src/app/features/book/components/duplicate-merger/duplicate-merger.component.html @@ -186,10 +186,14 @@ class="delete-checkbox"> } - + @if (urlHelper.getThumbnailUrl(book.id, book.metadata?.coverUpdatedOn); as coverUrl) { + + } @else { + + }

{{ book.metadata?.title || ('book.fileAttacher.unknownTitle' | transloco) }}
@if (book.metadata?.authors?.length) { diff --git a/frontend/src/app/features/book/components/duplicate-merger/duplicate-merger.component.ts b/frontend/src/app/features/book/components/duplicate-merger/duplicate-merger.component.ts index 6dedee536..5c70d26b4 100644 --- a/frontend/src/app/features/book/components/duplicate-merger/duplicate-merger.component.ts +++ b/frontend/src/app/features/book/components/duplicate-merger/duplicate-merger.component.ts @@ -15,6 +15,7 @@ import {Book, DuplicateDetectionRequest, DuplicateGroup} from '../../model/book. import {ConfirmationService, MessageService} from 'primeng/api'; import {TranslocoDirective, TranslocoPipe, TranslocoService} from '@jsverse/transloco'; import {UrlHelperService} from '../../../../shared/service/url-helper.service'; +import {CoverPlaceholderComponent} from '../../../../shared/components/cover-generator/cover-generator.component'; import {AppSettingsService} from '../../../../shared/service/app-settings.service'; type PresetMode = 'strict' | 'balanced' | 'aggressive' | 'custom'; @@ -39,6 +40,7 @@ interface DisplayGroup extends DuplicateGroup { Paginator, TranslocoDirective, TranslocoPipe, + CoverPlaceholderComponent, ], templateUrl: './duplicate-merger.component.html', styleUrls: ['./duplicate-merger.component.scss'] diff --git a/frontend/src/app/features/book/components/series-page/series-page.component.html b/frontend/src/app/features/book/components/series-page/series-page.component.html index 91e3673b6..492c46a13 100644 --- a/frontend/src/app/features/book/components/series-page/series-page.component.html +++ b/frontend/src/app/features/book/components/series-page/series-page.component.html @@ -32,12 +32,16 @@
@if (coverBook(); as coverBook) {
- + @if (getBookThumbnailUrl(coverBook); as coverUrl) { + + } @else { + + }
} @@ -186,10 +190,14 @@ tabindex="0" (click)="readBook(nextUp.book.id)" (keydown.enter)="readBook(nextUp.book.id)"> - + @if (nextUp.thumbnailUrl) { + + } @else { + + }
@@ -310,10 +318,14 @@ {{ book.metadata?.seriesNumber !== null && book.metadata?.seriesNumber !== undefined ? '#' + book.metadata?.seriesNumber : '-' }}
- + @if (getBookThumbnailUrl(book); as coverUrl) { + + } @else { + + }
{{ book.metadata?.title || '' }}
diff --git a/frontend/src/app/features/book/components/series-page/series-page.component.ts b/frontend/src/app/features/book/components/series-page/series-page.component.ts index 44303b685..e17a1df6f 100644 --- a/frontend/src/app/features/book/components/series-page/series-page.component.ts +++ b/frontend/src/app/features/book/components/series-page/series-page.component.ts @@ -31,6 +31,7 @@ import {animate, style, transition, trigger} from "@angular/animations"; import {AfterViewChecked, Component, computed, effect, ElementRef, inject, ViewChild} from '@angular/core'; import {BookCardOverlayPreferenceService} from '../book-browser/book-card-overlay-preference.service'; import {UrlHelperService} from '../../../../shared/service/url-helper.service'; +import {CoverPlaceholderComponent} from '../../../../shared/components/cover-generator/cover-generator.component'; import {injectQuery} from '@tanstack/angular-query-experimental'; interface ReadStatusSegment { @@ -48,7 +49,7 @@ interface SeriesCompletion { interface NextUpBook { book: Book; - thumbnailUrl: string; + thumbnailUrl: string | null; isReading: boolean; progressPercent: number | null; } @@ -88,7 +89,8 @@ interface SeriesStats { Tooltip, Divider, TranslocoDirective, - TagComponent + TagComponent, + CoverPlaceholderComponent ], animations: [ trigger('slideInOut', [ @@ -479,7 +481,7 @@ export class SeriesPageComponent implements AfterViewChecked { } } - getBookThumbnailUrl(book: Book): string { + getBookThumbnailUrl(book: Book): string | null { const isAudiobook = book.primaryFile?.bookType === 'AUDIOBOOK'; return isAudiobook ? this.urlHelper.getAudiobookThumbnailUrl(book.id, book.metadata?.audiobookCoverUpdatedOn) diff --git a/frontend/src/app/features/metadata/component/book-metadata-center/metadata-editor/metadata-editor.component.html b/frontend/src/app/features/metadata/component/book-metadata-center/metadata-editor/metadata-editor.component.html index bd036a820..6f536aff0 100644 --- a/frontend/src/app/features/metadata/component/book-metadata-center/metadata-editor/metadata-editor.component.html +++ b/frontend/src/app/features/metadata/component/book-metadata-center/metadata-editor/metadata-editor.component.html @@ -17,14 +17,18 @@ {{ t('ebookCover') }}
} - - + @if (urlHelper.getCoverUrl(book.id, book.metadata?.coverUpdatedOn); as coverUrl) { + + + } @else { + + } @if (isUploading) { } @@ -94,15 +98,19 @@
{{ t('audiobookCover') }}
- - + @if (urlHelper.getAudiobookCoverUrl(book.id, book.metadata?.audiobookCoverUpdatedOn); as coverUrl) { + + + } @else { + + } @if (isUploading) { } diff --git a/frontend/src/app/features/metadata/component/book-metadata-center/metadata-editor/metadata-editor.component.ts b/frontend/src/app/features/metadata/component/book-metadata-center/metadata-editor/metadata-editor.component.ts index ffd4ddbb3..f0ae910b8 100644 --- a/frontend/src/app/features/metadata/component/book-metadata-center/metadata-editor/metadata-editor.component.ts +++ b/frontend/src/app/features/metadata/component/book-metadata-center/metadata-editor/metadata-editor.component.ts @@ -7,6 +7,7 @@ import {Observable, sample} from "rxjs"; import {MessageService} from "primeng/api"; import {Book, BookMetadata, ComicMetadata, MetadataClearFlags, MetadataUpdateWrapper,} from "../../../../book/model/book.model"; import {UrlHelperService} from "../../../../../shared/service/url-helper.service"; +import {CoverPlaceholderComponent} from "../../../../../shared/components/cover-generator/cover-generator.component"; import {ALL_COMIC_METADATA_FIELDS, AUDIOBOOK_METADATA_FIELDS, COMIC_FORM_TO_MODEL_LOCK, COMIC_TEXT_METADATA_FIELDS, COMIC_ARRAY_METADATA_FIELDS, COMIC_TEXTAREA_METADATA_FIELDS, isFieldEmbeddable, hasMetadataWriter} from '../../../../../shared/metadata'; import {FileUpload, FileUploadErrorEvent, FileUploadEvent,} from "primeng/fileupload"; import {HttpResponse} from "@angular/common/http"; @@ -57,6 +58,7 @@ import {CdkDragDrop, CdkDropList, CdkDrag, moveItemInArray} from '@angular/cdk/d TranslocoDirective, CdkDropList, CdkDrag, + CoverPlaceholderComponent, ], }) export class MetadataEditorComponent implements OnInit { diff --git a/frontend/src/app/features/metadata/component/book-metadata-center/metadata-viewer/metadata-tabs/metadata-tabs.component.html b/frontend/src/app/features/metadata/component/book-metadata-center/metadata-viewer/metadata-tabs/metadata-tabs.component.html index ade8ff647..6be2e9d7b 100644 --- a/frontend/src/app/features/metadata/component/book-metadata-center/metadata-viewer/metadata-tabs/metadata-tabs.component.html +++ b/frontend/src/app/features/metadata/component/book-metadata-center/metadata-viewer/metadata-tabs/metadata-tabs.component.html @@ -73,26 +73,34 @@
{{ t('ebookCover') }}
- - + @if (urlHelper.getCoverUrl(book.id, book.metadata?.coverUpdatedOn); as coverUrl) { + + + } @else { + + }
{{ t('audiobookCover') }}
- - + @if (urlHelper.getAudiobookCoverUrl(book.id, book.metadata?.audiobookCoverUpdatedOn); as coverUrl) { + + + } @else { + + }
diff --git a/frontend/src/app/features/metadata/component/book-metadata-center/metadata-viewer/metadata-tabs/metadata-tabs.component.ts b/frontend/src/app/features/metadata/component/book-metadata-center/metadata-viewer/metadata-tabs/metadata-tabs.component.ts index d070f2f86..5a7d1459a 100644 --- a/frontend/src/app/features/metadata/component/book-metadata-center/metadata-viewer/metadata-tabs/metadata-tabs.component.ts +++ b/frontend/src/app/features/metadata/component/book-metadata-center/metadata-viewer/metadata-tabs/metadata-tabs.component.ts @@ -11,6 +11,7 @@ import {Button} from 'primeng/button'; import {Tooltip} from 'primeng/tooltip'; import {Image} from 'primeng/image'; import {UrlHelperService} from '../../../../../../shared/service/url-helper.service'; +import {CoverPlaceholderComponent} from '../../../../../../shared/components/cover-generator/cover-generator.component'; import {BookMetadataManageService} from '../../../../../book/service/book-metadata-manage.service'; import {TranslocoDirective, TranslocoService} from '@jsverse/transloco'; import {AudiobookService} from '../../../../../readers/audiobook-player/audiobook.service'; @@ -73,7 +74,8 @@ export interface DetachBookFileEvent { Tooltip, UpperCasePipe, Image, - TranslocoDirective + TranslocoDirective, + CoverPlaceholderComponent ], templateUrl: './metadata-tabs.component.html', styleUrl: './metadata-tabs.component.scss' diff --git a/frontend/src/app/features/metadata/component/book-metadata-center/metadata-viewer/metadata-viewer.component.html b/frontend/src/app/features/metadata/component/book-metadata-center/metadata-viewer/metadata-viewer.component.html index 9efb94070..75856107e 100644 --- a/frontend/src/app/features/metadata/component/book-metadata-center/metadata-viewer/metadata-viewer.component.html +++ b/frontend/src/app/features/metadata/component/book-metadata-center/metadata-viewer/metadata-viewer.component.html @@ -5,13 +5,17 @@
- - + @if (getBookCoverUrl(book); as coverUrl) { + + + } @else { + + } @if (book?.metadata!.seriesNumber !== null && book?.metadata!.seriesNumber !== undefined) {
diff --git a/frontend/src/app/features/metadata/component/book-metadata-center/metadata-viewer/metadata-viewer.component.ts b/frontend/src/app/features/metadata/component/book-metadata-center/metadata-viewer/metadata-viewer.component.ts index 068e1a5c9..308ba1c24 100644 --- a/frontend/src/app/features/metadata/component/book-metadata-center/metadata-viewer/metadata-viewer.component.ts +++ b/frontend/src/app/features/metadata/component/book-metadata-center/metadata-viewer/metadata-viewer.component.ts @@ -7,6 +7,7 @@ import {Rating, RatingRateEvent} from 'primeng/rating'; import {FormsModule} from '@angular/forms'; import {Book, BookFile, BookMetadata, BookRecommendation, BookType, ComicMetadata, FileInfo, ReadStatus} from '../../../../book/model/book.model'; import {UrlHelperService} from '../../../../../shared/service/url-helper.service'; +import {CoverPlaceholderComponent} from '../../../../../shared/components/cover-generator/cover-generator.component'; import {UserService} from '../../../../settings/user-management/user.service'; import {SplitButton} from 'primeng/splitbutton'; import {ConfirmationService, MenuItem, MessageService} from 'primeng/api'; @@ -45,7 +46,7 @@ import DOMPurify from 'dompurify'; standalone: true, templateUrl: './metadata-viewer.component.html', styleUrl: './metadata-viewer.component.scss', - imports: [Button, Rating, FormsModule, SplitButton, NgClass, Tooltip, DecimalPipe, ProgressBar, Menu, DatePicker, ProgressSpinner, TieredMenu, Image, TagComponent, MetadataTabsComponent, TranslocoDirective, TranslocoPipe, Dialog, Checkbox] + imports: [Button, Rating, FormsModule, SplitButton, NgClass, Tooltip, DecimalPipe, ProgressBar, Menu, DatePicker, ProgressSpinner, TieredMenu, Image, TagComponent, MetadataTabsComponent, TranslocoDirective, TranslocoPipe, Dialog, Checkbox, CoverPlaceholderComponent] }) export class MetadataViewerComponent implements OnInit, OnChanges, AfterViewChecked { private currentBook = signal(null); @@ -1281,7 +1282,7 @@ export class MetadataViewerComponent implements OnInit, OnChanges, AfterViewChec return !this.hasAnyFiles(book); } - getBookCoverUrl(book: Book): string { + getBookCoverUrl(book: Book): string | null { const isAudiobook = book.primaryFile?.bookType === 'AUDIOBOOK'; return isAudiobook ? this.urlHelper.getAudiobookCoverUrl(book.id, book.metadata?.audiobookCoverUpdatedOn) diff --git a/frontend/src/app/features/notebook/components/notebook/notebook.component.html b/frontend/src/app/features/notebook/components/notebook/notebook.component.html index 99e9fa7e5..035a3fc67 100644 --- a/frontend/src/app/features/notebook/components/notebook/notebook.component.html +++ b/frontend/src/app/features/notebook/components/notebook/notebook.component.html @@ -138,7 +138,11 @@
- + @if (group.thumbnailUrl) { + + } @else { + + }
{{ group.bookTitle }} diff --git a/frontend/src/app/features/notebook/components/notebook/notebook.component.ts b/frontend/src/app/features/notebook/components/notebook/notebook.component.ts index fc3867a10..59b0f662c 100644 --- a/frontend/src/app/features/notebook/components/notebook/notebook.component.ts +++ b/frontend/src/app/features/notebook/components/notebook/notebook.component.ts @@ -12,12 +12,13 @@ import {TranslocoDirective, TranslocoService} from '@jsverse/transloco'; import {NotebookService} from '../../service/notebook.service'; import {NotebookEntry, NotebookPage} from '../../model/notebook.model'; import {UrlHelperService} from '../../../../shared/service/url-helper.service'; +import {CoverPlaceholderComponent} from '../../../../shared/components/cover-generator/cover-generator.component'; import {PageTitleService} from '../../../../shared/service/page-title.service'; interface BookGroup { bookId: number; bookTitle: string; - thumbnailUrl: string; + thumbnailUrl: string | null; entries: NotebookEntry[]; } @@ -43,6 +44,7 @@ const EMPTY_PAGE: NotebookPage = { TooltipModule, Paginator, TranslocoDirective, + CoverPlaceholderComponent, ], templateUrl: './notebook.component.html', styleUrls: ['./notebook.component.scss'], @@ -184,7 +186,7 @@ export class NotebookComponent implements OnInit, OnDestroy { bookId: entry.bookId, bookTitle: entry.bookTitle, thumbnailUrl: isAudiobook - ? this.urlHelper.getAudiobookThumbnailUrl(entry.bookId) + ? this.urlHelper.getDirectAudiobookThumbnailUrl(entry.bookId) : this.urlHelper.getDirectThumbnailUrl(entry.bookId), entries: [], }); diff --git a/frontend/src/app/features/readers/cbx-reader/layout/sidebar/cbx-sidebar.component.html b/frontend/src/app/features/readers/cbx-reader/layout/sidebar/cbx-sidebar.component.html index 8028ea144..bf82cfd90 100644 --- a/frontend/src/app/features/readers/cbx-reader/layout/sidebar/cbx-sidebar.component.html +++ b/frontend/src/app/features/readers/cbx-reader/layout/sidebar/cbx-sidebar.component.html @@ -8,6 +8,8 @@ alt="Book cover" class="book-cover" /> + } @else { + }

{{ bookInfo().title }}

diff --git a/frontend/src/app/features/readers/cbx-reader/layout/sidebar/cbx-sidebar.component.ts b/frontend/src/app/features/readers/cbx-reader/layout/sidebar/cbx-sidebar.component.ts index b8585ad07..7ceec9b51 100644 --- a/frontend/src/app/features/readers/cbx-reader/layout/sidebar/cbx-sidebar.component.ts +++ b/frontend/src/app/features/readers/cbx-reader/layout/sidebar/cbx-sidebar.component.ts @@ -5,13 +5,14 @@ import {TranslocoPipe} from '@jsverse/transloco'; import {CbxSidebarService, CbxSidebarTab} from './cbx-sidebar.service'; import {BookNoteV2} from '../../../../../shared/service/book-note-v2.service'; import {ReaderIconComponent} from '../../../ebook-reader'; +import {CoverPlaceholderComponent} from '../../../../../shared/components/cover-generator/cover-generator.component'; @Component({ selector: 'app-cbx-sidebar', standalone: true, templateUrl: './cbx-sidebar.component.html', styleUrls: ['./cbx-sidebar.component.scss'], - imports: [CommonModule, FormsModule, TranslocoPipe, ReaderIconComponent, DatePipe] + imports: [CommonModule, FormsModule, TranslocoPipe, ReaderIconComponent, DatePipe, CoverPlaceholderComponent] }) export class CbxSidebarComponent { private readonly sidebarService = inject(CbxSidebarService); diff --git a/frontend/src/app/features/readers/ebook-reader/dialogs/metadata-dialog.component.html b/frontend/src/app/features/readers/ebook-reader/dialogs/metadata-dialog.component.html index 1c641c109..67cfa1f2f 100644 --- a/frontend/src/app/features/readers/ebook-reader/dialogs/metadata-dialog.component.html +++ b/frontend/src/app/features/readers/ebook-reader/dialogs/metadata-dialog.component.html @@ -12,9 +12,7 @@ @if (bookCoverUrl) { } @else { -
- 📚 -
+ }
diff --git a/frontend/src/app/features/readers/ebook-reader/dialogs/metadata-dialog.component.scss b/frontend/src/app/features/readers/ebook-reader/dialogs/metadata-dialog.component.scss index 88c63b67b..b17f9f426 100644 --- a/frontend/src/app/features/readers/ebook-reader/dialogs/metadata-dialog.component.scss +++ b/frontend/src/app/features/readers/ebook-reader/dialogs/metadata-dialog.component.scss @@ -179,14 +179,6 @@ $transition-normal: 200ms ease; max-height: 240px; } - .placeholder-icon { - font-size: 56px; - opacity: 0.3; - - @media (width <= 768px) { - font-size: 44px; - } - } } .metadata-section { diff --git a/frontend/src/app/features/readers/ebook-reader/dialogs/metadata-dialog.component.ts b/frontend/src/app/features/readers/ebook-reader/dialogs/metadata-dialog.component.ts index a0f45cfe2..7c02c8238 100644 --- a/frontend/src/app/features/readers/ebook-reader/dialogs/metadata-dialog.component.ts +++ b/frontend/src/app/features/readers/ebook-reader/dialogs/metadata-dialog.component.ts @@ -1,14 +1,14 @@ import {Component, EventEmitter, inject, Input, Output} from '@angular/core'; import {CommonModule} from '@angular/common'; -import {TranslocoDirective} from '@jsverse/transloco'; -import {TranslocoService} from '@jsverse/transloco'; +import {TranslocoDirective, TranslocoService} from '@jsverse/transloco'; import {Book} from '../../../book/model/book.model'; import {UrlHelperService} from '../../../../shared/service/url-helper.service'; +import {CoverPlaceholderComponent} from '../../../../shared/components/cover-generator/cover-generator.component'; @Component({ selector: 'app-reader-book-metadata-dialog', standalone: true, - imports: [CommonModule, TranslocoDirective], + imports: [CommonModule, TranslocoDirective, CoverPlaceholderComponent], templateUrl: './metadata-dialog.component.html', styleUrls: ['./metadata-dialog.component.scss'] }) diff --git a/frontend/src/app/features/readers/ebook-reader/layout/sidebar/sidebar.component.html b/frontend/src/app/features/readers/ebook-reader/layout/sidebar/sidebar.component.html index 20d7c94dd..6d4831a0c 100644 --- a/frontend/src/app/features/readers/ebook-reader/layout/sidebar/sidebar.component.html +++ b/frontend/src/app/features/readers/ebook-reader/layout/sidebar/sidebar.component.html @@ -14,6 +14,16 @@ tabindex="0" (keydown.enter)="onCoverClick()" /> + } @else { + }

{{ bookInfo().title }}

diff --git a/frontend/src/app/features/readers/ebook-reader/layout/sidebar/sidebar.component.ts b/frontend/src/app/features/readers/ebook-reader/layout/sidebar/sidebar.component.ts index 7f1a6cd2d..ed8a7b69b 100644 --- a/frontend/src/app/features/readers/ebook-reader/layout/sidebar/sidebar.component.ts +++ b/frontend/src/app/features/readers/ebook-reader/layout/sidebar/sidebar.component.ts @@ -5,13 +5,14 @@ import {TranslocoDirective} from '@jsverse/transloco'; import {TocItem} from 'epubjs'; import {ReaderSidebarService, SidebarTab} from './sidebar.service'; import {ReaderIconComponent} from '../../shared/icon.component'; +import {CoverPlaceholderComponent} from '../../../../../shared/components/cover-generator/cover-generator.component'; @Component({ selector: 'app-reader-sidebar', standalone: true, templateUrl: './sidebar.component.html', styleUrls: ['./sidebar.component.scss'], - imports: [CommonModule, FormsModule, TranslocoDirective, ReaderIconComponent] + imports: [CommonModule, FormsModule, TranslocoDirective, ReaderIconComponent, CoverPlaceholderComponent] }) export class ReaderSidebarComponent { private readonly sidebarService = inject(ReaderSidebarService); diff --git a/frontend/src/app/features/series-browser/components/series-card/series-card.component.html b/frontend/src/app/features/series-browser/components/series-card/series-card.component.html index c00e9c6e6..476d22270 100644 --- a/frontend/src/app/features/series-browser/components/series-card/series-card.component.html +++ b/frontend/src/app/features/series-browser/components/series-card/series-card.component.html @@ -1,13 +1,22 @@
@for (book of series.coverBooks; track book.id; let i = $index) { - + @if (getCoverUrl(i); as coverUrl) { + + } @else { + + } }
diff --git a/frontend/src/app/features/series-browser/components/series-card/series-card.component.spec.ts b/frontend/src/app/features/series-browser/components/series-card/series-card.component.spec.ts index ad20a89be..6821513f2 100644 --- a/frontend/src/app/features/series-browser/components/series-card/series-card.component.spec.ts +++ b/frontend/src/app/features/series-browser/components/series-card/series-card.component.spec.ts @@ -93,7 +93,7 @@ describe('SeriesCardComponent', () => { it('builds thumbnail URLs from ebook and audiobook covers', () => { expect(component.getCoverUrl(0)).toBe('thumb:1:2026-03-01'); expect(component.getCoverUrl(1)).toBe('audio:2:2026-03-02'); - expect(component.getCoverUrl(99)).toBe(''); + expect(component.getCoverUrl(99)).toBeNull(); }); it('emits a card click and stops propagation', () => { diff --git a/frontend/src/app/features/series-browser/components/series-card/series-card.component.ts b/frontend/src/app/features/series-browser/components/series-card/series-card.component.ts index 2cd4443cf..7a8e44662 100644 --- a/frontend/src/app/features/series-browser/components/series-card/series-card.component.ts +++ b/frontend/src/app/features/series-browser/components/series-card/series-card.component.ts @@ -7,6 +7,7 @@ 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'; +import {CoverPlaceholderComponent} from '../../../../shared/components/cover-generator/cover-generator.component'; @Component({ selector: 'app-series-card', @@ -14,7 +15,7 @@ import {UrlHelperService} from '../../../../shared/service/url-helper.service'; changeDetection: ChangeDetectionStrategy.OnPush, templateUrl: './series-card.component.html', styleUrls: ['./series-card.component.scss'], - imports: [NgClass, ProgressBar, Button, Tooltip, TranslocoPipe] + imports: [NgClass, ProgressBar, Button, Tooltip, TranslocoPipe, CoverPlaceholderComponent] }) export class SeriesCardComponent { @@ -34,9 +35,9 @@ export class SeriesCardComponent { return this.series.authors.slice(0, 2).join(', ') + ' +' + (this.series.authors.length - 2); } - getCoverUrl(index: number): string { + getCoverUrl(index: number): string | null { const book = this.series.coverBooks[index]; - if (!book) return ''; + if (!book) return null; const isAudiobook = book.primaryFile?.bookType === 'AUDIOBOOK'; return isAudiobook ? this.urlHelper.getAudiobookThumbnailUrl(book.id, book.metadata?.audiobookCoverUpdatedOn) diff --git a/frontend/src/app/shared/components/cover-generator/cover-generator.component.spec.ts b/frontend/src/app/shared/components/cover-generator/cover-generator.component.spec.ts index 5a1004d55..695719fe6 100644 --- a/frontend/src/app/shared/components/cover-generator/cover-generator.component.spec.ts +++ b/frontend/src/app/shared/components/cover-generator/cover-generator.component.spec.ts @@ -1,76 +1,67 @@ import {ComponentFixture, TestBed} from '@angular/core/testing'; import {afterEach, beforeEach, describe, expect, it} from 'vitest'; -import {CoverGeneratorComponent} from './cover-generator.component'; +import {CoverPlaceholderComponent, coverColorFor} from './cover-generator.component'; -describe('CoverGeneratorComponent', () => { - let fixture: ComponentFixture; - let component: CoverGeneratorComponent; +describe('CoverPlaceholderComponent', () => { + let fixture: ComponentFixture; beforeEach(async () => { await TestBed.configureTestingModule({ - imports: [CoverGeneratorComponent], + imports: [CoverPlaceholderComponent], }).compileComponents(); - fixture = TestBed.createComponent(CoverGeneratorComponent); - component = fixture.componentInstance; + fixture = TestBed.createComponent(CoverPlaceholderComponent); }); afterEach(() => { TestBed.resetTestingModule(); }); - function decodeCover(dataUrl: string): string { - const encoded = dataUrl.replace('data:image/svg+xml;base64,', ''); - return decodeURIComponent( - Array.from(atob(encoded)) - .map(char => `%${char.charCodeAt(0).toString(16).padStart(2, '0')}`) - .join('') - ); - } + it('renders the title and author text', () => { + fixture.componentRef.setInput('title', 'Dune'); + fixture.componentRef.setInput('author', 'Frank Herbert'); + fixture.detectChanges(); - it('generates a base64-encoded ebook cover with escaped title and author text', () => { - component.title = 'Dune & '; - component.author = 'Frank "Herbert"'; - - const svg = decodeCover(component.generateCover()); - - expect(svg).toContain(' { - component.title = 'Project Hail Mary'; - component.author = 'Andy Weir'; - component.isSquare = true; + it('applies the computed background color', () => { + fixture.componentRef.setInput('title', 'Dune'); + fixture.componentRef.setInput('author', 'Frank Herbert'); + fixture.detectChanges(); - const svg = decodeCover(component.generateCover()); - - expect(svg).toContain('width="250" height="250"'); - expect(svg).toContain('L-6,8 L8,0 Z'); + const container = fixture.nativeElement.querySelector('.placeholder'); + expect(container.style.background).toBeTruthy(); }); - it('wraps and truncates long titles into multiple lines', () => { - component.title = 'A Very Long Book Title That Keeps Going Beyond The Expected Width Of The Cover'; - component.author = 'Someone'; + it('applies the correct size class', () => { + fixture.componentRef.setInput('title', 'Test'); + fixture.componentRef.setInput('size', 'lg'); + fixture.detectChanges(); - const svg = decodeCover(component.generateCover()); + const container = fixture.nativeElement.querySelector('.placeholder'); + expect(container.classList.contains('size-lg')).toBe(true); + }); +}); - expect((svg.match(/ { + it('returns a deterministic color for the same inputs', () => { + const first = coverColorFor('Dune', 'Frank Herbert'); + const second = coverColorFor('Dune', 'Frank Herbert'); + expect(first).toBe(second); }); - it('produces deterministic palette selection for the same inputs', () => { - component.title = 'Dune'; - component.author = 'Frank Herbert'; + it('returns different colors for different inputs', () => { + const a = coverColorFor('Dune', 'Frank Herbert'); + const b = coverColorFor('Project Hail Mary', 'Andy Weir'); + expect(a).not.toBe(b); + }); - const first = component.generateCover(); - const second = component.generateCover(); - - expect(first).toBe(second); + it('returns a valid hex color', () => { + const color = coverColorFor('Test', 'Author'); + expect(color).toMatch(/^#[0-9A-Fa-f]{6}$/); }); }); diff --git a/frontend/src/app/shared/components/cover-generator/cover-generator.component.ts b/frontend/src/app/shared/components/cover-generator/cover-generator.component.ts index 267cdcf8e..01f714f09 100644 --- a/frontend/src/app/shared/components/cover-generator/cover-generator.component.ts +++ b/frontend/src/app/shared/components/cover-generator/cover-generator.component.ts @@ -1,235 +1,105 @@ -import {ChangeDetectionStrategy, Component, Input} from '@angular/core'; +import {ChangeDetectionStrategy, Component, computed, input} from '@angular/core'; + +const COVER_COLORS = [ + '#1a1a2e', '#2d3436', '#0c3547', '#1e3d59', '#2c2c54', '#1b262c', + '#2B2D42', '#3D405B', '#463F3A', '#1B2838', '#2E4057', '#4A3728', +]; + +function hashString(str: string): number { + let hash = 0; + for (let i = 0; i < str.length; i++) { + hash = ((hash << 5) - hash) + str.charCodeAt(i); + hash = hash & hash; + } + return Math.abs(hash); +} + +export function coverColorFor(title: string, author: string): string { + return COVER_COLORS[hashString(title + author) % COVER_COLORS.length]; +} + +export type CoverPlaceholderSize = 'sm' | 'md' | 'lg'; @Component({ + selector: 'app-cover-placeholder', standalone: true, changeDetection: ChangeDetectionStrategy.OnPush, - template: '' + template: ` +
+
{{ title() }}
+
{{ author() }}
+
+ `, + styles: [` + :host { + display: block; + width: 100%; + height: 100%; + } + + .placeholder { + width: 100%; + height: 100%; + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + text-align: center; + } + + .placeholder.size-sm { padding: 0.5rem; } + .placeholder.size-md { padding: 1rem; } + .placeholder.size-lg { padding: 1.5rem; } + + .placeholder-title { + color: rgba(255, 255, 255, 0.9); + font-weight: 600; + line-height: 1.375; + display: -webkit-box; + -webkit-line-clamp: 3; + -webkit-box-orient: vertical; + overflow: hidden; + } + + .size-sm .placeholder-title { + font-size: 11px; + margin-bottom: 2px; + } + + .size-md .placeholder-title { + font-size: 13px; + margin-bottom: 4px; + } + + .size-lg .placeholder-title { + font-size: 15px; + margin-bottom: 8px; + } + + .placeholder-author { + color: rgba(255, 255, 255, 0.5); + letter-spacing: 0.025em; + display: -webkit-box; + -webkit-line-clamp: 1; + -webkit-box-orient: vertical; + overflow: hidden; + } + + .size-sm .placeholder-author { font-size: 9px; } + .size-md .placeholder-author { font-size: 11px; } + .size-lg .placeholder-author { font-size: 12px; } + `] }) -export class CoverGeneratorComponent { - @Input() title: string = ''; - @Input() author: string = ''; - @Input() isSquare: boolean = false; +export class CoverPlaceholderComponent { + title = input(''); + author = input(''); + size = input('md'); - private wrapText(text: string, maxLineLength: number): string[] { - const words = text.split(' '); - const lines: string[] = []; - let currentLine = ''; - - words.forEach(word => { - if (word.length > maxLineLength) { - if (currentLine.length > 0) { - lines.push(currentLine); - currentLine = ''; - } - lines.push(word); - } else if (currentLine.length + word.length + 1 > maxLineLength) { - lines.push(currentLine); - currentLine = word; - } else { - currentLine += (currentLine.length > 0 ? ' ' : '') + word; - } - }); - - if (currentLine.length > 0) { - lines.push(currentLine); - } - - return lines; - } - - private truncateText(text: string, maxLength: number): string { - if (text.length <= maxLength) return text; - return text.substring(0, maxLength - 3) + '...'; - } - - private escapeXml(text: string): string { - return text - .replace(/&/g, '&') - .replace(//g, '>') - .replace(/"/g, '"') - .replace(/'/g, '''); - } - - private hashString(str: string): number { - let hash = 0; - for (let i = 0; i < str.length; i++) { - const char = str.charCodeAt(i); - hash = ((hash << 5) - hash) + char; - hash = hash & hash; - } - return Math.abs(hash); - } - - generateCover(): string { - const width = 250; - const height = this.isSquare ? 250 : 350; - const hash = this.hashString(this.title + this.author); - - if (this.isSquare) { - return this.generateAudiobookCover(width, height, hash); - } else { - return this.generateEbookCover(width, height, hash); - } - } - - private generateEbookCover(width: number, height: number, hash: number): string { - const palettes = [ - {bg1: '#1a1a2e', bg2: '#16213e', accent: '#e94560', text: '#eaeaea', textSecondary: '#b8b8b8'}, - {bg1: '#2d3436', bg2: '#636e72', accent: '#74b9ff', text: '#ffffff', textSecondary: '#dfe6e9'}, - {bg1: '#0c3547', bg2: '#1a5276', accent: '#f39c12', text: '#ecf0f1', textSecondary: '#bdc3c7'}, - {bg1: '#1e3d59', bg2: '#17263a', accent: '#ffc13b', text: '#f5f0e1', textSecondary: '#c7b198'}, - {bg1: '#2c2c54', bg2: '#474787', accent: '#ff793f', text: '#f8f8f8', textSecondary: '#d1ccc0'}, - {bg1: '#1b262c', bg2: '#0f4c75', accent: '#3282b8', text: '#bbe1fa', textSecondary: '#8fbdd3'}, - ]; - - const palette = palettes[hash % palettes.length]; - const {titleLines, authorLines, titleFontSize, authorFontSize} = this.processText(false); - - const titleLineHeight = titleFontSize * 1.3; - const titleStartY = 80; - - const titleElements = titleLines.map((line, index) => { - const y = titleStartY + (index * titleLineHeight); - return `${this.escapeXml(line)}`; - }).join('\n'); - - const authorLineHeight = authorFontSize * 1.3; - const authorStartY = height - 50 - ((authorLines.length - 1) * authorLineHeight); - - const authorElements = authorLines.map((line, index) => { - const y = authorStartY + (index * authorLineHeight); - return `${this.escapeXml(line)}`; - }).join('\n'); - - const decorY = titleStartY + (titleLines.length * titleLineHeight) + 20; - - const svg = ` - - - - - - - - - - - - - - - ${titleElements} - - - ${authorElements} - - `; - - return this.svgToDataUrl(svg); - } - - private generateAudiobookCover(width: number, height: number, hash: number): string { - const palettes = [ - {bg1: '#667eea', bg2: '#764ba2', accent: '#ffffff', text: '#ffffff', textSecondary: '#e8e8e8'}, - {bg1: '#f093fb', bg2: '#f5576c', accent: '#ffffff', text: '#ffffff', textSecondary: '#ffeaea'}, - {bg1: '#4facfe', bg2: '#00f2fe', accent: '#ffffff', text: '#1a1a2e', textSecondary: '#2d3436'}, - {bg1: '#43e97b', bg2: '#38f9d7', accent: '#ffffff', text: '#1a1a2e', textSecondary: '#2d3436'}, - {bg1: '#fa709a', bg2: '#fee140', accent: '#ffffff', text: '#1a1a2e', textSecondary: '#2d3436'}, - {bg1: '#a18cd1', bg2: '#fbc2eb', accent: '#ffffff', text: '#2d3436', textSecondary: '#4a4a4a'}, - ]; - - const palette = palettes[hash % palettes.length]; - const {titleLines, authorLines, titleFontSize, authorFontSize} = this.processText(true); - - const titleLineHeight = titleFontSize * 1.3; - const titleStartY = 70; - - const titleElements = titleLines.map((line, index) => { - const y = titleStartY + (index * titleLineHeight); - return `${this.escapeXml(line)}`; - }).join('\n'); - - const authorLineHeight = authorFontSize * 1.3; - const authorStartY = height - 40 - ((authorLines.length - 1) * authorLineHeight); - - const authorElements = authorLines.map((line, index) => { - const y = authorStartY + (index * authorLineHeight); - return `${this.escapeXml(line)}`; - }).join('\n'); - - const iconY = titleStartY + (titleLines.length * titleLineHeight) + 25; - - const svg = ` - - - - - - - - - - ${titleElements} - - - - - ${authorElements} - `; - - return this.svgToDataUrl(svg); - } - - private processText(isSquare: boolean): { - titleLines: string[]; - authorLines: string[]; - titleFontSize: number; - authorFontSize: number; - } { - const maxTitleLength = 60; - const maxAuthorLength = 40; - const truncatedTitle = this.truncateText(this.title, maxTitleLength); - const truncatedAuthor = this.truncateText(this.author, maxAuthorLength); - - const maxLineLength = 14; - const maxTitleLines = isSquare ? 3 : 4; - const maxAuthorLines = isSquare ? 2 : 3; - - let titleLines = this.wrapText(truncatedTitle, maxLineLength); - let authorLines = this.wrapText(truncatedAuthor, maxLineLength); - - if (titleLines.length > maxTitleLines) { - titleLines = titleLines.slice(0, maxTitleLines); - titleLines[maxTitleLines - 1] = this.truncateText(titleLines[maxTitleLines - 1], maxLineLength); - } - - if (authorLines.length > maxAuthorLines) { - authorLines = authorLines.slice(0, maxAuthorLines); - authorLines[maxAuthorLines - 1] = this.truncateText(authorLines[maxAuthorLines - 1], maxLineLength); - } - - const titleFontSize = this.calculateTitleFontSize(titleLines.length); - const authorFontSize = this.calculateAuthorFontSize(authorLines.length); - - return {titleLines, authorLines, titleFontSize, authorFontSize}; - } - - private calculateTitleFontSize(lineCount: number): number { - if (lineCount <= 2) return 28; - if (lineCount === 3) return 24; - return 20; - } - - private calculateAuthorFontSize(lineCount: number): number { - if (lineCount <= 2) return 18; - return 16; - } - - private svgToDataUrl(svg: string): string { - const base64 = btoa(encodeURIComponent(svg).replace(/%([0-9A-F]{2})/g, (_, p1) => { - return String.fromCharCode(parseInt(p1, 16)); - })); - return `data:image/svg+xml;base64,${base64}`; - } + protected color = computed(() => coverColorFor(this.title(), this.author())); } diff --git a/frontend/src/app/shared/service/url-helper.service.spec.ts b/frontend/src/app/shared/service/url-helper.service.spec.ts index 6799e2ca2..ad97d7b0a 100644 --- a/frontend/src/app/shared/service/url-helper.service.spec.ts +++ b/frontend/src/app/shared/service/url-helper.service.spec.ts @@ -4,8 +4,6 @@ import {afterEach, beforeEach, describe, expect, it, vi} from 'vitest'; import {API_CONFIG} from '../../core/config/api-config'; import {Book, BookType} from '../../features/book/model/book.model'; -import {BookService} from '../../features/book/service/book.service'; -import {CoverGeneratorComponent} from '../components/cover-generator/cover-generator.component'; import {AuthService} from './auth.service'; import {UrlHelperService} from './url-helper.service'; @@ -14,24 +12,12 @@ describe('UrlHelperService', () => { getInternalAccessToken: vi.fn(), }; - const bookServiceStub = { - findBookById: vi.fn(), - }; - const routerStub = { createUrlTree: vi.fn((commands: unknown[], extras?: unknown) => ({commands, extras})), }; let service: UrlHelperService; - const bookWithMetadata = { - id: 42, - metadata: { - title: 'The Testing Atlas', - authors: ['Ada Lovelace', 'Grace Hopper'], - }, - } as Book; - const supportedReadingRoutes: {bookType: BookType; readerSegment: string}[] = [ {bookType: 'PDF', readerSegment: 'pdf-reader'}, {bookType: 'EPUB', readerSegment: 'ebook-reader'}, @@ -44,15 +30,12 @@ describe('UrlHelperService', () => { beforeEach(() => { authServiceStub.getInternalAccessToken.mockReturnValue('token-123'); - bookServiceStub.findBookById.mockReset(); - bookServiceStub.findBookById.mockReturnValue(undefined); routerStub.createUrlTree.mockClear(); TestBed.configureTestingModule({ providers: [ UrlHelperService, {provide: AuthService, useValue: authServiceStub}, - {provide: BookService, useValue: bookServiceStub}, {provide: Router, useValue: routerStub}, ], }); @@ -64,17 +47,8 @@ describe('UrlHelperService', () => { vi.restoreAllMocks(); }); - it('generates a portrait cover when cached metadata exists and no updated marker is provided', () => { - bookServiceStub.findBookById.mockReturnValue(bookWithMetadata); - - const generateCoverSpy = vi.spyOn(CoverGeneratorComponent.prototype, 'generateCover').mockImplementation(function (this: CoverGeneratorComponent) { - return `${this.title}|${this.author}|${this.isSquare ? 'square' : 'portrait'}`; - }); - - const url = service.getThumbnailUrl(42); - - expect(generateCoverSpy).toHaveBeenCalledTimes(1); - expect(url).toBe('The Testing Atlas|Ada Lovelace, Grace Hopper|portrait'); + it('returns null for thumbnail when no coverUpdatedOn is provided', () => { + expect(service.getThumbnailUrl(42)).toBeNull(); }); it('appends the token to thumbnail urls that already have a cache key', () => { @@ -83,6 +57,22 @@ describe('UrlHelperService', () => { expect(url).toBe(`${API_CONFIG.BASE_URL}/api/v1/media/book/42/thumbnail?updated-2024&token=token-123`); }); + it('returns null for cover url when no coverUpdatedOn is provided', () => { + expect(service.getCoverUrl(42)).toBeNull(); + }); + + it('returns null for audiobook cover when no updated marker is provided', () => { + expect(service.getAudiobookCoverUrl(42)).toBeNull(); + }); + + it('returns null for audiobook thumbnail when no updated marker is provided', () => { + expect(service.getAudiobookThumbnailUrl(42)).toBeNull(); + }); + + it('uses the audiobook media url when an updated marker is present', () => { + expect(service.getAudiobookThumbnailUrl(42, 'updated-2024')).toBe(`${API_CONFIG.BASE_URL}/api/v1/media/book/42/audiobook-thumbnail?updated-2024&token=token-123`); + }); + it('returns direct thumbnail and backup urls without a token when auth is unavailable', () => { authServiceStub.getInternalAccessToken.mockReturnValue(null); @@ -90,23 +80,6 @@ describe('UrlHelperService', () => { expect(service.getBackupCoverUrl(42)).toBe(`${API_CONFIG.BASE_URL}/api/v1/media/book/42/backup-cover`); }); - it('generates a square audiobook cover when cached metadata exists', () => { - bookServiceStub.findBookById.mockReturnValue(bookWithMetadata); - - const generateCoverSpy = vi.spyOn(CoverGeneratorComponent.prototype, 'generateCover').mockImplementation(function (this: CoverGeneratorComponent) { - return `${this.title}|${this.author}|${this.isSquare ? 'square' : 'portrait'}`; - }); - - const url = service.getAudiobookCoverUrl(42); - - expect(generateCoverSpy).toHaveBeenCalledTimes(1); - expect(url).toBe('The Testing Atlas|Ada Lovelace, Grace Hopper|square'); - }); - - it('uses the audiobook media url when an updated marker is present', () => { - expect(service.getAudiobookThumbnailUrl(42, 'updated-2024')).toBe(`${API_CONFIG.BASE_URL}/api/v1/media/book/42/audiobook-thumbnail?updated-2024&token=token-123`); - }); - it.each(supportedReadingRoutes)('routes %s books to the correct reader path', ({bookType, readerSegment}: {bookType: BookType; readerSegment: string}) => { const book = { id: 77, diff --git a/frontend/src/app/shared/service/url-helper.service.ts b/frontend/src/app/shared/service/url-helper.service.ts index cd4d38eae..ddfaa9033 100644 --- a/frontend/src/app/shared/service/url-helper.service.ts +++ b/frontend/src/app/shared/service/url-helper.service.ts @@ -1,10 +1,8 @@ import {inject, Injectable} from '@angular/core'; import {API_CONFIG} from '../../core/config/api-config'; import {AuthService} from './auth.service'; -import {BookService} from '../../features/book/service/book.service'; -import {CoverGeneratorComponent} from '../components/cover-generator/cover-generator.component'; import {Router} from '@angular/router'; -import {Book,BookType} from '../../features/book/model/book.model'; +import {Book, BookType} from '../../features/book/model/book.model'; @Injectable({ providedIn: 'root' @@ -13,7 +11,6 @@ export class UrlHelperService { private readonly baseUrl = API_CONFIG.BASE_URL; private readonly mediaBaseUrl = `${this.baseUrl}/api/v1/media`; private authService = inject(AuthService); - private bookService = inject(BookService); private router = inject(Router); private getToken(): string | null { @@ -25,21 +22,9 @@ export class UrlHelperService { return token ? `${url}${url.includes('?') ? '&' : '?'}token=${token}` : url; } - getThumbnailUrl(bookId: number, coverUpdatedOn?: string): string { - if (!coverUpdatedOn) { - const book = this.bookService.findBookById(bookId); - if (book && book.metadata) { - const coverGenerator = new CoverGeneratorComponent(); - coverGenerator.title = book.metadata.title || ''; - coverGenerator.author = (book.metadata.authors || []).join(', '); - return coverGenerator.generateCover(); - } - } - let url = `${this.mediaBaseUrl}/book/${bookId}/thumbnail`; - if (coverUpdatedOn) { - url += `?${coverUpdatedOn}`; - } - return this.appendToken(url); + getThumbnailUrl(bookId: number, coverUpdatedOn?: string): string | null { + if (!coverUpdatedOn) return null; + return this.appendToken(`${this.mediaBaseUrl}/book/${bookId}/thumbnail?${coverUpdatedOn}`); } getDirectThumbnailUrl(bookId: number, coverUpdatedOn?: string): string { @@ -50,21 +35,9 @@ export class UrlHelperService { return this.appendToken(url); } - getCoverUrl(bookId: number, coverUpdatedOn?: string): string { - if (!coverUpdatedOn) { - const book = this.bookService.findBookById(bookId); - if (book && book.metadata) { - const coverGenerator = new CoverGeneratorComponent(); - coverGenerator.title = book.metadata.title || ''; - coverGenerator.author = (book.metadata.authors || []).join(', '); - return coverGenerator.generateCover(); - } - } - let url = `${this.mediaBaseUrl}/book/${bookId}/cover`; - if (coverUpdatedOn) { - url += `?${coverUpdatedOn}`; - } - return this.appendToken(url); + getCoverUrl(bookId: number, coverUpdatedOn?: string): string | null { + if (!coverUpdatedOn) return null; + return this.appendToken(`${this.mediaBaseUrl}/book/${bookId}/cover?${coverUpdatedOn}`); } getBackupCoverUrl(bookId: number): string { @@ -72,35 +45,17 @@ export class UrlHelperService { return this.appendToken(url); } - getAudiobookCoverUrl(bookId: number, audiobookCoverUpdatedOn?: string): string { - if (!audiobookCoverUpdatedOn) { - const book = this.bookService.findBookById(bookId); - if (book && book.metadata) { - const coverGenerator = new CoverGeneratorComponent(); - coverGenerator.title = book.metadata.title || ''; - coverGenerator.author = (book.metadata.authors || []).join(', '); - coverGenerator.isSquare = true; - return coverGenerator.generateCover(); - } - } - let url = `${this.mediaBaseUrl}/book/${bookId}/audiobook-cover`; - if (audiobookCoverUpdatedOn) { - url += `?${audiobookCoverUpdatedOn}`; - } - return this.appendToken(url); + getAudiobookCoverUrl(bookId: number, audiobookCoverUpdatedOn?: string): string | null { + if (!audiobookCoverUpdatedOn) return null; + return this.appendToken(`${this.mediaBaseUrl}/book/${bookId}/audiobook-cover?${audiobookCoverUpdatedOn}`); } - getAudiobookThumbnailUrl(bookId: number, audiobookCoverUpdatedOn?: string): string { - if (!audiobookCoverUpdatedOn) { - const book = this.bookService.findBookById(bookId); - if (book && book.metadata) { - const coverGenerator = new CoverGeneratorComponent(); - coverGenerator.title = book.metadata.title || ''; - coverGenerator.author = (book.metadata.authors || []).join(', '); - coverGenerator.isSquare = true; - return coverGenerator.generateCover(); - } - } + getAudiobookThumbnailUrl(bookId: number, audiobookCoverUpdatedOn?: string): string | null { + if (!audiobookCoverUpdatedOn) return null; + return this.appendToken(`${this.mediaBaseUrl}/book/${bookId}/audiobook-thumbnail?${audiobookCoverUpdatedOn}`); + } + + getDirectAudiobookThumbnailUrl(bookId: number, audiobookCoverUpdatedOn?: string): string { let url = `${this.mediaBaseUrl}/book/${bookId}/audiobook-thumbnail`; if (audiobookCoverUpdatedOn) { url += `?${audiobookCoverUpdatedOn}`;