Add more sort options
This commit is contained in:
committed by
Aditya Chandel
parent
b15e1dc642
commit
ff59e0b3ce
@@ -10,11 +10,21 @@ export class SortService {
|
||||
private readonly fieldExtractors: Record<string, (book: Book) => any> = {
|
||||
title: (book) => book.metadata?.title?.toLowerCase() || null,
|
||||
author: (book) => book.metadata?.authors?.map(a => a.toLowerCase()).join(", ") || null,
|
||||
publishedDate: (book) =>book.metadata?.publishedDate === null ? null : new Date(book.metadata?.publishedDate!).getTime(),
|
||||
publishedDate: (book) => book.metadata?.publishedDate === null ? null : new Date(book.metadata?.publishedDate!).getTime(),
|
||||
publisher: (book) => book.metadata?.publisher || null,
|
||||
pageCount: (book) => book.metadata?.pageCount || null,
|
||||
rating: (book) => book.metadata?.rating || null,
|
||||
reviewCount: (book) => book.metadata?.reviewCount || null,
|
||||
amazonRating: (book) => book.metadata?.amazonRating || null,
|
||||
amazonReviewCount: (book) => book.metadata?.amazonReviewCount || null,
|
||||
goodreadsRating: (book) => book.metadata?.goodreadsRating || null,
|
||||
goodreadsReviewCount: (book) => book.metadata?.goodreadsReviewCount || null,
|
||||
locked: (book) =>
|
||||
Object.keys(book.metadata ?? {})
|
||||
.filter((key) => key.endsWith('Locked'))
|
||||
.every((key) => book.metadata?.[key] === true),
|
||||
lastReadTime: (book) => book.lastReadTime ? new Date(book.lastReadTime).getTime() : null,
|
||||
addedOn: (book) => book.addedOn ? new Date(book.addedOn).getTime() : null
|
||||
};
|
||||
|
||||
applySort(books: Book[], selectedSort: SortOption | null): Book[] {
|
||||
|
||||
Reference in New Issue
Block a user