From 89cff9db6aa82440037f1466362a091d8aa72d21 Mon Sep 17 00:00:00 2001 From: schroda <50052685+schroda@users.noreply.github.com> Date: Sun, 13 Jul 2025 14:21:30 +0200 Subject: [PATCH] Handle duplicated chapters in chapter download action again Regression 85cec6fd8d62036df56a7d6b44c48404dd19050d --- .../ChaptersDownloadActionMenuItems.tsx | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/modules/chapter/components/actions/ChaptersDownloadActionMenuItems.tsx b/src/modules/chapter/components/actions/ChaptersDownloadActionMenuItems.tsx index ff8fd0b0..ba01e350 100644 --- a/src/modules/chapter/components/actions/ChaptersDownloadActionMenuItems.tsx +++ b/src/modules/chapter/components/actions/ChaptersDownloadActionMenuItems.tsx @@ -88,21 +88,26 @@ const handleDownload = async ( }, ).response; const filteredChapters = filterChapters(chapters.data.chapters.nodes, meta); - const chaptersToDownload = filteredChapters - .filter((chapter) => { - if (onlyUnread && chapter.isRead) { - return false; - } + const unreadUndownloadedChapters = filteredChapters.filter((chapter) => { + if (onlyUnread && chapter.isRead) { + return false; + } - return !chapter.isDownloaded; - }) - .slice(-(size ?? 0)); + return !chapter.isDownloaded; + }); - if (!chaptersToDownload.length) { + const uniqueChapters = Chapters.removeDuplicates( + unreadUndownloadedChapters.slice(-1)[0], + unreadUndownloadedChapters, + ); + const chaptersToDownload = uniqueChapters.slice(-(size ?? 0)); + const chaptersToDownloadWithDuplicates = Chapters.addDuplicates(chaptersToDownload, unreadUndownloadedChapters); + + if (!chaptersToDownloadWithDuplicates.length) { return; } - Chapters.performAction('download', Chapters.getIds(chaptersToDownload), {}).catch( + Chapters.performAction('download', Chapters.getIds(chaptersToDownloadWithDuplicates), {}).catch( defaultPromiseErrorHandler('ChaptersDownloadActionMenuItems::handleSelect::singleMangaMode'), ); };