From bc6fd41d91fcdb2111ad6a532f71f392f41bb255 Mon Sep 17 00:00:00 2001 From: schroda <50052685+schroda@users.noreply.github.com> Date: Fri, 3 Nov 2023 17:03:59 +0100 Subject: [PATCH] Fetch chapter pages everytime unless chapter is downloaded In case the chapter is not downloaded, the chapters pages have to be always fetched, since there is a possibility, that the chapter data is so old, that the available pages data is outdated. --- src/screens/Reader.tsx | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/screens/Reader.tsx b/src/screens/Reader.tsx index f0ce290841..70e28e8407 100644 --- a/src/screens/Reader.tsx +++ b/src/screens/Reader.tsx @@ -118,6 +118,7 @@ export function Reader() { const { data: chapterData, loading: isChapterLoading } = requestManager.useGetMangaChapter(mangaId, chapterIndex, { skip: isChapterLoaded, }); + const [arePagesUpdated, setArePagesUpdated] = useState(false); const getLoadedChapter = () => { const isAChapterLoaded = loadedChapter.current; @@ -127,6 +128,10 @@ export function Reader() { return loadedChapter.current; } + if (arePagesUpdated) { + setArePagesUpdated(false); + } + if (chapterData?.chapter) { return chapterData.chapter; } @@ -136,15 +141,21 @@ export function Reader() { loadedChapter.current = getLoadedChapter(); const chapter = loadedChapter.current ?? initialChapter; - const [fetchPages, { loading: areChapterPagesLoading }] = requestManager.useGetChapterPagesFetch(chapter.id); + const [fetchPages] = requestManager.useGetChapterPagesFetch(chapter.id); useEffect(() => { - if (!isChapterLoading && chapter.pageCount === -1) { - fetchPages(); + const reCheckPages = !chapter.isDownloaded || chapter.pageCount === -1; + const shouldFetchPages = !isChapterLoading && reCheckPages; + if (shouldFetchPages) { + fetchPages().then(() => setArePagesUpdated(true)); + } + + if (!reCheckPages && !arePagesUpdated) { + setArePagesUpdated(true); } }, [chapter.id]); - const isLoading = isChapterLoading || areChapterPagesLoading || chapter.pageCount === -1; + const isLoading = isChapterLoading || !arePagesUpdated; const [wasLastPageReadSet, setWasLastPageReadSet] = useState(false); const [curPage, setCurPage] = useState(0); const [pageToScrollTo, setPageToScrollTo] = useState(undefined); @@ -276,8 +287,7 @@ export function Reader() { } }, [chapter.sourceOrder, manga.id, settings.skipDupChapters]); - // return spinner while chpater data is loading - if (chapter.pageCount === -1) { + if (isLoading) { return (