2024-03-04 19:42:51 +03:00
|
|
|
import { ReactNode, RefObject } from "react";
|
2024-03-17 16:28:50 +03:00
|
|
|
import { isIOS, isMobile } from "react-device-detect";
|
2024-03-04 19:42:51 +03:00
|
|
|
|
|
|
|
|
export type ReviewTimelineProps = {
|
|
|
|
|
timelineRef: RefObject<HTMLDivElement>;
|
2024-03-10 16:23:36 +03:00
|
|
|
handlebarRef: RefObject<HTMLDivElement>;
|
2024-03-04 19:42:51 +03:00
|
|
|
handlebarTimeRef: RefObject<HTMLDivElement>;
|
|
|
|
|
handleMouseMove: (
|
|
|
|
|
e:
|
|
|
|
|
| React.MouseEvent<HTMLDivElement, MouseEvent>
|
|
|
|
|
| React.TouchEvent<HTMLDivElement>,
|
|
|
|
|
) => void;
|
|
|
|
|
handleMouseUp: (
|
|
|
|
|
e:
|
|
|
|
|
| React.MouseEvent<HTMLDivElement, MouseEvent>
|
|
|
|
|
| React.TouchEvent<HTMLDivElement>,
|
|
|
|
|
) => void;
|
|
|
|
|
handleMouseDown: (
|
|
|
|
|
e:
|
|
|
|
|
| React.MouseEvent<HTMLDivElement, MouseEvent>
|
|
|
|
|
| React.TouchEvent<HTMLDivElement>,
|
|
|
|
|
) => void;
|
|
|
|
|
segmentDuration: number;
|
|
|
|
|
showHandlebar: boolean;
|
|
|
|
|
isDragging: boolean;
|
|
|
|
|
children: ReactNode;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export function ReviewTimeline({
|
|
|
|
|
timelineRef,
|
2024-03-10 16:23:36 +03:00
|
|
|
handlebarRef,
|
2024-03-04 19:42:51 +03:00
|
|
|
handlebarTimeRef,
|
|
|
|
|
handleMouseMove,
|
|
|
|
|
handleMouseUp,
|
|
|
|
|
handleMouseDown,
|
|
|
|
|
segmentDuration,
|
|
|
|
|
showHandlebar = false,
|
|
|
|
|
isDragging,
|
|
|
|
|
children,
|
|
|
|
|
}: ReviewTimelineProps) {
|
|
|
|
|
return (
|
|
|
|
|
<div
|
|
|
|
|
ref={timelineRef}
|
|
|
|
|
onMouseMove={handleMouseMove}
|
|
|
|
|
onTouchMove={handleMouseMove}
|
|
|
|
|
onMouseUp={handleMouseUp}
|
|
|
|
|
onTouchEnd={handleMouseUp}
|
2024-03-07 00:35:10 +03:00
|
|
|
className={`relative h-full overflow-y-auto no-scrollbar bg-secondary ${
|
2024-03-04 19:42:51 +03:00
|
|
|
isDragging && showHandlebar ? "cursor-grabbing" : "cursor-auto"
|
|
|
|
|
}`}
|
|
|
|
|
>
|
2024-03-12 18:23:54 +03:00
|
|
|
<div 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}
|
|
|
|
|
</div>
|
2024-03-04 19:42:51 +03:00
|
|
|
{showHandlebar && (
|
2024-03-10 16:23:36 +03:00
|
|
|
<div
|
2024-03-17 16:28:50 +03:00
|
|
|
className={`absolute left-0 top-0 ${isDragging && isIOS ? "" : "z-20"} w-full`}
|
2024-03-10 16:23:36 +03:00
|
|
|
role="scrollbar"
|
|
|
|
|
ref={handlebarRef}
|
|
|
|
|
>
|
2024-03-04 19:42:51 +03:00
|
|
|
<div
|
|
|
|
|
className="flex items-center justify-center touch-none select-none"
|
|
|
|
|
onMouseDown={handleMouseDown}
|
|
|
|
|
onTouchStart={handleMouseDown}
|
|
|
|
|
>
|
|
|
|
|
<div
|
|
|
|
|
className={`relative w-full ${
|
|
|
|
|
isDragging ? "cursor-grabbing" : "cursor-grab"
|
|
|
|
|
}`}
|
|
|
|
|
>
|
|
|
|
|
<div
|
|
|
|
|
className={`bg-destructive rounded-full mx-auto ${
|
2024-03-07 00:35:10 +03:00
|
|
|
segmentDuration < 60 ? "w-12 md:w-20" : "w-12 md:w-16"
|
2024-03-17 16:28:50 +03:00
|
|
|
} h-5 ${isDragging && isMobile ? "fixed top-[18px] left-1/2 transform -translate-x-1/2 z-20 w-[30%] h-[30px] bg-destructive/80" : "static"} flex items-center justify-center`}
|
2024-03-04 19:42:51 +03:00
|
|
|
>
|
|
|
|
|
<div
|
|
|
|
|
ref={handlebarTimeRef}
|
2024-03-17 16:28:50 +03:00
|
|
|
className={`text-white ${isDragging && isMobile ? "text-lg" : "text-[8px] md:text-xs"} z-10`}
|
2024-03-04 19:42:51 +03:00
|
|
|
></div>
|
|
|
|
|
</div>
|
2024-03-17 16:28:50 +03:00
|
|
|
<div
|
|
|
|
|
className={`absolute h-1 w-full bg-destructive ${isDragging && isMobile ? "top-1" : "top-1/2 transform -translate-y-1/2"}`}
|
|
|
|
|
></div>
|
2024-03-04 19:42:51 +03:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default ReviewTimeline;
|