Add new library sort options (#547)
- latest fetched chapter - latest uploaded chapter
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -428,6 +428,8 @@
|
||||
"alphabetically": "A-Z",
|
||||
"by_date_added": "Recently added",
|
||||
"by_last_read": "Recently read",
|
||||
"by_latest_fetched_chapter": "Latest fetched chapter",
|
||||
"by_latest_uploaded_chapter": "Latest uploaded chapter",
|
||||
"by_unread_chapters": "Unread chapters"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -338,7 +338,13 @@ export type ChapterOptionsReducerAction =
|
||||
| { type: 'sortReverse' }
|
||||
| { type: 'showChapterNumber' };
|
||||
|
||||
export type LibrarySortMode = 'sortToRead' | 'sortAlph' | 'sortDateAdded' | 'sortLastRead';
|
||||
export type LibrarySortMode =
|
||||
| 'sortToRead'
|
||||
| 'sortAlph'
|
||||
| 'sortDateAdded'
|
||||
| 'sortLastRead'
|
||||
| 'sortLatestFetchedChapter'
|
||||
| 'sortLatestUploadedChapter';
|
||||
|
||||
enum GridLayout {
|
||||
Compact = 0,
|
||||
|
||||
Reference in New Issue
Block a user