fix: page indicator not tracking scroll when showing all pages
The IntersectionObserver was only set up when virtualizing pages, but the page indicator needs to work in both modes: - Virtualized mode (worksheet creator): lazy load pages - Non-virtualized mode (shared worksheets): show all pages Changed observer setup to always run when totalPages > 1, regardless of virtualization mode. The visible pages update logic still only runs when virtualizing to avoid unnecessary state updates. This fixes the page indicator being stuck on page 1 when initialData is provided (non-virtualized mode). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
8b361f06a4
commit
3d157e32ed
|
|
@ -161,18 +161,13 @@ function PreviewContent({ formState, initialData, isScrolling = false }: Workshe
|
|||
}
|
||||
})
|
||||
|
||||
// Intersection Observer to track visible pages (only when virtualizing)
|
||||
// Intersection Observer to track current page (works with or without virtualization)
|
||||
useEffect(() => {
|
||||
console.log('[PAGE INDICATOR] Observer useEffect triggered - shouldVirtualize:', shouldVirtualize, 'totalPages:', totalPages, 'refsReady:', refsReady)
|
||||
|
||||
if (!shouldVirtualize) {
|
||||
console.log('[PAGE INDICATOR] Skipping observer setup - not virtualizing')
|
||||
return // Skip virtualization when showing all pages
|
||||
}
|
||||
|
||||
if (totalPages <= 1) {
|
||||
console.log('[PAGE INDICATOR] Skipping observer setup - only', totalPages, 'page(s)')
|
||||
return // No need for virtualization with single page
|
||||
return // No need for page tracking with single page
|
||||
}
|
||||
|
||||
// Wait for refs to be populated
|
||||
|
|
@ -211,7 +206,8 @@ function PreviewContent({ formState, initialData, isScrolling = false }: Workshe
|
|||
console.log('[PAGE INDICATOR] No visible page (maxRatio = 0), keeping current page')
|
||||
}
|
||||
|
||||
// Update visible pages set
|
||||
// Update visible pages set (only when virtualizing)
|
||||
if (shouldVirtualize) {
|
||||
setVisiblePages((prev) => {
|
||||
const next = new Set(prev)
|
||||
|
||||
|
|
@ -229,6 +225,7 @@ function PreviewContent({ formState, initialData, isScrolling = false }: Workshe
|
|||
|
||||
return next
|
||||
})
|
||||
}
|
||||
},
|
||||
{
|
||||
root: null, // Use viewport as root (scrolling happens in parent)
|
||||
|
|
|
|||
Loading…
Reference in New Issue