fix to navigate to another page
deploy to danak / build_and_deploy (push) Has been cancelled

This commit is contained in:
hamid zarghami
2026-06-13 09:47:37 +03:30
parent 89d9155184
commit a1c182afde
+26 -62
View File
@@ -347,81 +347,45 @@ const BookViewer: FC<BookViewerProps> = ({ pages, catalogSize, documentSettings
setIsAutoPlayActive(prev => !prev);
}, [pages.length]);
const handleLinkClick = useCallback((linkUrl: string) => {
if (pages.length <= 1) return;
if (linkUrl.startsWith('page://')) {
const action = linkUrl.replace('page://', '');
const pageFlipAPI = bookRef.current?.pageFlip() as PageFlipWithFlipController | undefined;
const navigateToPageIndex = useCallback(
(targetIndex: number) => {
const pageFlipAPI = bookRef.current?.pageFlip();
if (!pageFlipAPI) return;
const clamped = Math.max(0, Math.min(targetIndex, pages.length - 1));
pageFlipAPI.turnToPage(clamped);
lastFlipPageRef.current = clamped;
scheduleEntranceForSpread(clamped);
},
[pages.length, scheduleEntranceForSpread],
);
const handleLinkClick = useCallback(
(linkUrl: string) => {
if (pages.length <= 1) return;
stopAutoPlayByUser();
if (!linkUrl.startsWith('page://')) return;
const action = linkUrl.replace('page://', '');
if (action === 'next') {
goToNextPage();
} else if (action === 'prev') {
goToPrevPage();
} else if (action === 'first') {
// رفتن به صفحه اول
const flipToFirst = () => {
if (currentPage > 0) {
triggerFlipPrev(pageFlipAPI);
setTimeout(() => {
setCurrentPage(prev => {
if (prev > 1) {
flipToFirst();
}
return prev - 1;
});
}, 300);
}
};
flipToFirst();
navigateToPageIndex(0);
} else if (action === 'last') {
// رفتن به صفحه آخر
const lastPageIndex = pages.length - 1;
const flipToLast = () => {
if (currentPage < lastPageIndex) {
pageFlipAPI.flipNext();
setTimeout(() => {
setCurrentPage(prev => {
if (prev < lastPageIndex - 1) {
flipToLast();
}
return prev + 1;
});
}, 300);
}
};
flipToLast();
navigateToPageIndex(pages.length - 1);
} else {
// شماره صفحه مشخص (مثل page://3)
const pageNum = parseInt(action, 10);
if (!isNaN(pageNum) && pageNum >= 1 && pageNum <= pages.length) {
const targetIndex = pageNum - 1;
const diff = targetIndex - currentPage;
const flipToTarget = (remaining: number) => {
if (remaining === 0) return;
if (remaining > 0) {
pageFlipAPI.flipNext();
setTimeout(() => {
setCurrentPage(prev => prev + 1);
flipToTarget(remaining - 1);
}, 300);
} else {
triggerFlipPrev(pageFlipAPI);
setTimeout(() => {
setCurrentPage(prev => prev - 1);
flipToTarget(remaining + 1);
}, 300);
}
};
flipToTarget(diff);
navigateToPageIndex(pageNum - 1);
}
}
}
}, [currentPage, pages.length, goToNextPage, goToPrevPage]);
},
[pages.length, goToNextPage, goToPrevPage, navigateToPageIndex, stopAutoPlayByUser],
);
const prevFlipKeyRef = useRef(flipKey);
useEffect(() => {