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

Expose setter for review timeline handlebar #9978

Merged
merged 2 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions web/src/components/timeline/EventReviewTimeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export type EventReviewTimelineProps = {
timelineDuration?: number;
showHandlebar?: boolean;
handlebarTime?: number;
setHandlebarTime?: React.Dispatch<React.SetStateAction<number>>;
showMinimap?: boolean;
minimapStartTime?: number;
minimapEndTime?: number;
Expand All @@ -33,6 +34,7 @@ export function EventReviewTimeline({
timelineDuration = 24 * 60 * 60,
showHandlebar = false,
handlebarTime,
setHandlebarTime,
showMinimap = false,
minimapStartTime,
minimapEndTime,
Expand Down Expand Up @@ -62,6 +64,7 @@ export function EventReviewTimeline({
isDragging,
setIsDragging,
currentTimeRef,
setHandlebarTime,
});

function handleResize() {
Expand Down
5 changes: 5 additions & 0 deletions web/src/hooks/use-handle-dragging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ interface DragHandlerProps {
isDragging: boolean;
setIsDragging: React.Dispatch<React.SetStateAction<boolean>>;
currentTimeRef: React.MutableRefObject<HTMLDivElement | null>;
setHandlebarTime?: React.Dispatch<React.SetStateAction<number>>;
}

// TODO: handle mobile touch events
Expand All @@ -27,6 +28,7 @@ function useDraggableHandler({
isDragging,
setIsDragging,
currentTimeRef,
setHandlebarTime,
}: DragHandlerProps) {
const handleMouseDown = useCallback(
(e: React.MouseEvent<HTMLDivElement>) => {
Expand Down Expand Up @@ -108,6 +110,9 @@ function useDraggableHandler({
});
}
});
if (setHandlebarTime) {
setHandlebarTime(segmentStartTime);
}
}
}
},
Expand Down
10 changes: 9 additions & 1 deletion web/src/pages/UIPlayground.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ function UIPlayground() {
const [timeline, setTimeline] = useState<string | undefined>(undefined);
const contentRef = useRef<HTMLDivElement>(null);
const [mockEvents, setMockEvents] = useState<ReviewSegment[]>([]);
const [handlebarTime, setHandlebarTime] = useState(
Math.floor(Date.now() / 1000) - 27 * 60
);

const onSelect = useCallback(({ items }: { items: string[] }) => {
setTimeline(items[0]);
Expand Down Expand Up @@ -158,6 +161,10 @@ function UIPlayground() {
<div className="flex">
<div className="flex-grow">
<div ref={contentRef}>
<Heading as="h4" className="my-5">
Handlebar time
</Heading>
<p className="text-small">{handlebarTime}</p>
<Heading as="h4" className="my-5">
Color scheme
</Heading>
Expand Down Expand Up @@ -190,7 +197,8 @@ function UIPlayground() {
timelineStart={Math.floor(Date.now() / 1000)} // start of the timeline - all times are numeric, not Date objects
timelineDuration={24 * 60 * 60} // in minutes, defaults to 24 hours
showHandlebar // show / hide the handlebar
handlebarTime={Math.floor(Date.now() / 1000) - 27 * 60} // set the time of the handlebar
handlebarTime={handlebarTime} // set the time of the handlebar
setHandlebarTime={setHandlebarTime} // expose handler to set the handlebar time
showMinimap // show / hide the minimap
minimapStartTime={Math.floor(Date.now() / 1000) - 35 * 60} // start time of the minimap - the earlier time (eg 1:00pm)
minimapEndTime={Math.floor(Date.now() / 1000) - 21 * 60} // end of the minimap - the later time (eg 3:00pm)
Expand Down
Loading