From e97642d92a57ff1e8a632592c6964676a99a1ec1 Mon Sep 17 00:00:00 2001 From: Aria Moradi Date: Tue, 25 May 2021 13:14:07 +0430 Subject: [PATCH] prevPage handle * go back to previous chapter on page 0 when prevPage is triggered --- webUI/react/src/components/reader/pager/PagedPager.tsx | 4 ++-- webUI/react/src/components/reader/pager/VerticalPager.tsx | 4 +++- webUI/react/src/screens/Reader.tsx | 8 ++++++++ webUI/react/src/typings.d.ts | 1 + 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/webUI/react/src/components/reader/pager/PagedPager.tsx b/webUI/react/src/components/reader/pager/PagedPager.tsx index b489eb2..e23c187 100644 --- a/webUI/react/src/components/reader/pager/PagedPager.tsx +++ b/webUI/react/src/components/reader/pager/PagedPager.tsx @@ -22,7 +22,7 @@ const useStyles = makeStyles({ export default function PagedReader(props: IReaderProps) { const { - pages, settings, setCurPage, curPage, nextChapter, + pages, settings, setCurPage, curPage, nextChapter, prevChapter, } = props; const classes = useStyles(); @@ -38,7 +38,7 @@ export default function PagedReader(props: IReaderProps) { } function prevPage() { - if (curPage > 0) { setCurPage(curPage - 1); } + if (curPage > 0) { setCurPage(curPage - 1); } else if (curPage === 0) { prevChapter(); } } function keyboardControl(e:KeyboardEvent) { diff --git a/webUI/react/src/components/reader/pager/VerticalPager.tsx b/webUI/react/src/components/reader/pager/VerticalPager.tsx index 44044cd..2de8666 100644 --- a/webUI/react/src/components/reader/pager/VerticalPager.tsx +++ b/webUI/react/src/components/reader/pager/VerticalPager.tsx @@ -21,7 +21,7 @@ const useStyles = makeStyles({ export default function VerticalReader(props: IReaderProps) { const { - pages, settings, setCurPage, curPage, chapter, nextChapter, + pages, settings, setCurPage, curPage, chapter, nextChapter, prevChapter, } = props; const classes = useStyles(); @@ -47,6 +47,8 @@ export default function VerticalReader(props: IReaderProps) { pagesRef.current[curPage - 1]?.scrollIntoView(); setCurPage(curPage - 1); } + } else if (curPage === 0) { + prevChapter(); } } diff --git a/webUI/react/src/screens/Reader.tsx b/webUI/react/src/screens/Reader.tsx index b6dd8fb..4722eb6 100644 --- a/webUI/react/src/screens/Reader.tsx +++ b/webUI/react/src/screens/Reader.tsx @@ -139,6 +139,7 @@ export default function Reader() { } }, [curPage]); + // return spinner while chpater data is loading if (chapter.pageCount === -1) { return (
@@ -158,6 +159,12 @@ export default function Reader() { } }; + const prevChapter = () => { + if (chapter.index > 1) { + history.push(`/manga/${manga.id}/chapter/${chapter.index - 1}`); + } + }; + const pages = range(chapter.pageCount).map((index) => ({ index, src: `${serverAddress}/api/v1/manga/${mangaId}/chapter/${chapterIndex}/page/${index}`, @@ -181,6 +188,7 @@ export default function Reader() { manga={manga} chapter={chapter} nextChapter={nextChapter} + prevChapter={prevChapter} />
); diff --git a/webUI/react/src/typings.d.ts b/webUI/react/src/typings.d.ts index f318138..a7c6c2c 100644 --- a/webUI/react/src/typings.d.ts +++ b/webUI/react/src/typings.d.ts @@ -117,4 +117,5 @@ interface IReaderProps { manga: IMangaCard | IManga chapter: IChapter | IPartialChpter nextChapter: () => void + prevChapter: () => void }