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 85cec6fd8d
This commit is contained in:
@@ -34,6 +34,7 @@ const DOWNLOAD_OPTIONS: {
|
|||||||
title: TranslationKey;
|
title: TranslationKey;
|
||||||
getCount: (downloadAheadLimit: number) => number | undefined;
|
getCount: (downloadAheadLimit: number) => number | undefined;
|
||||||
onlyUnread?: boolean;
|
onlyUnread?: boolean;
|
||||||
|
isDownloadAhead?: boolean;
|
||||||
}[] = [
|
}[] = [
|
||||||
{ title: 'chapter.action.download.add.label.next', getCount: () => 1 },
|
{ title: 'chapter.action.download.add.label.next', getCount: () => 1 },
|
||||||
{ title: 'chapter.action.download.add.label.next', getCount: () => 5 },
|
{ title: 'chapter.action.download.add.label.next', getCount: () => 5 },
|
||||||
@@ -43,6 +44,7 @@ const DOWNLOAD_OPTIONS: {
|
|||||||
title: 'chapter.action.download.add.label.ahead',
|
title: 'chapter.action.download.add.label.ahead',
|
||||||
getCount: (downloadAheadLimit) => downloadAheadLimit,
|
getCount: (downloadAheadLimit) => downloadAheadLimit,
|
||||||
onlyUnread: true,
|
onlyUnread: true,
|
||||||
|
isDownloadAhead: true,
|
||||||
},
|
},
|
||||||
{ title: 'chapter.action.download.add.label.unread', getCount: () => undefined, onlyUnread: true },
|
{ title: 'chapter.action.download.add.label.unread', getCount: () => undefined, onlyUnread: true },
|
||||||
{ title: 'chapter.action.download.add.label.all', getCount: () => undefined, onlyUnread: false },
|
{ title: 'chapter.action.download.add.label.all', getCount: () => undefined, onlyUnread: false },
|
||||||
@@ -88,6 +90,16 @@ const handleDownload = async (
|
|||||||
},
|
},
|
||||||
).response;
|
).response;
|
||||||
const filteredChapters = filterChapters(chapters.data.chapters.nodes, meta);
|
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) => {
|
const unreadUndownloadedChapters = filteredChapters.filter((chapter) => {
|
||||||
if (onlyUnread && chapter.isRead) {
|
if (onlyUnread && chapter.isRead) {
|
||||||
return false;
|
return false;
|
||||||
@@ -141,10 +153,10 @@ export const ChaptersDownloadActionMenuItems = ({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{DOWNLOAD_OPTIONS.map(({ title, getCount, onlyUnread }) => (
|
{DOWNLOAD_OPTIONS.map(({ title, getCount, onlyUnread, isDownloadAhead }) => (
|
||||||
<MenuItem
|
<MenuItem
|
||||||
key={t(title, { count: getCount(downloadAheadLimit) })}
|
key={t(title, { count: getCount(downloadAheadLimit) })}
|
||||||
onClick={() => handleSelect(getCount(downloadAheadLimit), onlyUnread)}
|
onClick={() => handleSelect(getCount(downloadAheadLimit), onlyUnread, isDownloadAhead)}
|
||||||
>
|
>
|
||||||
{t(title, { count: getCount(downloadAheadLimit) })}
|
{t(title, { count: getCount(downloadAheadLimit) })}
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
|
|||||||
Reference in New Issue
Block a user