fix(ui): fall back the book sorting service to primary file (#944)
This commit is contained in:
@@ -43,6 +43,16 @@ describe('SortService', () => {
|
||||
expect(service.applySort(books, sortOption).map(book => book.id)).toEqual([1, 2]);
|
||||
});
|
||||
|
||||
it('sorts by primaryFile file name if file name is missing', () => {
|
||||
const books = [
|
||||
makeBook(2, {fileName: undefined, primaryFile: { id: 2, bookId: 2, fileName: 'Book 2' }, metadata: {bookId: 2, title: 'Book 10'}}),
|
||||
makeBook(1, {fileName: 'Book 1', primaryFile: { id: 1, bookId: 1, fileName: 'Book 3' }, metadata: {bookId: 1, title: 'Book 2'}}),
|
||||
];
|
||||
const sortOption: SortOption = {label: 'File Name', field: 'fileName', direction: SortDirection.ASCENDING};
|
||||
|
||||
expect(service.applySort(books, sortOption).map(book => book.id)).toEqual([1, 2]);
|
||||
});
|
||||
|
||||
it('sorts by array fields and read status rank', () => {
|
||||
const books = [
|
||||
makeBook(1, {metadata: {bookId: 1, authors: ['Jane Zed']}, readStatus: ReadStatus.READ}),
|
||||
|
||||
@@ -89,9 +89,9 @@ export class SortService {
|
||||
locked: (book) => book.metadata?.allMetadataLocked ?? false,
|
||||
lastReadTime: (book) => book.lastReadTime ? new Date(book.lastReadTime).getTime() : null,
|
||||
addedOn: (book) => book.addedOn ? new Date(book.addedOn).getTime() : null,
|
||||
fileSizeKb: (book) => book.fileSizeKb || null,
|
||||
fileName: (book) => book.fileName,
|
||||
filePath: (book) => book.filePath,
|
||||
fileSizeKb: (book) => book.fileSizeKb ?? book.primaryFile?.fileSizeKb ?? null,
|
||||
fileName: (book) => book.fileName ?? book.primaryFile?.fileName ?? null,
|
||||
filePath: (book) => book.filePath ?? book.primaryFile?.filePath ?? null,
|
||||
random: () => Math.random(),
|
||||
seriesName: (book) => book.metadata?.seriesName?.toLowerCase() || null,
|
||||
seriesNumber: (book) => book.metadata?.seriesNumber ?? null,
|
||||
|
||||
Reference in New Issue
Block a user