Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timeline tweaks #10816

Merged
merged 3 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions web/src/components/filter/ReviewFilterGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Button } from "../ui/button";
import { Popover, PopoverContent, PopoverTrigger } from "../ui/popover";
import useSWR from "swr";
import { CameraGroupConfig, FrigateConfig } from "@/types/frigateConfig";
import { useCallback, useMemo, useState } from "react";
import { useCallback, useEffect, useMemo, useState } from "react";
import {
DropdownMenu,
DropdownMenuContent,
Expand Down Expand Up @@ -631,16 +631,21 @@ function ShowMotionOnlyButton({
motionOnly,
setMotionOnly,
}: ShowMotionOnlyButtonProps) {
const [motionOnlyButton, setMotionOnlyButton] = useState(motionOnly);

useEffect(
() => setMotionOnly(motionOnlyButton),
[motionOnlyButton, setMotionOnly],
);

return (
<>
<div className="hidden md:inline-flex items-center justify-center whitespace-nowrap text-sm bg-secondary hover:bg-secondary/80 text-secondary-foreground h-9 rounded-md px-3 mx-1 cursor-pointer">
<Switch
className="ml-1"
id="collapse-motion"
checked={motionOnly}
onCheckedChange={() => {
setMotionOnly(!motionOnly);
}}
checked={motionOnlyButton}
onCheckedChange={setMotionOnlyButton}
/>
<Label
className="mx-2 text-secondary-foreground cursor-pointer"
Expand Down
6 changes: 5 additions & 1 deletion web/src/components/timeline/ReviewTimeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export function ReviewTimeline({
const [isDraggingExportEnd, setIsDraggingExportEnd] = useState(false);
const [exportStartPosition, setExportStartPosition] = useState(0);
const [exportEndPosition, setExportEndPosition] = useState(0);
const segmentsRef = useRef<HTMLDivElement>(null);
const handlebarRef = useRef<HTMLDivElement>(null);
const handlebarTimeRef = useRef<HTMLDivElement>(null);
const exportStartRef = useRef<HTMLDivElement>(null);
Expand Down Expand Up @@ -100,6 +101,7 @@ export function ReviewTimeline({
} = useDraggableElement({
contentRef,
timelineRef,
segmentsRef,
draggableElementRef: handlebarRef,
segmentDuration,
showDraggableElement: showHandlebar,
Expand All @@ -123,6 +125,7 @@ export function ReviewTimeline({
} = useDraggableElement({
contentRef,
timelineRef,
segmentsRef,
draggableElementRef: exportStartRef,
segmentDuration,
showDraggableElement: showExportHandles,
Expand All @@ -147,6 +150,7 @@ export function ReviewTimeline({
} = useDraggableElement({
contentRef,
timelineRef,
segmentsRef,
draggableElementRef: exportEndRef,
segmentDuration,
showDraggableElement: showExportHandles,
Expand Down Expand Up @@ -319,7 +323,7 @@ export function ReviewTimeline({
: "cursor-auto"
}`}
>
<div className="flex flex-col relative">
<div ref={segmentsRef} className="flex flex-col relative">
<div className="absolute top-0 inset-x-0 z-20 w-full h-[30px] bg-gradient-to-b from-secondary to-transparent pointer-events-none"></div>
<div className="absolute bottom-0 inset-x-0 z-20 w-full h-[30px] bg-gradient-to-t from-secondary to-transparent pointer-events-none"></div>
{children}
Expand Down
21 changes: 17 additions & 4 deletions web/src/hooks/use-draggable-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useTimelineUtils } from "./use-timeline-utils";
type DraggableElementProps = {
contentRef: React.RefObject<HTMLElement>;
timelineRef: React.RefObject<HTMLDivElement>;
segmentsRef: React.RefObject<HTMLDivElement>;
draggableElementRef: React.RefObject<HTMLDivElement>;
segmentDuration: number;
showDraggableElement: boolean;
Expand All @@ -29,6 +30,7 @@ type DraggableElementProps = {
function useDraggableElement({
contentRef,
timelineRef,
segmentsRef,
draggableElementRef,
segmentDuration,
showDraggableElement,
Expand Down Expand Up @@ -430,12 +432,18 @@ function useDraggableElement({
useEffect(() => {
if (
timelineRef.current &&
segmentsRef.current &&
draggableElementTime &&
timelineCollapsed &&
timelineSegments &&
segments
) {
setFullTimelineHeight(timelineRef.current.scrollHeight);
setFullTimelineHeight(
Math.min(
timelineRef.current.scrollHeight,
segmentsRef.current.scrollHeight,
),
);
const alignedSegmentTime = alignStartDateToTimeline(draggableElementTime);

let segmentElement = timelineRef.current.querySelector(
Expand Down Expand Up @@ -486,11 +494,16 @@ function useDraggableElement({
}, [timelineCollapsed, segments]);

useEffect(() => {
if (timelineRef.current && segments) {
if (timelineRef.current && segments && segmentsRef.current) {
setScrollEdgeSize(timelineRef.current.clientHeight * 0.03);
setFullTimelineHeight(timelineRef.current.scrollHeight);
setFullTimelineHeight(
Math.min(
timelineRef.current.scrollHeight,
segmentsRef.current.scrollHeight,
),
);
}
}, [timelineRef, segments]);
}, [timelineRef, segmentsRef, segments]);

return { handleMouseDown, handleMouseUp, handleMouseMove };
}
Expand Down
2 changes: 1 addition & 1 deletion web/src/views/events/EventView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,7 @@ function MotionReview({
}
const detectionType = getDetectionType(camera.name);
return (
<div className={`relative ${spans}`}>
<div key={camera.name} className={`relative ${spans}`}>
<PreviewPlayer
key={camera.name}
className={`rounded-2xl ${spans} ${grow}`}
Expand Down
Loading