From c6fe715e57a4f1828310d428d983fb27f9819f96 Mon Sep 17 00:00:00 2001 From: schroda <50052685+schroda@users.noreply.github.com> Date: Wed, 12 Feb 2025 19:39:58 +0100 Subject: [PATCH] Handle faulty "lastPageRead" values There seems to be a bug on the server which sets the "lastPageRead" of a chapter to -1 which should not happen --- src/modules/reader/components/viewer/ReaderViewer.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/reader/components/viewer/ReaderViewer.tsx b/src/modules/reader/components/viewer/ReaderViewer.tsx index 48e57056..7189ece7 100644 --- a/src/modules/reader/components/viewer/ReaderViewer.tsx +++ b/src/modules/reader/components/viewer/ReaderViewer.tsx @@ -62,7 +62,7 @@ import { getReaderChapterViewerCurrentPageIndex, getReaderChapterViewResumeMode, } from '@/modules/reader/utils/Reader.utils.ts'; -import { noOp } from '@/lib/HelperFunctions.ts'; +import { coerceIn, noOp } from '@/lib/HelperFunctions.ts'; import { useNavBarContext } from '@/modules/navigation-bar/contexts/NavbarContext.tsx'; import { NavbarContextType } from '@/modules/navigation-bar/NavigationBar.types.ts'; @@ -341,7 +341,7 @@ const BaseReaderViewer = forwardRef( nextChapterId={nextChapter?.id} isPreviousChapterVisible={isPreviousChapterVisible} isNextChapterVisible={isNextChapterVisible} - lastPageRead={chapter.lastPageRead} + lastPageRead={coerceIn(chapter.lastPageRead, 0, chapter.pageCount - 1)} currentPageIndex={getReaderChapterViewerCurrentPageIndex( currentPageIndex, chapter,