import { useState } from "react"; import { deleteReviewComment, editReviewComment, replyReviewComment, resolveReviewThread } from "~/fns/reviews"; import { useAction } from "~/hooks/use-action"; import { ReactionBar } from "./ReactionBar"; import { Avatar } from "~/ui/Avatar"; import { Badge } from "~/ui/Badge"; import { Markdown } from "~/ui/Markdown"; import { RelativeTime } from "~/ui/RelativeTime"; import { Button } from "~/ui/Button"; import { inputClass } from "~/ui/Field"; import type { getPullFiles } from "~/fns/pulls"; import { cn } from "~/utils/cn"; import { ReportLink } from "./ReportLink"; export type ReviewComment = Awaited>["comments"][number]; type Props = { owner: string; repo: string; number: number; root: ReviewComment; replies: ReviewComment[]; canReply: boolean; suggestion?: SuggestionControls; }; export type SuggestionControls = { inBatch: boolean; pending: boolean; onCommit: () => void; onToggleBatch: () => void; }; function rangeLabel(comment: ReviewComment): string | null { if (!comment.startLine) return null; const prefix = (side: string | null) => (side === "LEFT" ? "L" : "R"); return `Lines ${prefix(comment.startSide)}${comment.startLine}–${prefix(comment.side)}${comment.line}`; } function SuggestionBar({ comment, controls }: { comment: ReviewComment; controls?: SuggestionControls }) { if (!comment.hasSuggestion) return null; if (comment.suggestionApplied) return Suggestion applied; if (!controls) return Suggested change; return ( ); } function CommentBody({ owner, repo, number, comment, }: { owner: string; repo: string; number: number; comment: ReviewComment; }) { const [editing, setEditing] = useState(false); const [draft, setDraft] = useState(comment.body); const edit = useAction(editReviewComment); const remove = useAction(deleteReviewComment); if (!editing) { return ( <> {comment.canEdit && (
)} ); } return (
{ event.preventDefault(); if (!draft.trim()) return; const ok = await edit.run({ data: { owner, repo, number, commentId: comment.id, body: draft } }); if (ok) setEditing(false); }} >