Stirling-PDF/frontend/src/components/viewer/ScrollAPIBridge.tsx
Reece Browne 065bb46c1e
Feature/v2/embed pdf (#4437)
Switched to Embed pdf for viewer

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: James Brunton <james@stirlingpdf.com>
2025-09-19 15:35:51 +01:00

32 lines
941 B
TypeScript

import { useEffect } from 'react';
import { useScroll } from '@embedpdf/plugin-scroll/react';
import { useViewer } from '../../contexts/ViewerContext';
/**
* ScrollAPIBridge manages scroll state and exposes scroll actions.
* Registers with ViewerContext to provide scroll functionality to UI components.
*/
export function ScrollAPIBridge() {
const { provides: scroll, state: scrollState } = useScroll();
const { registerBridge, triggerImmediateScrollUpdate } = useViewer();
useEffect(() => {
if (scroll && scrollState) {
const newState = {
currentPage: scrollState.currentPage,
totalPages: scrollState.totalPages,
};
// Trigger immediate update for responsive UI
triggerImmediateScrollUpdate(newState.currentPage, newState.totalPages);
registerBridge('scroll', {
state: newState,
api: scroll
});
}
}, [scroll, scrollState]);
return null;
}