From f52b634da130a5bbbb9ddf5a9c4c69a7dea6fa43 Mon Sep 17 00:00:00 2001 From: schroda <50052685+schroda@users.noreply.github.com> Date: Fri, 28 Jun 2024 11:13:00 +0200 Subject: [PATCH] Properly sort chapter list by chapter number The sort order was switched and instead of ASC it was sorted DESC and vice versa. This was caused because the server returned the list (most of the time) in ASC order by chapter number. Additionally, the list was overall never properly sorted by chapter number and only worked because the server (most of the time) returned it in the correct order by chapter number. However, this is not guaranteed at all since the server sorts in ASC order by the chapter id by default --- src/components/chapter/util.tsx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/components/chapter/util.tsx b/src/components/chapter/util.tsx index d883baf9..b5648c80 100644 --- a/src/components/chapter/util.tsx +++ b/src/components/chapter/util.tsx @@ -22,7 +22,7 @@ const defaultChapterOptions: ChapterListOptions = { unread: undefined, downloaded: undefined, bookmarked: undefined, - reverse: false, + reverse: true, sortBy: 'source', showChapterNumber: false, }; @@ -88,14 +88,14 @@ export function filterAndSortChapters(chapters: TChapter[], options: ChapterList bookmarkedFilter(options.bookmarked, chp), ) : [...chapters]; - const Sorted = + const sorted = options.sortBy === 'fetchedAt' - ? filtered.sort((a, b) => Number(a.fetchedAt ?? 0) - Number(b.fetchedAt ?? 0)) - : filtered; + ? filtered.toSorted((a, b) => Number(a.fetchedAt ?? 0) - Number(b.fetchedAt ?? 0)) + : filtered.toSorted((a, b) => a.chapterNumber - b.chapterNumber); if (options.reverse) { - Sorted.reverse(); + sorted.reverse(); } - return Sorted; + return sorted; } export const useChapterOptions = (mangaId: number) =>