mirror of
https://github.com/blakeblackshear/frigate.git
synced 2024-11-21 19:07:46 +01:00
Timeline handlebar tweaks (#10336)
* initial offset click for desktop only * align start timeline and update pixel math
This commit is contained in:
parent
3d539c93eb
commit
05a66ce90d
@ -59,6 +59,11 @@ export function EventReviewTimeline({
|
|||||||
segmentDuration,
|
segmentDuration,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const timelineStartAligned = useMemo(
|
||||||
|
() => alignStartDateToTimeline(timelineStart),
|
||||||
|
[timelineStart, alignStartDateToTimeline],
|
||||||
|
);
|
||||||
|
|
||||||
const { handleMouseDown, handleMouseUp, handleMouseMove } =
|
const { handleMouseDown, handleMouseUp, handleMouseMove } =
|
||||||
useDraggableHandler({
|
useDraggableHandler({
|
||||||
contentRef,
|
contentRef,
|
||||||
@ -71,7 +76,7 @@ export function EventReviewTimeline({
|
|||||||
handlebarTime,
|
handlebarTime,
|
||||||
setHandlebarTime,
|
setHandlebarTime,
|
||||||
timelineDuration,
|
timelineDuration,
|
||||||
timelineStart,
|
timelineStartAligned,
|
||||||
isDragging,
|
isDragging,
|
||||||
setIsDragging,
|
setIsDragging,
|
||||||
handlebarTimeRef,
|
handlebarTimeRef,
|
||||||
@ -80,10 +85,9 @@ export function EventReviewTimeline({
|
|||||||
// Generate segments for the timeline
|
// Generate segments for the timeline
|
||||||
const generateSegments = useCallback(() => {
|
const generateSegments = useCallback(() => {
|
||||||
const segmentCount = timelineDuration / segmentDuration;
|
const segmentCount = timelineDuration / segmentDuration;
|
||||||
const segmentAlignedTime = alignStartDateToTimeline(timelineStart);
|
|
||||||
|
|
||||||
return Array.from({ length: segmentCount }, (_, index) => {
|
return Array.from({ length: segmentCount }, (_, index) => {
|
||||||
const segmentTime = segmentAlignedTime - index * segmentDuration;
|
const segmentTime = timelineStartAligned - index * segmentDuration;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<EventSegment
|
<EventSegment
|
||||||
|
@ -60,6 +60,11 @@ export function MotionReviewTimeline({
|
|||||||
segmentDuration,
|
segmentDuration,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const timelineStartAligned = useMemo(
|
||||||
|
() => alignStartDateToTimeline(timelineStart),
|
||||||
|
[timelineStart, alignStartDateToTimeline],
|
||||||
|
);
|
||||||
|
|
||||||
const { handleMouseDown, handleMouseUp, handleMouseMove } =
|
const { handleMouseDown, handleMouseUp, handleMouseMove } =
|
||||||
useDraggableHandler({
|
useDraggableHandler({
|
||||||
contentRef,
|
contentRef,
|
||||||
@ -72,7 +77,7 @@ export function MotionReviewTimeline({
|
|||||||
handlebarTime,
|
handlebarTime,
|
||||||
setHandlebarTime,
|
setHandlebarTime,
|
||||||
timelineDuration,
|
timelineDuration,
|
||||||
timelineStart,
|
timelineStartAligned,
|
||||||
isDragging,
|
isDragging,
|
||||||
setIsDragging,
|
setIsDragging,
|
||||||
handlebarTimeRef,
|
handlebarTimeRef,
|
||||||
@ -81,10 +86,9 @@ export function MotionReviewTimeline({
|
|||||||
// Generate segments for the timeline
|
// Generate segments for the timeline
|
||||||
const generateSegments = useCallback(() => {
|
const generateSegments = useCallback(() => {
|
||||||
const segmentCount = timelineDuration / segmentDuration;
|
const segmentCount = timelineDuration / segmentDuration;
|
||||||
const segmentAlignedTime = alignStartDateToTimeline(timelineStart);
|
|
||||||
|
|
||||||
return Array.from({ length: segmentCount }, (_, index) => {
|
return Array.from({ length: segmentCount }, (_, index) => {
|
||||||
const segmentTime = segmentAlignedTime - index * segmentDuration;
|
const segmentTime = timelineStartAligned - index * segmentDuration;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MotionSegment
|
<MotionSegment
|
||||||
@ -106,7 +110,7 @@ export function MotionReviewTimeline({
|
|||||||
}, [
|
}, [
|
||||||
segmentDuration,
|
segmentDuration,
|
||||||
timestampSpread,
|
timestampSpread,
|
||||||
timelineStart,
|
timelineStartAligned,
|
||||||
timelineDuration,
|
timelineDuration,
|
||||||
showMinimap,
|
showMinimap,
|
||||||
minimapStartTime,
|
minimapStartTime,
|
||||||
@ -122,7 +126,7 @@ export function MotionReviewTimeline({
|
|||||||
[
|
[
|
||||||
segmentDuration,
|
segmentDuration,
|
||||||
timestampSpread,
|
timestampSpread,
|
||||||
timelineStart,
|
timelineStartAligned,
|
||||||
timelineDuration,
|
timelineDuration,
|
||||||
showMinimap,
|
showMinimap,
|
||||||
minimapStartTime,
|
minimapStartTime,
|
||||||
|
@ -14,7 +14,7 @@ type DragHandlerProps = {
|
|||||||
setHandlebarTime?: React.Dispatch<React.SetStateAction<number>>;
|
setHandlebarTime?: React.Dispatch<React.SetStateAction<number>>;
|
||||||
handlebarTimeRef: React.MutableRefObject<HTMLDivElement | null>;
|
handlebarTimeRef: React.MutableRefObject<HTMLDivElement | null>;
|
||||||
timelineDuration: number;
|
timelineDuration: number;
|
||||||
timelineStart: number;
|
timelineStartAligned: number;
|
||||||
isDragging: boolean;
|
isDragging: boolean;
|
||||||
setIsDragging: React.Dispatch<React.SetStateAction<boolean>>;
|
setIsDragging: React.Dispatch<React.SetStateAction<boolean>>;
|
||||||
};
|
};
|
||||||
@ -30,7 +30,7 @@ function useDraggableHandler({
|
|||||||
setHandlebarTime,
|
setHandlebarTime,
|
||||||
handlebarTimeRef,
|
handlebarTimeRef,
|
||||||
timelineDuration,
|
timelineDuration,
|
||||||
timelineStart,
|
timelineStartAligned,
|
||||||
isDragging,
|
isDragging,
|
||||||
setIsDragging,
|
setIsDragging,
|
||||||
}: DragHandlerProps) {
|
}: DragHandlerProps) {
|
||||||
@ -83,7 +83,7 @@ function useDraggableHandler({
|
|||||||
getClientYPosition(e);
|
getClientYPosition(e);
|
||||||
setIsDragging(true);
|
setIsDragging(true);
|
||||||
|
|
||||||
if (scrollTimeRef.current && clientYPosition) {
|
if (scrollTimeRef.current && clientYPosition && isDesktop) {
|
||||||
const handlebarRect = scrollTimeRef.current.getBoundingClientRect();
|
const handlebarRect = scrollTimeRef.current.getBoundingClientRect();
|
||||||
setInitialClickAdjustment(clientYPosition - handlebarRect.top);
|
setInitialClickAdjustment(clientYPosition - handlebarRect.top);
|
||||||
}
|
}
|
||||||
@ -207,7 +207,7 @@ function useDraggableHandler({
|
|||||||
|
|
||||||
const segmentIndex = Math.floor(newHandlePosition / segmentHeight);
|
const segmentIndex = Math.floor(newHandlePosition / segmentHeight);
|
||||||
const segmentStartTime = alignStartDateToTimeline(
|
const segmentStartTime = alignStartDateToTimeline(
|
||||||
timelineStart - segmentIndex * segmentDuration,
|
timelineStartAligned - segmentIndex * segmentDuration,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (draggingAtTopEdge || draggingAtBottomEdge) {
|
if (draggingAtTopEdge || draggingAtBottomEdge) {
|
||||||
@ -233,8 +233,9 @@ function useDraggableHandler({
|
|||||||
|
|
||||||
if (setHandlebarTime) {
|
if (setHandlebarTime) {
|
||||||
setHandlebarTime(
|
setHandlebarTime(
|
||||||
timelineStart -
|
timelineStartAligned -
|
||||||
(newHandlePosition / segmentHeight) * segmentDuration,
|
((newHandlePosition - segmentHeight / 2 - 2) / segmentHeight) *
|
||||||
|
segmentDuration,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -265,7 +266,7 @@ function useDraggableHandler({
|
|||||||
clientYPosition,
|
clientYPosition,
|
||||||
isDragging,
|
isDragging,
|
||||||
segmentDuration,
|
segmentDuration,
|
||||||
timelineStart,
|
timelineStartAligned,
|
||||||
timelineDuration,
|
timelineDuration,
|
||||||
timelineRef,
|
timelineRef,
|
||||||
draggingAtTopEdge,
|
draggingAtTopEdge,
|
||||||
@ -290,20 +291,17 @@ function useDraggableHandler({
|
|||||||
const parentScrollTop = getCumulativeScrollTop(timelineRef.current);
|
const parentScrollTop = getCumulativeScrollTop(timelineRef.current);
|
||||||
|
|
||||||
const newHandlePosition =
|
const newHandlePosition =
|
||||||
((timelineStart - handlebarTime) / segmentDuration) * segmentHeight +
|
((timelineStartAligned - handlebarTime) / segmentDuration) *
|
||||||
|
segmentHeight +
|
||||||
parentScrollTop -
|
parentScrollTop -
|
||||||
scrolled;
|
scrolled -
|
||||||
|
2; // height of handlebar horizontal line
|
||||||
|
|
||||||
updateHandlebarPosition(
|
updateHandlebarPosition(newHandlePosition, handlebarTime, true, true);
|
||||||
newHandlePosition - segmentHeight,
|
|
||||||
handlebarTime,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
// we know that these deps are correct
|
// we know that these deps are correct
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [handlebarTime, showHandlebar, scrollTimeRef, timelineStart]);
|
}, [handlebarTime, showHandlebar, scrollTimeRef, timelineStartAligned]);
|
||||||
|
|
||||||
return { handleMouseDown, handleMouseUp, handleMouseMove };
|
return { handleMouseDown, handleMouseUp, handleMouseMove };
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user