load first page on read manga (#76)

This commit is contained in:
Aria Moradi
2021-11-15 12:53:18 +03:30
committed by GitHub
parent 72ef61e286
commit 0eedbe6626
3 changed files with 10 additions and 11 deletions

View File

@@ -87,8 +87,9 @@ export default function HorizontalPager(props: IReaderProps) {
}; };
useEffect(() => { useEffect(() => {
// scroll last read page into view after first mount
pagesRef.current[curPage]?.scrollIntoView({ inline: 'center' }); pagesRef.current[curPage]?.scrollIntoView({ inline: 'center' });
}, [settings.readerType]); }, [pagesRef.current.length]);
useEffect(() => { useEffect(() => {
selfRef.current?.addEventListener('mousedown', dragControl); selfRef.current?.addEventListener('mousedown', dragControl);

View File

@@ -11,7 +11,7 @@ import Page from '../Page';
export default function VerticalReader(props: IReaderProps) { export default function VerticalReader(props: IReaderProps) {
const { const {
pages, settings, setCurPage, curPage, chapter, nextChapter, prevChapter, pages, settings, setCurPage, curPage, nextChapter, prevChapter,
} = props; } = props;
const selfRef = useRef<HTMLDivElement>(null); const selfRef = useRef<HTMLDivElement>(null);
@@ -88,14 +88,8 @@ export default function VerticalReader(props: IReaderProps) {
}, [selfRef, curPage]); }, [selfRef, curPage]);
useEffect(() => { useEffect(() => {
// scroll last read page into view // scroll last read page into view after first mount
let initialPage = (chapter as IChapter).lastPageRead; pagesRef.current[curPage].scrollIntoView();
if (initialPage > pages.length - 1) {
initialPage = pages.length - 1;
}
if (initialPage > -1) {
pagesRef.current[initialPage].scrollIntoView();
}
}, [pagesRef.current.length]); }, [pagesRef.current.length]);
return ( return (

View File

@@ -111,7 +111,11 @@ export default function Reader() {
.then((response) => response.data) .then((response) => response.data)
.then((data:IChapter) => { .then((data:IChapter) => {
setChapter(data); setChapter(data);
setCurPage(data.lastPageRead);
if (data.lastPageRead === data.pageCount - 1) {
// last page, also probably read = true, we will load the first page.
setCurPage(0);
} else setCurPage(data.lastPageRead);
}); });
}, [chapterIndex]); }, [chapterIndex]);