From d643a9a27767d001301f5d8cefc68f227582c446 Mon Sep 17 00:00:00 2001 From: Maze Winther Date: Fri, 11 Jul 2025 00:57:09 +0200 Subject: small refactor --- apps/web/src/components/editor/timeline-playhead.tsx | 11 ++++++++++- apps/web/src/components/editor/timeline.tsx | 5 ++++- 2 files changed, 14 insertions(+), 2 deletions(-) (limited to 'apps/web/src/components') diff --git a/apps/web/src/components/editor/timeline-playhead.tsx b/apps/web/src/components/editor/timeline-playhead.tsx index 4deb6797..ce4ed1ff 100644 --- a/apps/web/src/components/editor/timeline-playhead.tsx +++ b/apps/web/src/components/editor/timeline-playhead.tsx @@ -1,5 +1,6 @@ "use client"; +import { useRef } from "react"; import { TimelineTrack } from "@/types/timeline"; import { TIMELINE_CONSTANTS, @@ -18,6 +19,7 @@ interface TimelinePlayheadProps { tracksScrollRef: React.RefObject; trackLabelsRef?: React.RefObject; timelineRef: React.RefObject; + playheadRef?: React.RefObject; } export function TimelinePlayhead({ @@ -31,7 +33,10 @@ export function TimelinePlayhead({ tracksScrollRef, trackLabelsRef, timelineRef, + playheadRef: externalPlayheadRef, }: TimelinePlayheadProps) { + const internalPlayheadRef = useRef(null); + const playheadRef = externalPlayheadRef || internalPlayheadRef; const { playheadPosition, handlePlayheadMouseDown } = useTimelinePlayhead({ currentTime, duration, @@ -40,6 +45,7 @@ export function TimelinePlayhead({ rulerRef, rulerScrollRef, tracksScrollRef, + playheadRef, }); // Use timeline container height minus a few pixels for breathing room @@ -57,7 +63,8 @@ export function TimelinePlayhead({ return (
) { const { handleRulerMouseDown, isDraggingRuler } = useTimelinePlayhead({ currentTime, @@ -93,6 +101,7 @@ export function useTimelinePlayheadRuler({ rulerRef, rulerScrollRef, tracksScrollRef, + playheadRef, }); return { handleRulerMouseDown, isDraggingRuler }; diff --git a/apps/web/src/components/editor/timeline.tsx b/apps/web/src/components/editor/timeline.tsx index fb4723d6..53a7aacd 100644 --- a/apps/web/src/components/editor/timeline.tsx +++ b/apps/web/src/components/editor/timeline.tsx @@ -124,6 +124,7 @@ export function Timeline() { const rulerScrollRef = useRef(null); const tracksScrollRef = useRef(null); const trackLabelsRef = useRef(null); + const playheadRef = useRef(null); const isUpdatingRef = useRef(false); const lastRulerSync = useRef(0); const lastTracksSync = useRef(0); @@ -137,6 +138,7 @@ export function Timeline() { rulerRef, rulerScrollRef, tracksScrollRef, + playheadRef, }); // Timeline content click to seek handler @@ -148,7 +150,7 @@ export function Timeline() { } // Don't seek if clicking on playhead - if ((e.target as HTMLElement).closest(".playhead")) { + if (playheadRef.current?.contains(e.target as Node)) { return; } @@ -880,6 +882,7 @@ export function Timeline() { tracksScrollRef={tracksScrollRef} trackLabelsRef={trackLabelsRef} timelineRef={timelineRef} + playheadRef={playheadRef} /> {/* Timeline Header with Ruler */}
-- cgit v1.3.1