Improve reader chapter update on last page reached

In case "endReached" is force set to "true" the chapters last page index should always be set to prevent 2 chapter updates
 - 1. for second to last page, read true
 - 2. last page, read true

This only happens in "continuous pagers" which have to handle cases where the end of the last page is already visible while the last page itself is too small to ever get set as the "current page index"
This commit is contained in:
schroda
2024-12-16 14:48:30 +01:00
parent b4c1cdee77
commit e95cc232a2

View File

@@ -389,8 +389,10 @@ export class ReaderControls {
return;
}
const hasLastPageReadChanged = pageIndex !== currentChapterUpToDate.lastPageRead;
const isLastPage = pageIndex === currentChapterUpToDate.pageCount - 1;
const actualPageIndex = endReached ? currentChapterUpToDate.pageCount - 1 : pageIndex;
const hasLastPageReadChanged = actualPageIndex !== currentChapterUpToDate.lastPageRead;
const isLastPage = actualPageIndex === currentChapterUpToDate.pageCount - 1;
const hasIsReadChanged = (isLastPage || endReached) && !currentChapterUpToDate.isRead;
const shouldUpdateChapter = hasLastPageReadChanged || hasIsReadChanged;
@@ -399,7 +401,7 @@ export class ReaderControls {
}
updateChapter({
lastPageRead: hasLastPageReadChanged ? pageIndex : undefined,
lastPageRead: hasLastPageReadChanged ? actualPageIndex : undefined,
isRead: isLastPage ? true : undefined,
});
};