From ab8cc918a77e55fa0548ad3afaa7ebf44cde2520 Mon Sep 17 00:00:00 2001 From: schroda <50052685+schroda@users.noreply.github.com> Date: Tue, 9 Jul 2024 23:42:02 +0200 Subject: [PATCH] Use correct fragment to read chapters from cache The used fragment specified properties that were not in the cache, resulting in null being returned instead of the required chapter data --- src/screens/Reader.tsx | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/screens/Reader.tsx b/src/screens/Reader.tsx index 933e814d..ff9b1d82 100644 --- a/src/screens/Reader.tsx +++ b/src/screens/Reader.tsx @@ -36,14 +36,18 @@ import { } from '@/lib/graphql/generated/graphql.ts'; import { useMetadataServerSettings } from '@/lib/metadata/metadataServerSettings.ts'; import { defaultPromiseErrorHandler } from '@/util/defaultPromiseErrorHandler.ts'; -import { Chapters } from '@/lib/data/Chapters.ts'; +import { ChapterIdInfo, Chapters } from '@/lib/data/Chapters.ts'; import { EmptyViewAbsoluteCentered } from '@/components/util/EmptyViewAbsoluteCentered.tsx'; import { GET_CHAPTERS_READER } from '@/lib/graphql/queries/ChapterQuery.ts'; import { GET_MANGA_READER } from '@/lib/graphql/queries/MangaQuery.ts'; import { TMangaReader } from '@/lib/data/Mangas.ts'; +import { CHAPTER_READER_FIELDS } from '@/lib/graphql/fragments/ChapterFragments.ts'; type TChapter = GetChaptersReaderQuery['chapters']['nodes'][number]; +const getChapterFromCache = (id: ChapterIdInfo['id']): TChapter | null => + Chapters.getFromCache(id, CHAPTER_READER_FIELDS, 'CHAPTER_READER_FIELDS')!; + const getReaderComponent = (readerType: ReaderType) => { switch (readerType) { case 'ContinuesVertical': @@ -277,7 +281,7 @@ export function Reader() { } // chapter has to exist in the cache since the reader fetches all chapters of the manga - const chapterToDeleteUpToDateData = Chapters.getFromCache(chapterToDelete.id)!; + const chapterToDeleteUpToDateData = getChapterFromCache(chapterToDelete.id)!; const shouldDeleteChapter = chapterToDeleteUpToDateData.isRead && @@ -294,14 +298,14 @@ export function Reader() { }; const downloadAhead = () => { - const currentChapter = Chapters.getFromCache(chapter.id); + const currentChapter = getChapterFromCache(chapter.id); const inDownloadRange = (patch.lastPageRead ?? 0) / chapter.pageCount > 0.25; const shouldCheckDownloadAhead = isDownloadAheadEnabled && manga.inLibrary && !!currentChapter?.isDownloaded && inDownloadRange; if (shouldCheckDownloadAhead) { - const nextChapterUpToDate = nextChapter ? Chapters.getFromCache(nextChapter.id) : null; + const nextChapterUpToDate = nextChapter ? getChapterFromCache(nextChapter.id) : null; if (!nextChapterUpToDate?.isDownloaded) { return; @@ -309,7 +313,7 @@ export function Reader() { const nextChaptersUpToDate = Chapters.getNonRead(nextChapters).map( // the chapters have to be in the cache since the reader fetches the whole chapter list of the manga - (mangaChapter) => Chapters.getFromCache(mangaChapter.id)!, + (mangaChapter) => getChapterFromCache(mangaChapter.id)!, ); const chapterIdsToDownload = nextChaptersUpToDate @@ -452,7 +456,7 @@ export function Reader() { return; } - const chapterUpToDate = Chapters.getFromCache(chapter.id); + const chapterUpToDate = getChapterFromCache(chapter.id); if (curPageDebounced === chapterUpToDate?.lastPageRead) { return; }