From 28957004ba9d636a9e567ce968ad545bc9659618 Mon Sep 17 00:00:00 2001 From: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com> Date: Thu, 7 Mar 2024 16:24:33 -0600 Subject: [PATCH] better segment clicking on motion segments --- web/src/components/timeline/MotionSegment.tsx | 38 +++++++++++-------- web/src/hooks/use-motion-segment-utils.ts | 2 +- web/src/pages/UIPlayground.tsx | 4 +- 3 files changed, 26 insertions(+), 18 deletions(-) diff --git a/web/src/components/timeline/MotionSegment.tsx b/web/src/components/timeline/MotionSegment.tsx index 2c7138967..2efdd73d0 100644 --- a/web/src/components/timeline/MotionSegment.tsx +++ b/web/src/components/timeline/MotionSegment.tsx @@ -82,6 +82,19 @@ export function MotionSegment({ return isMobile ? 30 : 50; }, []); + const segmentWidth = useMemo(() => { + return interpolateMotionAudioData( + getMotionSegmentValue(segmentTime + segmentDuration / 2), + maxSegmentWidth, + ); + }, [ + segmentTime, + segmentDuration, + maxSegmentWidth, + getMotionSegmentValue, + interpolateMotionAudioData, + ]); + const alignedMinimapStartTime = useMemo( () => alignStartDateToTimeline(minimapStartTime ?? 0), [minimapStartTime, alignStartDateToTimeline], @@ -154,13 +167,18 @@ export function MotionSegment({ }; const segmentClick = useCallback(() => { - if (startTimestamp && setHandlebarTime) { + if (startTimestamp && setHandlebarTime && segmentWidth > 1) { setHandlebarTime(startTimestamp); } - }, [startTimestamp, setHandlebarTime]); + }, [startTimestamp, setHandlebarTime, segmentWidth]); return ( -