Added sort by last read (#254)

This commit is contained in:
akabhirav
2023-03-05 12:26:50 +05:30
committed by GitHub
parent e32078917d
commit 91e7bd2b27
5 changed files with 10 additions and 1 deletions

View File

@@ -70,6 +70,8 @@ const sortByTitle = (a: IMangaCard, b: IMangaCard): number => a.title.localeComp
const sortByDateAdded = (a: IMangaCard, b: IMangaCard): number => a.inLibraryAt - b.inLibraryAt;
const sortByLastRead = (a: IMangaCard, b: IMangaCard): number => b.lastReadAt - a.lastReadAt;
const sortManga = (
manga: IMangaCard[],
sort: NullAndUndefined<LibrarySortMode>,
@@ -87,6 +89,9 @@ const sortManga = (
case 'sortToRead':
result.sort(sortByUnread);
break;
case 'sortLastRead':
result.sort(sortByLastRead);
break;
default:
break;
}

View File

@@ -25,6 +25,7 @@ const SORT_OPTIONS: [LibrarySortMode, string][] = [
['sortToRead', 'By Unread chapters'],
['sortAlph', 'Alphabetically'],
['sortDateAdded', 'Date Added'],
['sortLastRead', 'Last Read'],
];
interface IProps {

View File

@@ -73,6 +73,7 @@ export default function Reader() {
thumbnailUrl: '',
genre: [],
inLibraryAt: 0,
lastReadAt: 0,
});
const [chapter, setChapter] = useState<IChapter | IPartialChapter>(initialChapter());
const [curPage, setCurPage] = useState<number>(0);

View File

@@ -205,6 +205,7 @@ export default function SourceMangas(props: { popular: boolean }) {
inLibrary: it.inLibrary,
genre: it.genre,
inLibraryAt: it.inLibraryAt,
lastReadAt: it.lastReadAt,
})),
]);
setHasNextPage(data.hasNextPage);

View File

@@ -99,6 +99,7 @@ export interface IMangaCard {
inLibrary?: boolean;
meta?: IMetadata;
inLibraryAt: number;
lastReadAt: number;
}
export interface IManga {
@@ -331,7 +332,7 @@ export type ChapterOptionsReducerAction =
| { type: 'sortReverse' }
| { type: 'showChapterNumber' };
export type LibrarySortMode = 'sortToRead' | 'sortAlph' | 'sortDateAdded';
export type LibrarySortMode = 'sortToRead' | 'sortAlph' | 'sortDateAdded' | 'sortLastRead';
enum GridLayout {
Compact = 0,