import { Play } from "lucide-react"; import { useRef, useState } from "react"; import type { Post } from "../../../types/post"; import { useVideoPlayer } from "../overlays/VideoPlayer"; import { autolink } from "../utils/autolink"; import { formatBytes } from "../utils/formatBytes"; function formatDuration(sec: number | undefined): string { if (!sec || sec <= 0) return ""; const m = Math.floor(sec / 60); const s = Math.floor(sec % 60); return `${m}:${s.toString().padStart(2, "0")}`; } export function VideoBubble({ post }: { post: Post }) { const { openVideo } = useVideoPlayer(); const att = post.attachments[0]; const [playing, setPlaying] = useState(false); const videoRef = useRef(null); if (!att) return null; const ratio = att.width && att.height ? `${att.width} / ${att.height}` : "16 / 9"; return (
{ if (playing) { const v = videoRef.current; openVideo(att, v?.currentTime ?? 0); } }} > {playing ? (
{post.text ? (
{autolink(post.text)}
) : null}
); }