Always use "secondary page index" as "current page index" when available

There was an issue where one had to click twice at the end of a chapter in the "double page mode" to get to the chapter transition page.
This was caused due to setting the "primary page index" as the "current page index" and thus, when opening the next page, it got changed to the "secondary page index". However, this page was already visible and therefore, there was no visual change.
This commit is contained in:
schroda
2024-12-12 13:21:29 +01:00
parent 89b81de830
commit 9a8655db2f
4 changed files with 33 additions and 26 deletions

View File

@@ -13,7 +13,7 @@ import { useMemo } from 'react';
import FormControl from '@mui/material/FormControl';
import InputLabel from '@mui/material/InputLabel';
import { Select } from '@/modules/core/components/inputs/Select.tsx';
import { getPage } from '@/modules/reader/utils/ReaderProgressBar.utils.tsx';
import { getNextIndexFromPage, getPage } from '@/modules/reader/utils/ReaderProgressBar.utils.tsx';
import { ReaderStatePages } from '@/modules/reader/types/ReaderProgressBar.types.ts';
import { ReaderControls } from '@/modules/reader/services/ReaderControls.ts';
import { useGetOptionForDirection } from '@/modules/theme/services/ThemeCreator.ts';
@@ -50,7 +50,7 @@ export const ReaderNavBarDesktopPageNavigation = ({
<Select
labelId="reader-nav-bar-desktop-page-select"
label={t('reader.page_info.label.page')}
value={currentPage.primary.index}
value={getNextIndexFromPage(currentPage)}
onChange={(e) => openPage(e.target.value as number)}
>
{pages.map(({ primary: { index }, name }) => (

View File

@@ -20,6 +20,7 @@ import { ReaderProgressBarSlotsContainer } from '@/modules/reader/components/ove
import { ProgressBarHighlightReadPages } from '@/modules/reader/components/overlay/progress-bar/ProgressBarHighlightReadPages.tsx';
import { ReaderProgressBarCurrentPageSlot } from '@/modules/reader/components/overlay/progress-bar/ReaderProgressBarCurrentPageSlot.tsx';
import {
getNextIndexFromPage,
getPage,
getPageForMousePos,
getProgressBarPositionInfo,
@@ -116,13 +117,15 @@ export const ReaderProgressBar = ({
}
openPage(
getPageForMousePos(
event.touches[0],
progressBarRef.current.getBoundingClientRect(),
pages,
isHorizontalPosition,
getOptionForDirection,
).primary.index,
getNextIndexFromPage(
getPageForMousePos(
event.touches[0],
progressBarRef.current.getBoundingClientRect(),
pages,
isHorizontalPosition,
getOptionForDirection,
),
),
);
setIsDragging(true);
}}
@@ -133,13 +136,15 @@ export const ReaderProgressBar = ({
}
openPage(
getPageForMousePos(
event,
progressBarRef.current.getBoundingClientRect(),
pages,
isHorizontalPosition,
getOptionForDirection,
).primary.index,
getNextIndexFromPage(
getPageForMousePos(
event,
progressBarRef.current.getBoundingClientRect(),
pages,
isHorizontalPosition,
getOptionForDirection,
),
),
);
setIsDragging(true);
}}

View File

@@ -13,7 +13,7 @@ import { ReaderService } from '@/modules/reader/services/ReaderService.ts';
import { ReaderPagerProps, ReadingDirection } from '@/modules/reader/types/Reader.types.ts';
import { applyStyles } from '@/modules/core/utils/ApplyStyles.ts';
import { createReaderPage } from '@/modules/reader/utils/ReaderPager.utils.tsx';
import { getPage } from '@/modules/reader/utils/ReaderProgressBar.utils.tsx';
import { getNextIndexFromPage, getPage } from '@/modules/reader/utils/ReaderProgressBar.utils.tsx';
const getPagePosition = (
pageType: 'first' | 'second',
@@ -58,7 +58,7 @@ export const ReaderDoublePagedPager = ({
createPage={(page, pagesIndex, shouldLoad, shouldDisplay) => {
const { primary, secondary } = page;
const currentSecondaryPageIndex = currentPage.secondary?.index ?? currentPage.primary.index;
const currentSecondaryPageIndex = getNextIndexFromPage(currentPage);
const hasSecondaryPage = !!secondary;
const isPrimaryPage = currentPage.primary.index === primary.index;

View File

@@ -110,15 +110,17 @@ export const useHandleProgressDragging = (
return;
}
const newPageIndex = getPageForMousePos(
coordinates,
progressBarRef.current.getBoundingClientRect(),
pages,
isHorizontal,
getOptionForDirection,
).primary.index;
const newPageIndex = getNextIndexFromPage(
getPageForMousePos(
coordinates,
progressBarRef.current.getBoundingClientRect(),
pages,
isHorizontal,
getOptionForDirection,
),
);
const hasCurrentPageIndexChanged = currentPage.primary.index !== newPageIndex;
const hasCurrentPageIndexChanged = getNextIndexFromPage(currentPage) !== newPageIndex;
if (!hasCurrentPageIndexChanged) {
return;
}