diff --git a/booklore-ui/src/app/book/components/book-browser/book-browser.component.ts b/booklore-ui/src/app/book/components/book-browser/book-browser.component.ts index 8c3b0b4e6..904a621d3 100644 --- a/booklore-ui/src/app/book/components/book-browser/book-browser.component.ts +++ b/booklore-ui/src/app/book/components/book-browser/book-browser.component.ts @@ -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 diff --git a/booklore-ui/src/app/book/service/sort.service.ts b/booklore-ui/src/app/book/service/sort.service.ts index 5525471d8..647ff96ca 100644 --- a/booklore-ui/src/app/book/service/sort.service.ts +++ b/booklore-ui/src/app/book/service/sort.service.ts @@ -9,6 +9,12 @@ export class SortService { private readonly fieldExtractors: Record 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,