diff --git a/server/src/main/kotlin/ir/armor/tachidesk/impl/Chapter.kt b/server/src/main/kotlin/ir/armor/tachidesk/impl/Chapter.kt index 60e4421..1a800f3 100644 --- a/server/src/main/kotlin/ir/armor/tachidesk/impl/Chapter.kt +++ b/server/src/main/kotlin/ir/armor/tachidesk/impl/Chapter.kt @@ -22,7 +22,6 @@ import org.jetbrains.exposed.sql.and import org.jetbrains.exposed.sql.deleteWhere import org.jetbrains.exposed.sql.insert import org.jetbrains.exposed.sql.select -import org.jetbrains.exposed.sql.selectAll import org.jetbrains.exposed.sql.transactions.transaction import org.jetbrains.exposed.sql.update @@ -139,7 +138,7 @@ object Chapter { ).awaitSingle() val chapterId = chapterEntry[ChapterTable.id].value - val chapterCount = transaction { ChapterTable.selectAll().count() } + val chapterCount = transaction { ChapterTable.select { ChapterTable.manga eq mangaId }.count() } // update page list for this chapter transaction { diff --git a/webUI/react/src/components/reader/pager/PagedPager.tsx b/webUI/react/src/components/reader/pager/PagedPager.tsx index 3fd2474..35fd365 100644 --- a/webUI/react/src/components/reader/pager/PagedPager.tsx +++ b/webUI/react/src/components/reader/pager/PagedPager.tsx @@ -24,7 +24,7 @@ const useStyles = makeStyles({ export default function PagedReader(props: IReaderProps) { const { - pages, settings, setCurPage, curPage, manga, chapter, + pages, settings, setCurPage, curPage, manga, chapter, nextChapter, } = props; const classes = useStyles(); @@ -36,7 +36,7 @@ export default function PagedReader(props: IReaderProps) { if (curPage < pages.length - 1) { setCurPage(curPage + 1); } else if (settings.loadNextonEnding) { - history.push(`/manga/${manga.id}/chapter/${chapter.index + 1}`); + nextChapter(); } } diff --git a/webUI/react/src/components/reader/pager/VerticalPager.tsx b/webUI/react/src/components/reader/pager/VerticalPager.tsx index 890a6fc..cf0b389 100644 --- a/webUI/react/src/components/reader/pager/VerticalPager.tsx +++ b/webUI/react/src/components/reader/pager/VerticalPager.tsx @@ -23,7 +23,7 @@ const useStyles = makeStyles({ export default function VerticalReader(props: IReaderProps) { const { - pages, settings, setCurPage, curPage, manga, chapter, + pages, settings, setCurPage, curPage, manga, chapter, nextChapter, } = props; const classes = useStyles(); @@ -31,8 +31,7 @@ export default function VerticalReader(props: IReaderProps) { const handleLoadNextonEnding = () => { if ((window.innerHeight + window.scrollY) >= document.body.offsetHeight) { - setCurPage(0); - history.push(`/manga/${manga.id}/chapter/${chapter.index + 1}`); + nextChapter(); } }; useEffect(() => { diff --git a/webUI/react/src/screens/Reader.tsx b/webUI/react/src/screens/Reader.tsx index bdcce66..7436dc8 100644 --- a/webUI/react/src/screens/Reader.tsx +++ b/webUI/react/src/screens/Reader.tsx @@ -9,7 +9,7 @@ import CircularProgress from '@material-ui/core/CircularProgress'; import { makeStyles } from '@material-ui/core/styles'; import React, { useContext, useEffect, useState } from 'react'; -import { useParams } from 'react-router-dom'; +import { useHistory, useParams } from 'react-router-dom'; import HorizontalPager from '../components/reader/pager/HorizontalPager'; import Page from '../components/reader/Page'; import PageNumber from '../components/reader/PageNumber'; @@ -63,6 +63,7 @@ export default function Reader() { const [settings, setSettings] = useLocalStorage('readerSettings', defaultReaderSettings); const classes = useStyles(settings)(); + const history = useHistory(); const [serverAddress] = useLocalStorage('serverBaseURL', ''); @@ -133,6 +134,12 @@ export default function Reader() { ); } + const nextChapter = () => { + if (chapter.index < chapter.chapterCount) { + 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}`, @@ -155,6 +162,7 @@ export default function Reader() { settings={settings} manga={manga} chapter={chapter} + nextChapter={nextChapter} /> ); diff --git a/webUI/react/src/typings.d.ts b/webUI/react/src/typings.d.ts index 4d11494..58ebf12 100644 --- a/webUI/react/src/typings.d.ts +++ b/webUI/react/src/typings.d.ts @@ -116,4 +116,5 @@ interface IReaderProps { settings: IReaderSettings manga: IMangaCard | IManga chapter: IChapter | IPartialChpter + nextChapter: () => void }