From 70825bc938ef12dc4dba4469cbb041c428fec546 Mon Sep 17 00:00:00 2001 From: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com> Date: Sun, 10 Mar 2024 08:23:36 -0500 Subject: [PATCH] rename vars and change which div is absolutely positioned (#10358) --- .../timeline/EventReviewTimeline.tsx | 6 ++--- .../timeline/MotionReviewTimeline.tsx | 6 ++--- .../components/timeline/ReviewTimeline.tsx | 11 ++++++---- web/src/hooks/use-handle-dragging.ts | 22 +++++++++---------- 4 files changed, 24 insertions(+), 21 deletions(-) diff --git a/web/src/components/timeline/EventReviewTimeline.tsx b/web/src/components/timeline/EventReviewTimeline.tsx index 7e2b60bc3..5f6c6dc0a 100644 --- a/web/src/components/timeline/EventReviewTimeline.tsx +++ b/web/src/components/timeline/EventReviewTimeline.tsx @@ -46,7 +46,7 @@ export function EventReviewTimeline({ onHandlebarDraggingChange, }: EventReviewTimelineProps) { const [isDragging, setIsDragging] = useState(false); - const scrollTimeRef = useRef(null); + const handlebarRef = useRef(null); const timelineRef = useRef(null); const handlebarTimeRef = useRef(null); const timelineDuration = useMemo( @@ -68,7 +68,7 @@ export function EventReviewTimeline({ useDraggableHandler({ contentRef, timelineRef, - scrollTimeRef, + handlebarRef, alignStartDateToTimeline, alignEndDateToTimeline, segmentDuration, @@ -143,7 +143,7 @@ export function EventReviewTimeline({ return ( (null); + const handlebarRef = useRef(null); const timelineRef = useRef(null); const handlebarTimeRef = useRef(null); const timelineDuration = useMemo( @@ -69,7 +69,7 @@ export function MotionReviewTimeline({ useDraggableHandler({ contentRef, timelineRef, - scrollTimeRef, + handlebarRef, alignStartDateToTimeline, alignEndDateToTimeline, segmentDuration, @@ -145,7 +145,7 @@ export function MotionReviewTimeline({ return ( ; - scrollTimeRef: RefObject; + handlebarRef: RefObject; handlebarTimeRef: RefObject; handleMouseMove: ( e: @@ -27,7 +27,7 @@ export type ReviewTimelineProps = { export function ReviewTimeline({ timelineRef, - scrollTimeRef, + handlebarRef, handlebarTimeRef, handleMouseMove, handleMouseUp, @@ -50,14 +50,17 @@ export function ReviewTimeline({ >
{children}
{showHandlebar && ( -
+
; timelineRef: React.RefObject; - scrollTimeRef: React.RefObject; + handlebarRef: React.RefObject; alignStartDateToTimeline: (time: number) => number; alignEndDateToTimeline: (time: number) => number; segmentDuration: number; @@ -22,7 +22,7 @@ type DragHandlerProps = { function useDraggableHandler({ contentRef, timelineRef, - scrollTimeRef, + handlebarRef, alignStartDateToTimeline, segmentDuration, showHandlebar, @@ -83,12 +83,12 @@ function useDraggableHandler({ getClientYPosition(e); setIsDragging(true); - if (scrollTimeRef.current && clientYPosition && isDesktop) { - const handlebarRect = scrollTimeRef.current.getBoundingClientRect(); + if (handlebarRef.current && clientYPosition && isDesktop) { + const handlebarRect = handlebarRef.current.getBoundingClientRect(); setInitialClickAdjustment(clientYPosition - handlebarRect.top); } }, - [setIsDragging, getClientYPosition, scrollTimeRef, clientYPosition], + [setIsDragging, getClientYPosition, handlebarRef, clientYPosition], ); const handleMouseUp = useCallback( @@ -121,7 +121,7 @@ function useDraggableHandler({ scrollTimeline: boolean, updateHandle: boolean, ) => { - const thumb = scrollTimeRef.current; + const thumb = handlebarRef.current; if (thumb) { requestAnimationFrame(() => { thumb.style.top = `${newHandlePosition}px`; @@ -148,7 +148,7 @@ function useDraggableHandler({ } } }, - [segmentDuration, handlebarTimeRef, scrollTimeRef, setHandlebarTime], + [segmentDuration, handlebarTimeRef, handlebarRef, setHandlebarTime], ); const handleMouseMove = useCallback( @@ -158,7 +158,7 @@ function useDraggableHandler({ if ( !contentRef.current || !timelineRef.current || - !scrollTimeRef.current + !handlebarRef.current ) { return; } @@ -166,7 +166,7 @@ function useDraggableHandler({ getClientYPosition(e); }, - [contentRef, scrollTimeRef, timelineRef, getClientYPosition], + [contentRef, handlebarRef, timelineRef, getClientYPosition], ); useEffect(() => { @@ -277,7 +277,7 @@ function useDraggableHandler({ useEffect(() => { if ( timelineRef.current && - scrollTimeRef.current && + handlebarRef.current && showHandlebar && handlebarTime && !isDragging @@ -301,7 +301,7 @@ function useDraggableHandler({ } // we know that these deps are correct // eslint-disable-next-line react-hooks/exhaustive-deps - }, [handlebarTime, showHandlebar, scrollTimeRef, timelineStartAligned]); + }, [handlebarTime, showHandlebar, handlebarRef, timelineStartAligned]); return { handleMouseDown, handleMouseUp, handleMouseMove }; }