Add new library sort options (#547)

- latest fetched chapter
- latest uploaded chapter
This commit is contained in:
schroda
2024-01-11 03:56:04 +01:00
committed by GitHub
parent 3973eda089
commit be5497af94
4 changed files with 23 additions and 1 deletions

View File

@@ -28,6 +28,8 @@ const SORT_OPTIONS: [LibrarySortMode, TranslationKey][] = [
['sortAlph', 'library.option.sort.label.alphabetically'],
['sortDateAdded', 'library.option.sort.label.by_date_added'],
['sortLastRead', 'library.option.sort.label.by_last_read'],
['sortLatestFetchedChapter', 'library.option.sort.label.by_latest_fetched_chapter'],
['sortLatestUploadedChapter', 'library.option.sort.label.by_latest_uploaded_chapter'],
];
interface IProps {

View File

@@ -70,6 +70,12 @@ const sortByDateAdded = (a: TManga, b: TManga): number => Number(a.inLibraryAt)
const sortByLastRead = (a: TManga, b: TManga): number =>
Number(b.lastReadChapter?.lastReadAt ?? 0) - Number(a.lastReadChapter?.lastReadAt ?? 0);
const sortByLatestUploadedChapter = (a: TManga, b: TManga): number =>
(a.latestUploadedChapter?.fetchedAt ?? 0) - (b.latestUploadedChapter?.fetchedAt ?? 0);
const sortByLatestFetchedChapter = (a: TManga, b: TManga): number =>
(a.latestFetchedChapter?.fetchedAt ?? 0) - (b.latestFetchedChapter?.fetchedAt ?? 0);
const sortManga = (
manga: TManga[],
sort: NullAndUndefined<LibrarySortMode>,
@@ -90,6 +96,12 @@ const sortManga = (
case 'sortLastRead':
result.sort(sortByLastRead);
break;
case 'sortLatestUploadedChapter':
result.sort(sortByLatestUploadedChapter);
break;
case 'sortLatestFetchedChapter':
result.sort(sortByLatestFetchedChapter);
break;
default:
break;
}