summaryrefslogtreecommitdiff
path: root/apps/web/src/components/editor/timeline/timeline-wheel-handler.tsx
blob: 430d65aee7c47f8440aca3b8465a1b84cc13728e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { useEffect } from "react";

export interface TimelineWheelHandlerProps {
  timelineRef: React.RefObject<HTMLDivElement>;
  isInTimeline: boolean;
  handleWheel: (e: React.WheelEvent) => void;
}

export function useTimelineWheelHandler({
  timelineRef,
  isInTimeline,
  handleWheel,
}: TimelineWheelHandlerProps) {
  // Add wheel event listeners with passive: false to allow preventDefault
  useEffect(() => {
    const timelineContainer = timelineRef.current;
    if (!timelineContainer || !isInTimeline) return;

    const handleWheelCapture = (e: WheelEvent) => {
      // Call the existing handleWheel function
      handleWheel(e as any);
    };

    // Add wheel event listener with passive: false to allow preventDefault
    timelineContainer.addEventListener("wheel", handleWheelCapture, { passive: false });

    return () => {
      timelineContainer.removeEventListener("wheel", handleWheelCapture);
    };
  }, [handleWheel, isInTimeline, timelineRef]);

  return null;
}