Fetch chapter pages everytime unless chapter is downloaded (#439)
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.
This commit is contained in:
@@ -118,6 +118,7 @@ export function Reader() {
|
|||||||
const { data: chapterData, loading: isChapterLoading } = requestManager.useGetMangaChapter(mangaId, chapterIndex, {
|
const { data: chapterData, loading: isChapterLoading } = requestManager.useGetMangaChapter(mangaId, chapterIndex, {
|
||||||
skip: isChapterLoaded,
|
skip: isChapterLoaded,
|
||||||
});
|
});
|
||||||
|
const [arePagesUpdated, setArePagesUpdated] = useState(false);
|
||||||
|
|
||||||
const getLoadedChapter = () => {
|
const getLoadedChapter = () => {
|
||||||
const isAChapterLoaded = loadedChapter.current;
|
const isAChapterLoaded = loadedChapter.current;
|
||||||
@@ -127,6 +128,10 @@ export function Reader() {
|
|||||||
return loadedChapter.current;
|
return loadedChapter.current;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (arePagesUpdated) {
|
||||||
|
setArePagesUpdated(false);
|
||||||
|
}
|
||||||
|
|
||||||
if (chapterData?.chapter) {
|
if (chapterData?.chapter) {
|
||||||
return chapterData.chapter;
|
return chapterData.chapter;
|
||||||
}
|
}
|
||||||
@@ -136,15 +141,21 @@ export function Reader() {
|
|||||||
loadedChapter.current = getLoadedChapter();
|
loadedChapter.current = getLoadedChapter();
|
||||||
|
|
||||||
const chapter = loadedChapter.current ?? initialChapter;
|
const chapter = loadedChapter.current ?? initialChapter;
|
||||||
const [fetchPages, { loading: areChapterPagesLoading }] = requestManager.useGetChapterPagesFetch(chapter.id);
|
const [fetchPages] = requestManager.useGetChapterPagesFetch(chapter.id);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!isChapterLoading && chapter.pageCount === -1) {
|
const reCheckPages = !chapter.isDownloaded || chapter.pageCount === -1;
|
||||||
fetchPages();
|
const shouldFetchPages = !isChapterLoading && reCheckPages;
|
||||||
|
if (shouldFetchPages) {
|
||||||
|
fetchPages().then(() => setArePagesUpdated(true));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!reCheckPages && !arePagesUpdated) {
|
||||||
|
setArePagesUpdated(true);
|
||||||
}
|
}
|
||||||
}, [chapter.id]);
|
}, [chapter.id]);
|
||||||
|
|
||||||
const isLoading = isChapterLoading || areChapterPagesLoading || chapter.pageCount === -1;
|
const isLoading = isChapterLoading || !arePagesUpdated;
|
||||||
const [wasLastPageReadSet, setWasLastPageReadSet] = useState(false);
|
const [wasLastPageReadSet, setWasLastPageReadSet] = useState(false);
|
||||||
const [curPage, setCurPage] = useState<number>(0);
|
const [curPage, setCurPage] = useState<number>(0);
|
||||||
const [pageToScrollTo, setPageToScrollTo] = useState<number | undefined>(undefined);
|
const [pageToScrollTo, setPageToScrollTo] = useState<number | undefined>(undefined);
|
||||||
@@ -276,8 +287,7 @@ export function Reader() {
|
|||||||
}
|
}
|
||||||
}, [chapter.sourceOrder, manga.id, settings.skipDupChapters]);
|
}, [chapter.sourceOrder, manga.id, settings.skipDupChapters]);
|
||||||
|
|
||||||
// return spinner while chpater data is loading
|
if (isLoading) {
|
||||||
if (chapter.pageCount === -1) {
|
|
||||||
return (
|
return (
|
||||||
<Box
|
<Box
|
||||||
sx={{
|
sx={{
|
||||||
|
|||||||
Reference in New Issue
Block a user