From e32078917d82991ecdb70f4a9c23e941ff147a23 Mon Sep 17 00:00:00 2001 From: akabhirav <108609220+akabhirav@users.noreply.github.com> Date: Sat, 4 Mar 2023 22:21:39 +0530 Subject: [PATCH] Replace Sort by ID with Date Added (#253) --- .nvmrc | 1 + src/components/library/LibraryMangaGrid.tsx | 6 +++--- src/components/library/LibraryOptionsPanel.tsx | 2 +- src/screens/Reader.tsx | 1 + src/screens/SourceMangas.tsx | 1 + src/typings.ts | 11 ++++++++++- tsconfig.json | 2 +- 7 files changed, 18 insertions(+), 6 deletions(-) create mode 100644 .nvmrc diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 00000000..e329619c --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +v16.19.1 diff --git a/src/components/library/LibraryMangaGrid.tsx b/src/components/library/LibraryMangaGrid.tsx index 62263823..93d47eb6 100644 --- a/src/components/library/LibraryMangaGrid.tsx +++ b/src/components/library/LibraryMangaGrid.tsx @@ -68,7 +68,7 @@ const sortByUnread = (a: IMangaCard, b: IMangaCard): number => const sortByTitle = (a: IMangaCard, b: IMangaCard): number => a.title.localeCompare(b.title); -const sortById = (a: IMangaCard, b: IMangaCard): number => a.id - b.id; +const sortByDateAdded = (a: IMangaCard, b: IMangaCard): number => a.inLibraryAt - b.inLibraryAt; const sortManga = ( manga: IMangaCard[], @@ -81,8 +81,8 @@ const sortManga = ( case 'sortAlph': result.sort(sortByTitle); break; - case 'sortID': - result.sort(sortById); + case 'sortDateAdded': + result.sort(sortByDateAdded); break; case 'sortToRead': result.sort(sortByUnread); diff --git a/src/components/library/LibraryOptionsPanel.tsx b/src/components/library/LibraryOptionsPanel.tsx index a985cbd1..a2ee0f24 100644 --- a/src/components/library/LibraryOptionsPanel.tsx +++ b/src/components/library/LibraryOptionsPanel.tsx @@ -24,7 +24,7 @@ const TITLES = { const SORT_OPTIONS: [LibrarySortMode, string][] = [ ['sortToRead', 'By Unread chapters'], ['sortAlph', 'Alphabetically'], - ['sortID', 'By ID'], + ['sortDateAdded', 'Date Added'], ]; interface IProps { diff --git a/src/screens/Reader.tsx b/src/screens/Reader.tsx index fe40138e..f6173279 100644 --- a/src/screens/Reader.tsx +++ b/src/screens/Reader.tsx @@ -72,6 +72,7 @@ export default function Reader() { title: '', thumbnailUrl: '', genre: [], + inLibraryAt: 0, }); const [chapter, setChapter] = useState(initialChapter()); const [curPage, setCurPage] = useState(0); diff --git a/src/screens/SourceMangas.tsx b/src/screens/SourceMangas.tsx index 0af7ad96..eb05635e 100644 --- a/src/screens/SourceMangas.tsx +++ b/src/screens/SourceMangas.tsx @@ -204,6 +204,7 @@ export default function SourceMangas(props: { popular: boolean }) { id: it.id, inLibrary: it.inLibrary, genre: it.genre, + inLibraryAt: it.inLibraryAt, })), ]); setHasNextPage(data.hasNextPage); diff --git a/src/typings.ts b/src/typings.ts index 709e1e54..6054737b 100644 --- a/src/typings.ts +++ b/src/typings.ts @@ -98,6 +98,7 @@ export interface IMangaCard { downloadCount?: number; inLibrary?: boolean; meta?: IMetadata; + inLibraryAt: number; } export interface IManga { @@ -126,6 +127,14 @@ export interface IManga { age: number; chaptersAge: number; + chaptersLastFetchedAt: number; + inLibraryAt: number; + initialized: boolean; + lastChapterRead: NullAndUndefined; + lastFetchedAt: number; + lastReadAt: number; + thumbnailUrlLastFetched: number; + updateStrategy: string; } export interface IChapter { @@ -322,7 +331,7 @@ export type ChapterOptionsReducerAction = | { type: 'sortReverse' } | { type: 'showChapterNumber' }; -export type LibrarySortMode = 'sortToRead' | 'sortAlph' | 'sortID'; +export type LibrarySortMode = 'sortToRead' | 'sortAlph' | 'sortDateAdded'; enum GridLayout { Compact = 0, diff --git a/tsconfig.json b/tsconfig.json index 00a10034..972b640e 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -24,4 +24,4 @@ "include": [ "src" ] -} \ No newline at end of file +}