2024-03-04 19:42:51 +03:00
|
|
|
import useDraggableHandler from "@/hooks/use-handle-dragging";
|
|
|
|
|
import {
|
|
|
|
|
useEffect,
|
|
|
|
|
useCallback,
|
|
|
|
|
useMemo,
|
|
|
|
|
useRef,
|
|
|
|
|
useState,
|
|
|
|
|
RefObject,
|
|
|
|
|
} from "react";
|
|
|
|
|
import MotionSegment from "./MotionSegment";
|
|
|
|
|
import { useEventUtils } from "@/hooks/use-event-utils";
|
2024-03-05 22:55:44 +03:00
|
|
|
import { MotionData, ReviewSegment, ReviewSeverity } from "@/types/review";
|
2024-03-04 19:42:51 +03:00
|
|
|
import ReviewTimeline from "./ReviewTimeline";
|
|
|
|
|
|
|
|
|
|
export type MotionReviewTimelineProps = {
|
|
|
|
|
segmentDuration: number;
|
|
|
|
|
timestampSpread: number;
|
|
|
|
|
timelineStart: number;
|
|
|
|
|
timelineEnd: number;
|
|
|
|
|
showHandlebar?: boolean;
|
|
|
|
|
handlebarTime?: number;
|
|
|
|
|
setHandlebarTime?: React.Dispatch<React.SetStateAction<number>>;
|
|
|
|
|
showMinimap?: boolean;
|
|
|
|
|
minimapStartTime?: number;
|
|
|
|
|
minimapEndTime?: number;
|
|
|
|
|
events: ReviewSegment[];
|
2024-03-05 22:55:44 +03:00
|
|
|
motion_events: MotionData[];
|
2024-03-04 19:42:51 +03:00
|
|
|
severityType: ReviewSeverity;
|
|
|
|
|
contentRef: RefObject<HTMLDivElement>;
|
|
|
|
|
onHandlebarDraggingChange?: (isDragging: boolean) => void;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export function MotionReviewTimeline({
|
|
|
|
|
segmentDuration,
|
|
|
|
|
timestampSpread,
|
|
|
|
|
timelineStart,
|
|
|
|
|
timelineEnd,
|
|
|
|
|
showHandlebar = false,
|
|
|
|
|
handlebarTime,
|
|
|
|
|
setHandlebarTime,
|
|
|
|
|
showMinimap = false,
|
|
|
|
|
minimapStartTime,
|
|
|
|
|
minimapEndTime,
|
|
|
|
|
events,
|
|
|
|
|
motion_events,
|
|
|
|
|
contentRef,
|
|
|
|
|
onHandlebarDraggingChange,
|
|
|
|
|
}: MotionReviewTimelineProps) {
|
|
|
|
|
const [isDragging, setIsDragging] = useState(false);
|
|
|
|
|
const scrollTimeRef = useRef<HTMLDivElement>(null);
|
|
|
|
|
const timelineRef = useRef<HTMLDivElement>(null);
|
|
|
|
|
const handlebarTimeRef = useRef<HTMLDivElement>(null);
|
|
|
|
|
const timelineDuration = useMemo(
|
|
|
|
|
() => timelineStart - timelineEnd,
|
|
|
|
|
[timelineEnd, timelineStart],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const { alignStartDateToTimeline, alignEndDateToTimeline } = useEventUtils(
|
|
|
|
|
events,
|
|
|
|
|
segmentDuration,
|
|
|
|
|
);
|
|
|
|
|
|
2024-03-09 01:49:10 +03:00
|
|
|
const timelineStartAligned = useMemo(
|
|
|
|
|
() => alignStartDateToTimeline(timelineStart),
|
|
|
|
|
[timelineStart, alignStartDateToTimeline],
|
|
|
|
|
);
|
|
|
|
|
|
2024-03-04 19:42:51 +03:00
|
|
|
const { handleMouseDown, handleMouseUp, handleMouseMove } =
|
|
|
|
|
useDraggableHandler({
|
|
|
|
|
contentRef,
|
|
|
|
|
timelineRef,
|
|
|
|
|
scrollTimeRef,
|
|
|
|
|
alignStartDateToTimeline,
|
|
|
|
|
alignEndDateToTimeline,
|
|
|
|
|
segmentDuration,
|
|
|
|
|
showHandlebar,
|
|
|
|
|
handlebarTime,
|
|
|
|
|
setHandlebarTime,
|
|
|
|
|
timelineDuration,
|
2024-03-09 01:49:10 +03:00
|
|
|
timelineStartAligned,
|
2024-03-04 19:42:51 +03:00
|
|
|
isDragging,
|
|
|
|
|
setIsDragging,
|
|
|
|
|
handlebarTimeRef,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Generate segments for the timeline
|
|
|
|
|
const generateSegments = useCallback(() => {
|
|
|
|
|
const segmentCount = timelineDuration / segmentDuration;
|
|
|
|
|
|
|
|
|
|
return Array.from({ length: segmentCount }, (_, index) => {
|
2024-03-09 01:49:10 +03:00
|
|
|
const segmentTime = timelineStartAligned - index * segmentDuration;
|
2024-03-04 19:42:51 +03:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<MotionSegment
|
|
|
|
|
key={segmentTime}
|
|
|
|
|
events={events}
|
|
|
|
|
motion_events={motion_events}
|
|
|
|
|
segmentDuration={segmentDuration}
|
|
|
|
|
segmentTime={segmentTime}
|
|
|
|
|
timestampSpread={timestampSpread}
|
|
|
|
|
showMinimap={showMinimap}
|
|
|
|
|
minimapStartTime={minimapStartTime}
|
|
|
|
|
minimapEndTime={minimapEndTime}
|
2024-03-07 00:35:10 +03:00
|
|
|
setHandlebarTime={setHandlebarTime}
|
2024-03-04 19:42:51 +03:00
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
// we know that these deps are correct
|
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
|
}, [
|
|
|
|
|
segmentDuration,
|
|
|
|
|
timestampSpread,
|
2024-03-09 01:49:10 +03:00
|
|
|
timelineStartAligned,
|
2024-03-04 19:42:51 +03:00
|
|
|
timelineDuration,
|
|
|
|
|
showMinimap,
|
|
|
|
|
minimapStartTime,
|
|
|
|
|
minimapEndTime,
|
|
|
|
|
events,
|
2024-03-05 01:18:27 +03:00
|
|
|
motion_events,
|
2024-03-04 19:42:51 +03:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
const segments = useMemo(
|
|
|
|
|
() => generateSegments(),
|
|
|
|
|
// we know that these deps are correct
|
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
|
[
|
|
|
|
|
segmentDuration,
|
|
|
|
|
timestampSpread,
|
2024-03-09 01:49:10 +03:00
|
|
|
timelineStartAligned,
|
2024-03-04 19:42:51 +03:00
|
|
|
timelineDuration,
|
|
|
|
|
showMinimap,
|
|
|
|
|
minimapStartTime,
|
|
|
|
|
minimapEndTime,
|
|
|
|
|
events,
|
2024-03-05 01:18:27 +03:00
|
|
|
motion_events,
|
2024-03-04 19:42:51 +03:00
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (onHandlebarDraggingChange) {
|
|
|
|
|
onHandlebarDraggingChange(isDragging);
|
|
|
|
|
}
|
|
|
|
|
}, [isDragging, onHandlebarDraggingChange]);
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<ReviewTimeline
|
|
|
|
|
timelineRef={timelineRef}
|
|
|
|
|
scrollTimeRef={scrollTimeRef}
|
|
|
|
|
handlebarTimeRef={handlebarTimeRef}
|
|
|
|
|
handleMouseMove={handleMouseMove}
|
|
|
|
|
handleMouseUp={handleMouseUp}
|
|
|
|
|
handleMouseDown={handleMouseDown}
|
|
|
|
|
segmentDuration={segmentDuration}
|
|
|
|
|
showHandlebar={showHandlebar}
|
|
|
|
|
isDragging={isDragging}
|
|
|
|
|
>
|
|
|
|
|
{segments}
|
|
|
|
|
</ReviewTimeline>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default MotionReviewTimeline;
|