Prevent updating "lastPageRead" of chapter to the initial chapters "lastPageRead" (#357)
This could cause racing conditions with the chapter load which lead to the lastPageRead to be reset to 0
This commit is contained in:
@@ -108,6 +108,7 @@ export default function Reader() {
|
|||||||
mangaId,
|
mangaId,
|
||||||
chapterIndex,
|
chapterIndex,
|
||||||
);
|
);
|
||||||
|
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);
|
||||||
const { setOverride, setTitle } = useContext(NavbarContext);
|
const { setOverride, setTitle } = useContext(NavbarContext);
|
||||||
@@ -154,6 +155,7 @@ export default function Reader() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setWasLastPageReadSet(true);
|
||||||
if (chapter.lastPageRead === chapter.pageCount - 1) {
|
if (chapter.lastPageRead === chapter.pageCount - 1) {
|
||||||
// last page, also probably read = true, we will load the first page.
|
// last page, also probably read = true, we will load the first page.
|
||||||
setCurPage(0);
|
setCurPage(0);
|
||||||
@@ -198,6 +200,10 @@ export default function Reader() {
|
|||||||
}, [manga, chapter, settings, curPage, chapterIndex, retrievingNextChapter]);
|
}, [manga, chapter, settings, curPage, chapterIndex, retrievingNextChapter]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (!wasLastPageReadSet) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (curPage !== -1) {
|
if (curPage !== -1) {
|
||||||
requestManager.updateChapter(manga.id, chapter.index, { lastPageRead: curPage });
|
requestManager.updateChapter(manga.id, chapter.index, { lastPageRead: curPage });
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user