import { useEffect, useId, useRef, useState, type ComponentProps } from "react"; import { cn } from "~/lib/utils"; import { Button } from "../ui/button"; import { PullRequestMarkdown } from "./PullRequestMarkdown"; /** Keep the complete markdown intact while limiting long reports to a readable preview. */ export function PullRequestCommentBody({ className, ...props }: ComponentProps) { const [expanded, setExpanded] = useState(false); const [overflowing, setOverflowing] = useState(false); const content = useRef(null); const id = useId(); useEffect(() => { const element = content.current; if (!element) return; const measure = () => setOverflowing(element.getBoundingClientRect().height > 240); measure(); const observer = new ResizeObserver(measure); observer.observe(element); return () => observer.disconnect(); }, []); return (
setExpanded(true)} >
{overflowing && !expanded ? (
) : null}
{overflowing ? ( ) : null}
); }