Download ahead only in case current and next chapter are downloaded

This commit is contained in:
schroda
2024-02-12 20:53:53 +01:00
parent d5b633f5c9
commit 7caea4e526

View File

@@ -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, {