Add sorting option: Title followed by Series

This commit is contained in:
aditya.chandel
2025-05-27 07:35:16 -07:00
committed by Aditya Chandel
parent e559efc2f7
commit 1acb2917dd
2 changed files with 10 additions and 2 deletions
@@ -115,6 +115,7 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
sortOptions: any[] = [
{label: 'Title', icon: '', field: 'title', command: () => this.sortBooks('title')},
{label: 'Title + Series', icon: '', field: 'titleSeries', command: () => this.sortBooks('titleSeries')},
{label: 'Author', icon: '', field: 'author', command: () => this.sortBooks('author')},
{label: 'Last Read', field: 'lastReadTime', command: () => this.sortBooks('lastReadTime')},
{label: 'Added On', field: 'addedOn', command: () => this.sortBooks('addedOn')},
@@ -497,7 +498,6 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
sortBooks(field: string): void {
const existingSort = this.sortOptions.find(opt => opt.field === field);
if (!existingSort) return;
if (this.selectedSort?.field === field) {
@@ -521,7 +521,9 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
this.router.navigate([], {
queryParams: {
sort: this.selectedSort.field,
direction: this.selectedSort.direction === SortDirection.ASCENDING ? SORT_DIRECTION.ASCENDING : SORT_DIRECTION.DESCENDING
direction: this.selectedSort.direction === SortDirection.ASCENDING
? SORT_DIRECTION.ASCENDING
: SORT_DIRECTION.DESCENDING
},
queryParamsHandling: 'merge',
replaceUrl: true
@@ -9,6 +9,12 @@ export class SortService {
private readonly fieldExtractors: Record<string, (book: Book) => any> = {
title: (book) => book.metadata?.title?.toLowerCase() || null,
titleSeries: (book) => {
const title = book.metadata?.title?.toLowerCase() || '';
const inSeries = !!book.metadata?.seriesName;
const seriesOrder = book.metadata?.seriesNumber ?? Number.MAX_SAFE_INTEGER;
return [title, inSeries ? 1 : 0, seriesOrder];
},
author: (book) => book.metadata?.authors?.map(a => a.toLowerCase()).join(", ") || null,
publishedDate: (book) => book.metadata?.publishedDate === null ? null : new Date(book.metadata?.publishedDate!).getTime(),
publisher: (book) => book.metadata?.publisher || null,