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

View File

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

View File

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

View File

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

View File

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