fix(ui): add square audiobook artwork in command palette (#1099)

This commit is contained in:
Alex
2026-05-04 12:54:19 +01:00
committed by GitHub
parent 108cd1954a
commit ddd3d6a296
5 changed files with 50 additions and 4 deletions
@@ -51,7 +51,7 @@
> >
@if (item.kind === 'book' && item.bookMeta; as bookMeta) { @if (item.kind === 'book' && item.bookMeta; as bookMeta) {
<ng-container *transloco="let tb; prefix: 'book.searcher'"> <ng-container *transloco="let tb; prefix: 'book.searcher'">
<div class="command-palette-book-cover"> <div class="command-palette-book-cover" [class.square-cover]="bookMeta.isAudiobook">
@if (bookMeta.thumbnailUrl) { @if (bookMeta.thumbnailUrl) {
<img [src]="bookMeta.thumbnailUrl" alt="" /> <img [src]="bookMeta.thumbnailUrl" alt="" />
} @else { } @else {
@@ -134,6 +134,10 @@
background: var(--surface-800); background: var(--surface-800);
box-shadow: var(--shadow-sm); box-shadow: var(--shadow-sm);
&.square-cover {
height: 32px;
}
img { img {
width: 100%; width: 100%;
height: 100%; height: 100%;
@@ -16,6 +16,7 @@ export interface PaletteBookMeta {
seriesName: string | null; seriesName: string | null;
seriesNumber: number | null; seriesNumber: number | null;
year: string | null; year: string | null;
isAudiobook: boolean;
} }
export interface PaletteItem { export interface PaletteItem {
@@ -18,15 +18,17 @@ import { DialogLauncherService } from '../../shared/services/dialog-launcher.ser
import { CommandPaletteService } from './command-palette.service'; import { CommandPaletteService } from './command-palette.service';
function makeBook(id: number, title: string, authors: string[] = []): Book { function makeBook(id: number, title: string, authors: string[] = [], overrides: Partial<Book> = {}): Book {
return { return {
id, id,
libraryId: 1, libraryId: 1,
libraryName: 'Library', libraryName: 'Library',
...overrides,
metadata: { metadata: {
bookId: id, bookId: id,
title, title,
authors, authors,
...overrides.metadata,
}, },
} as Book; } as Book;
} }
@@ -34,6 +36,10 @@ function makeBook(id: number, title: string, authors: string[] = []): Book {
describe('CommandPaletteService', () => { describe('CommandPaletteService', () => {
let service: CommandPaletteService; let service: CommandPaletteService;
let books = signal<Book[]>([]); let books = signal<Book[]>([]);
let urlHelper: {
getThumbnailUrl: ReturnType<typeof vi.fn>;
getAudiobookThumbnailUrl: ReturnType<typeof vi.fn>;
};
beforeEach(() => { beforeEach(() => {
vi.useFakeTimers(); vi.useFakeTimers();
@@ -45,6 +51,10 @@ describe('CommandPaletteService', () => {
makeBook(2, 'The Fellowship of the Ring', ['J.R.R. Tolkien']), makeBook(2, 'The Fellowship of the Ring', ['J.R.R. Tolkien']),
makeBook(3, 'Dune', ['Frank Herbert']), makeBook(3, 'Dune', ['Frank Herbert']),
]); ]);
urlHelper = {
getThumbnailUrl: vi.fn(() => null),
getAudiobookThumbnailUrl: vi.fn(() => null),
};
TestBed.configureTestingModule({ TestBed.configureTestingModule({
imports: [getTranslocoModule()], imports: [getTranslocoModule()],
@@ -55,7 +65,7 @@ describe('CommandPaletteService', () => {
{ provide: MagicShelfService, useValue: { shelves: signal([]) } }, { provide: MagicShelfService, useValue: { shelves: signal([]) } },
{ provide: LibraryService, useValue: { libraries: signal([]) } }, { provide: LibraryService, useValue: { libraries: signal([]) } },
{ provide: UserService, useValue: { currentUser: signal({ permissions: {} }) } }, { provide: UserService, useValue: { currentUser: signal({ permissions: {} }) } },
{ provide: UrlHelperService, useValue: { getThumbnailUrl: vi.fn(() => null) } }, { provide: UrlHelperService, useValue: urlHelper },
{ provide: IconService, useValue: { getSvgIconContent: vi.fn(() => of('')) } }, { provide: IconService, useValue: { getSvgIconContent: vi.fn(() => of('')) } },
{ {
provide: DialogLauncherService, provide: DialogLauncherService,
@@ -115,4 +125,31 @@ describe('CommandPaletteService', () => {
expect(service.groups()).toEqual([]); expect(service.groups()).toEqual([]);
expect(service.visibleItems()).toEqual([]); expect(service.visibleItems()).toEqual([]);
}); });
it('uses square audiobook metadata and audiobook thumbnails for audiobook results', async () => {
urlHelper.getAudiobookThumbnailUrl.mockReturnValue('/audio-thumb.jpg');
books.set([
makeBook(4, 'Audio Sample', ['Narrator'], {
primaryFile: { id: 4, bookId: 4, bookType: 'AUDIOBOOK' },
metadata: {
bookId: 4,
title: 'Audio Sample',
authors: ['Narrator'],
audiobookCoverUpdatedOn: 'audio-updated',
},
}),
]);
service.query.set('audio');
TestBed.flushEffects();
await vi.advanceTimersByTimeAsync(200);
TestBed.flushEffects();
const book = service.groups().find((group) => group.kind === 'book')?.items[0];
expect(book?.bookMeta?.isAudiobook).toBe(true);
expect(book?.bookMeta?.thumbnailUrl).toBe('/audio-thumb.jpg');
expect(urlHelper.getAudiobookThumbnailUrl).toHaveBeenCalledWith(4, 'audio-updated');
expect(urlHelper.getThumbnailUrl).not.toHaveBeenCalled();
});
}); });
@@ -286,6 +286,7 @@ export class CommandPaletteService {
const publishedDate = metadata?.publishedDate ?? ''; const publishedDate = metadata?.publishedDate ?? '';
const year = publishedDate && /^\d{4}/.test(publishedDate) ? publishedDate.slice(0, 4) : null; const year = publishedDate && /^\d{4}/.test(publishedDate) ? publishedDate.slice(0, 4) : null;
const haystack = [title, metadata?.seriesName ?? '', ...authors].filter(Boolean).join(' '); const haystack = [title, metadata?.seriesName ?? '', ...authors].filter(Boolean).join(' ');
const isAudiobook = book.primaryFile?.bookType === 'AUDIOBOOK';
return { return {
id: `book:${book.id}`, id: `book:${book.id}`,
@@ -296,11 +297,14 @@ export class CommandPaletteService {
route: ['/book', book.id], route: ['/book', book.id],
queryParams: { tab: 'view' }, queryParams: { tab: 'view' },
bookMeta: { bookMeta: {
thumbnailUrl: this.urlHelper.getThumbnailUrl(book.id, metadata?.coverUpdatedOn), thumbnailUrl: isAudiobook
? this.urlHelper.getAudiobookThumbnailUrl(book.id, metadata?.audiobookCoverUpdatedOn)
: this.urlHelper.getThumbnailUrl(book.id, metadata?.coverUpdatedOn),
authors, authors,
seriesName: metadata?.seriesName ?? null, seriesName: metadata?.seriesName ?? null,
seriesNumber: metadata?.seriesNumber ?? null, seriesNumber: metadata?.seriesNumber ?? null,
year, year,
isAudiobook,
}, },
}; };
} }