Download ahead only in case current and next chapter are downloaded
This commit is contained in:
@@ -188,6 +188,16 @@ export function Reader() {
|
|||||||
const { settings: metadataSettings } = useMetadataServerSettings();
|
const { settings: metadataSettings } = useMetadataServerSettings();
|
||||||
|
|
||||||
const updateChapter = (patch: UpdateChapterPatchInput) => {
|
const updateChapter = (patch: UpdateChapterPatchInput) => {
|
||||||
|
const getChapterFromCache = (id: number) =>
|
||||||
|
requestManager.graphQLClient.client.cache.readFragment<TChapter>({
|
||||||
|
id: requestManager.graphQLClient.client.cache.identify({
|
||||||
|
__typename: 'ChapterType',
|
||||||
|
id,
|
||||||
|
}),
|
||||||
|
fragment: FULL_CHAPTER_FIELDS,
|
||||||
|
fragmentName: 'FULL_CHAPTER_FIELDS',
|
||||||
|
});
|
||||||
|
|
||||||
const isAutoDeletionEnabled = !!patch.isRead && !!metadataSettings.deleteChaptersWhileReading;
|
const isAutoDeletionEnabled = !!patch.isRead && !!metadataSettings.deleteChaptersWhileReading;
|
||||||
|
|
||||||
const getChapterIdToDelete = () => {
|
const getChapterIdToDelete = () => {
|
||||||
@@ -204,14 +214,7 @@ export function Reader() {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
const chapterToDeleteUpToDateData = requestManager.graphQLClient.client.cache.readFragment<TChapter>({
|
const chapterToDeleteUpToDateData = getChapterFromCache(chapterToDelete.id);
|
||||||
id: requestManager.graphQLClient.client.cache.identify({
|
|
||||||
__typename: 'ChapterType',
|
|
||||||
id: chapterToDelete.id,
|
|
||||||
}),
|
|
||||||
fragment: FULL_CHAPTER_FIELDS,
|
|
||||||
fragmentName: 'FULL_CHAPTER_FIELDS',
|
|
||||||
});
|
|
||||||
|
|
||||||
const shouldDeleteChapter =
|
const shouldDeleteChapter =
|
||||||
chapterToDeleteUpToDateData?.isDownloaded &&
|
chapterToDeleteUpToDateData?.isDownloaded &&
|
||||||
@@ -223,8 +226,17 @@ export function Reader() {
|
|||||||
return chapterToDelete.id;
|
return chapterToDelete.id;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const currentChapter = getChapterFromCache(chapter.id);
|
||||||
|
const nextChapterId = mangaChapters?.[Number(chapterIndex) + 1]?.id;
|
||||||
|
const nextChapter = nextChapterId ? getChapterFromCache(nextChapterId) : null;
|
||||||
|
|
||||||
const shouldDownloadAhead =
|
const shouldDownloadAhead =
|
||||||
chapter.manga.inLibrary && !chapter.isRead && !!patch.isRead && isDownloadAheadEnabled;
|
isDownloadAheadEnabled &&
|
||||||
|
chapter.manga.inLibrary &&
|
||||||
|
!chapter.isRead &&
|
||||||
|
!!patch.isRead &&
|
||||||
|
!!currentChapter?.isDownloaded &&
|
||||||
|
!!nextChapter?.isDownloaded;
|
||||||
|
|
||||||
requestManager
|
requestManager
|
||||||
.updateChapter(chapter.id, {
|
.updateChapter(chapter.id, {
|
||||||
|
|||||||
Reference in New Issue
Block a user