Merge pull request #20007 from overleaf/ae-review-panel-container-ref

Fix event listener attachment to review panel container

GitOrigin-RevId: ceb1023d7be48d9b88e725963124cd04e98127bd
This commit is contained in:
Alf Eaton 2024-08-20 08:36:18 +01:00 committed by Copybot
parent 7e187d903b
commit ee8b8d0692

View file

@ -100,17 +100,29 @@ const ReviewPanelCurrentFile: FC = () => {
} }
}, [state, updatePositions]) }, [state, updatePositions])
const handleContainer = useCallback(
(element: HTMLDivElement | null) => {
containerRef.current = element
if (containerRef.current) {
containerRef.current.addEventListener(
'review-panel:position',
updatePositions
)
}
},
[updatePositions]
)
useEffect(() => { useEffect(() => {
const element = containerRef.current
if (element) {
element.addEventListener('review-panel:position', updatePositions)
// view.scrollDOM.addEventListener('scroll', positionListener)
return () => { return () => {
element.removeEventListener('review-panel:position', updatePositions) if (containerRef.current) {
// view.scrollDOM.removeEventListener('scroll', positionListener) containerRef.current.removeEventListener(
'review-panel:position',
updatePositions
)
} }
} }
}, [view, updatePositions]) }, [updatePositions])
const buildEntries = useCallback(() => { const buildEntries = useCallback(() => {
if (ranges) { if (ranges) {
@ -194,7 +206,7 @@ const ReviewPanelCurrentFile: FC = () => {
rangesWithPositions.comments.length === 0 rangesWithPositions.comments.length === 0
return ( return (
<div ref={containerRef}> <div ref={handleContainer}>
{selectionCoords && ( {selectionCoords && (
<div <div
className="review-panel-entry" className="review-panel-entry"