diff options
| author | Maze Winther <mazewinther@gmail.com> | 2026-02-10 16:28:21 +0100 |
|---|---|---|
| committer | Maze Winther <mazewinther@gmail.com> | 2026-02-10 16:28:21 +0100 |
| commit | fca99d6126c31fbb18ed9f1034cee6f940b040e8 (patch) | |
| tree | 11500ff0fcc4a933650e3e91f1ea00fd315c4d0c /apps/web/src/components/editor/timeline/timeline-playhead.tsx | |
| parent | 33a8705f0d967891402c61dd3192e6bad24921ef (diff) | |
| download | opencut-fca99d6126c31fbb18ed9f1034cee6f940b040e8.tar.gz | |
refactor
Diffstat (limited to 'apps/web/src/components/editor/timeline/timeline-playhead.tsx')
| -rw-r--r-- | apps/web/src/components/editor/timeline/timeline-playhead.tsx | 92 |
1 files changed, 0 insertions, 92 deletions
diff --git a/apps/web/src/components/editor/timeline/timeline-playhead.tsx b/apps/web/src/components/editor/timeline/timeline-playhead.tsx deleted file mode 100644 index 8af35dc9..00000000 --- a/apps/web/src/components/editor/timeline/timeline-playhead.tsx +++ /dev/null @@ -1,92 +0,0 @@ -"use client"; - -import { useRef } from "react"; -import { TIMELINE_CONSTANTS } from "@/constants/timeline-constants"; -import { useTimelinePlayhead } from "@/hooks/timeline/use-timeline-playhead"; -import { useEditor } from "@/hooks/use-editor"; - -interface TimelinePlayheadProps { - zoomLevel: number; - rulerRef: React.RefObject<HTMLDivElement | null>; - rulerScrollRef: React.RefObject<HTMLDivElement | null>; - tracksScrollRef: React.RefObject<HTMLDivElement | null>; - timelineRef: React.RefObject<HTMLDivElement | null>; - playheadRef?: React.RefObject<HTMLDivElement | null>; - isSnappingToPlayhead?: boolean; -} - -export function TimelinePlayhead({ - zoomLevel, - rulerRef, - rulerScrollRef, - tracksScrollRef, - timelineRef, - playheadRef: externalPlayheadRef, - isSnappingToPlayhead = false, -}: TimelinePlayheadProps) { - const editor = useEditor(); - const duration = editor.timeline.getTotalDuration(); - const internalPlayheadRef = useRef<HTMLDivElement>(null); - const playheadRef = externalPlayheadRef || internalPlayheadRef; - - const { playheadPosition, handlePlayheadMouseDown } = useTimelinePlayhead({ - zoomLevel, - rulerRef, - rulerScrollRef, - tracksScrollRef, - playheadRef, - }); - - const timelineContainerHeight = - tracksScrollRef.current?.clientHeight ?? - timelineRef.current?.clientHeight ?? - 400; - const totalHeight = Math.max(0, timelineContainerHeight - 4); - - const timelinePosition = - playheadPosition * TIMELINE_CONSTANTS.PIXELS_PER_SECOND * zoomLevel; - const leftPosition = timelinePosition; - - const handlePlayheadKeyDown = ( - event: React.KeyboardEvent<HTMLDivElement>, - ) => { - if (event.key !== "ArrowLeft" && event.key !== "ArrowRight") return; - - event.preventDefault(); - const step = 1 / Math.max(1, editor.project.getActive().settings.fps); - const direction = event.key === "ArrowRight" ? 1 : -1; - const nextTime = Math.max( - 0, - Math.min(duration, playheadPosition + direction * step), - ); - - editor.playback.seek({ time: nextTime }); - }; - - return ( - <div - ref={playheadRef} - role="slider" - aria-label="Timeline playhead" - aria-valuemin={0} - aria-valuemax={duration} - aria-valuenow={playheadPosition} - tabIndex={0} - className="pointer-events-auto absolute z-60" - style={{ - left: `${leftPosition}px`, - top: 0, - height: `${totalHeight}px`, - width: "2px", - }} - onMouseDown={handlePlayheadMouseDown} - onKeyDown={handlePlayheadKeyDown} - > - <div className="bg-foreground absolute left-0 h-full w-0.5 cursor-col-resize" /> - - <div - className={`absolute top-1 left-1/2 size-3 -translate-x-1/2 transform rounded-full border-2 shadow-xs ${isSnappingToPlayhead ? "bg-foreground border-foreground" : "bg-foreground border-foreground/50"}`} - /> - </div> - ); -} |
