expose setter for handlebar

This commit is contained in:
Josh Hawkins 2024-02-22 07:56:43 -06:00
parent 940be5dc6f
commit a632c2de5e
3 changed files with 17 additions and 1 deletions

View File

@ -18,6 +18,7 @@ export type EventReviewTimelineProps = {
timelineDuration?: number; timelineDuration?: number;
showHandlebar?: boolean; showHandlebar?: boolean;
handlebarTime?: number; handlebarTime?: number;
setHandlebarTime?: React.Dispatch<React.SetStateAction<number>>;
showMinimap?: boolean; showMinimap?: boolean;
minimapStartTime?: number; minimapStartTime?: number;
minimapEndTime?: number; minimapEndTime?: number;
@ -33,6 +34,7 @@ export function EventReviewTimeline({
timelineDuration = 24 * 60 * 60, timelineDuration = 24 * 60 * 60,
showHandlebar = false, showHandlebar = false,
handlebarTime, handlebarTime,
setHandlebarTime,
showMinimap = false, showMinimap = false,
minimapStartTime, minimapStartTime,
minimapEndTime, minimapEndTime,
@ -62,6 +64,7 @@ export function EventReviewTimeline({
isDragging, isDragging,
setIsDragging, setIsDragging,
currentTimeRef, currentTimeRef,
setHandlebarTime,
}); });
function handleResize() { function handleResize() {

View File

@ -12,6 +12,7 @@ interface DragHandlerProps {
isDragging: boolean; isDragging: boolean;
setIsDragging: React.Dispatch<React.SetStateAction<boolean>>; setIsDragging: React.Dispatch<React.SetStateAction<boolean>>;
currentTimeRef: React.MutableRefObject<HTMLDivElement | null>; currentTimeRef: React.MutableRefObject<HTMLDivElement | null>;
setHandlebarTime?: React.Dispatch<React.SetStateAction<number>>;
} }
// TODO: handle mobile touch events // TODO: handle mobile touch events
@ -27,6 +28,7 @@ function useDraggableHandler({
isDragging, isDragging,
setIsDragging, setIsDragging,
currentTimeRef, currentTimeRef,
setHandlebarTime,
}: DragHandlerProps) { }: DragHandlerProps) {
const handleMouseDown = useCallback( const handleMouseDown = useCallback(
(e: React.MouseEvent<HTMLDivElement>) => { (e: React.MouseEvent<HTMLDivElement>) => {
@ -108,6 +110,9 @@ function useDraggableHandler({
}); });
} }
}); });
if (setHandlebarTime) {
setHandlebarTime(segmentStartTime);
}
} }
} }
}, },

View File

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