Slice chapter list correctly for downloads
Chapters are sorted in desc order and thus, the oldest chapters are at the end of the list. Thus, the chapters to download need to be taken from the end instead from the start
This commit is contained in:
@@ -82,11 +82,11 @@ const handleDownload = async (
|
|||||||
const chapters = await requestManager.getChapters<GetChaptersMangaQuery, GetChaptersMangaQueryVariables>(
|
const chapters = await requestManager.getChapters<GetChaptersMangaQuery, GetChaptersMangaQueryVariables>(
|
||||||
GET_CHAPTERS_MANGA,
|
GET_CHAPTERS_MANGA,
|
||||||
{
|
{
|
||||||
|
// Align conditions/filters with the query from ChapterList to potentially be able to reuse the cache
|
||||||
condition: { mangaId: Number(mangaId) },
|
condition: { mangaId: Number(mangaId) },
|
||||||
order: [{ by: ChapterOrderBy.SourceOrder, byType: SortOrder.Desc }],
|
order: [{ by: ChapterOrderBy.SourceOrder, byType: SortOrder.Desc }],
|
||||||
},
|
},
|
||||||
).response;
|
).response;
|
||||||
|
|
||||||
const filteredChapters = filterChapters(chapters.data.chapters.nodes, meta);
|
const filteredChapters = filterChapters(chapters.data.chapters.nodes, meta);
|
||||||
const chaptersToDownload = filteredChapters
|
const chaptersToDownload = filteredChapters
|
||||||
.filter((chapter) => {
|
.filter((chapter) => {
|
||||||
@@ -96,7 +96,7 @@ const handleDownload = async (
|
|||||||
|
|
||||||
return !chapter.isDownloaded;
|
return !chapter.isDownloaded;
|
||||||
})
|
})
|
||||||
.slice(0, size);
|
.slice(-(size ?? 0));
|
||||||
|
|
||||||
if (!chaptersToDownload.length) {
|
if (!chaptersToDownload.length) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user