From 1fb5b3cc090f371d205ddad9fc6db543bc580a2b Mon Sep 17 00:00:00 2001 From: schroda <50052685+schroda@users.noreply.github.com> Date: Mon, 21 Jul 2025 02:40:10 +0200 Subject: [PATCH] Fix chapter list download ahead option The option should not download anything in case there is already the download ahead number of unread downloaded chapters available. Regression 85cec6fd8d62036df56a7d6b44c48404dd19050d --- .../actions/ChaptersDownloadActionMenuItems.tsx | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/modules/chapter/components/actions/ChaptersDownloadActionMenuItems.tsx b/src/modules/chapter/components/actions/ChaptersDownloadActionMenuItems.tsx index ba01e350..a74acae9 100644 --- a/src/modules/chapter/components/actions/ChaptersDownloadActionMenuItems.tsx +++ b/src/modules/chapter/components/actions/ChaptersDownloadActionMenuItems.tsx @@ -34,6 +34,7 @@ const DOWNLOAD_OPTIONS: { title: TranslationKey; getCount: (downloadAheadLimit: number) => number | undefined; onlyUnread?: boolean; + isDownloadAhead?: boolean; }[] = [ { title: 'chapter.action.download.add.label.next', getCount: () => 1 }, { title: 'chapter.action.download.add.label.next', getCount: () => 5 }, @@ -43,6 +44,7 @@ const DOWNLOAD_OPTIONS: { title: 'chapter.action.download.add.label.ahead', getCount: (downloadAheadLimit) => downloadAheadLimit, onlyUnread: true, + isDownloadAhead: true, }, { title: 'chapter.action.download.add.label.unread', getCount: () => undefined, onlyUnread: true }, { title: 'chapter.action.download.add.label.all', getCount: () => undefined, onlyUnread: false }, @@ -88,6 +90,16 @@ const handleDownload = async ( }, ).response; const filteredChapters = filterChapters(chapters.data.chapters.nodes, meta); + + const doNecessaryDownloadAheadDownloadsExist = + downloadAhead && + Chapters.removeDuplicates(filteredChapters.slice(-1)[0], filteredChapters) + .slice(-(size ?? 0)) + .every((chapter) => !Chapters.isRead(chapter) && Chapters.isDownloaded(chapter)); + if (doNecessaryDownloadAheadDownloadsExist) { + return; + } + const unreadUndownloadedChapters = filteredChapters.filter((chapter) => { if (onlyUnread && chapter.isRead) { return false; @@ -141,10 +153,10 @@ export const ChaptersDownloadActionMenuItems = ({ return ( <> - {DOWNLOAD_OPTIONS.map(({ title, getCount, onlyUnread }) => ( + {DOWNLOAD_OPTIONS.map(({ title, getCount, onlyUnread, isDownloadAhead }) => ( handleSelect(getCount(downloadAheadLimit), onlyUnread)} + onClick={() => handleSelect(getCount(downloadAheadLimit), onlyUnread, isDownloadAhead)} > {t(title, { count: getCount(downloadAheadLimit) })}