feat(sort): replace compound sort options with atomic fields and multi-sort support (#2686)

* fix(sidebar): replace routerLinkActive with getter-based route matching to prevent stale highlights

* feat(sort): replace compound sort options with atomic fields and add 6 new sort criteria
This commit is contained in:
ACX
2026-02-10 14:27:07 -07:00
committed by GitHub
parent 78a8bb4fea
commit 0fa84e3424
23 changed files with 509 additions and 190 deletions
@@ -1,5 +1,5 @@
import {Injectable} from '@angular/core';
import {Book} from '../model/book.model';
import {Book, ReadStatus} from '../model/book.model';
import {SortDirection, SortOption} from "../model/sort.model";
@Injectable({
@@ -48,18 +48,22 @@ export class SortService {
return aChunks.length - bChunks.length;
}
private static readonly READ_STATUS_RANK: Record<string, number> = {
[ReadStatus.UNSET]: 0,
[ReadStatus.UNREAD]: 1,
[ReadStatus.READING]: 2,
[ReadStatus.RE_READING]: 3,
[ReadStatus.PARTIALLY_READ]: 4,
[ReadStatus.PAUSED]: 5,
[ReadStatus.READ]: 6,
[ReadStatus.ABANDONED]: 7,
[ReadStatus.WONT_READ]: 8,
};
private readonly fieldExtractors: Record<string, (book: Book) => unknown> = {
title: (book) => (book.seriesCount ? (book.metadata?.seriesName?.toLowerCase() || null) : null)
?? (book.metadata?.title?.toLowerCase() || null),
titleSeries: (book) => {
const title = book.metadata?.title?.toLowerCase() || '';
const series = book.metadata?.seriesName?.toLowerCase();
const seriesNumber = book.metadata?.seriesNumber ?? Number.MAX_SAFE_INTEGER;
if (series) {
return [series, seriesNumber];
}
return [title, Number.MAX_SAFE_INTEGER];
},
title: (book) => book.metadata?.seriesName?.toLowerCase()
|| book.metadata?.title?.toLowerCase()
|| null,
author: (book) => book.metadata?.authors?.map(a => a.toLowerCase()).join(", ") || null,
authorSurnameVorname: (book) => book.metadata?.authors?.map(a => {
const parts = a.trim().split(/\s+/);
@@ -68,17 +72,6 @@ export class SortService {
const firstname = parts.join(" ");
return `${surname}, ${firstname}`.toLowerCase();
}).join(", ") || null,
authorSeries: (book) => {
const author = book.metadata?.authors?.map(a => a.toLowerCase()).join(", ") || null;
const series = book.metadata?.seriesName?.toLowerCase() || null;
const seriesNumber = book.metadata?.seriesNumber ?? Number.MAX_SAFE_INTEGER;
const title = book.metadata?.title?.toLowerCase() || '';
if (series) {
return [author, series, seriesNumber, title];
}
// For books without a series, use a very large string for series name to sort them last within an author.
return [author, '~~~~~~~~~~~~~~~~~', Number.MAX_SAFE_INTEGER, title];
},
publishedDate: (book) => {
const date = book.metadata?.publishedDate;
return date === null || date === undefined ? null : new Date(date).getTime();
@@ -105,6 +98,19 @@ export class SortService {
fileName: (book) => book.fileName,
filePath: (book) => book.filePath,
random: (book) => Math.random(),
seriesName: (book) => book.metadata?.seriesName?.toLowerCase() || null,
seriesNumber: (book) => book.metadata?.seriesNumber ?? null,
readStatus: (book) => book.readStatus ? (SortService.READ_STATUS_RANK[book.readStatus] ?? null) : null,
dateFinished: (book) => book.dateFinished ? new Date(book.dateFinished).getTime() : null,
readingProgress: (book) =>
book.epubProgress?.percentage
?? book.pdfProgress?.percentage
?? book.cbxProgress?.percentage
?? book.audiobookProgress?.percentage
?? book.koreaderProgress?.percentage
?? book.koboProgress?.percentage
?? null,
bookType: (book) => book.primaryFile?.bookType || null,
};
applySort(books: Book[], selectedSort: SortOption | null): Book[] {