"use client"; import { useRouter } from "next/navigation"; import { Fragment, useState, useTransition, type ReactNode } from "react"; import { Textarea } from "@unlocalhosted/metalui"; import { lineCommentAction } from "@/app/actions/pulls"; import { FileIcon, PlusIcon } from "@/components/icons"; import { Alert, Box, Button, ButtonLink, Label } from "@/components/ui"; import type { DiffLine, FileDiff } from "@/lib/git"; import { lineKey } from "./line-key"; const MAX_RENDERED_LINES = 3000; const lineStyles = { add: { row: "bg-[var(--diff-add)]", num: "bg-[var(--diff-add-num)]", sign: "+" }, del: { row: "bg-[var(--diff-del)]", num: "bg-[var(--diff-del-num)]", sign: "-" }, ctx: { row: "", num: "", sign: " " }, }; function keyOf(file: FileDiff, line: DiffLine) { if (line.kind === "del") return { side: "old" as const, path: file.oldPath, line: line.oldNo! }; return { side: "new" as const, path: file.newPath, line: line.newNo! }; } function NewComment({ owner, name, number, at, onDone }: { owner: string; name: string; number: number; at: ReturnType; onDone: () => void }) { const router = useRouter(); const [body, setBody] = useState(""); const [error, setError] = useState(null); const [pending, startTransition] = useTransition(); const submit = () => startTransition(async () => { const result = await lineCommentAction(owner, name, number, { ...at, body }); if (result.error) return setError(result.error); onDone(); router.refresh(); }); return (