Update chapter

This commit is contained in:
schroda
2024-12-07 03:43:18 +01:00
parent 916abd3bb1
commit 965aa7215c
9 changed files with 365 additions and 18 deletions

View File

@@ -23,6 +23,13 @@ export const getPage = (pageIndex: number, pages: ReaderProgressBarProps['pages'
};
};
/**
* for the double page mode the secondary page index has to be used to be able to correctly detect if the last page is visible
*
*/
export const getNextIndexFromPage = (page: ReaderProgressBarProps['pages'][number]) =>
page.secondary?.index ?? page.primary.index;
export const getNextPageIndex = (
offset: 'previous' | 'next',
pagesIndex: number,
@@ -30,9 +37,9 @@ export const getNextPageIndex = (
): number => {
switch (offset) {
case 'previous':
return pages[Math.max(0, pagesIndex - 1)].primary.index;
return getNextIndexFromPage(pages[Math.max(0, pagesIndex - 1)]);
case 'next':
return pages[Math.min(pages.length - 1, pagesIndex + 1)].primary.index;
return getNextIndexFromPage(pages[Math.min(pages.length - 1, pagesIndex + 1)]);
default:
throw new Error(`Unexpected offset "${offset}"`);
}