import { useState } from "react"; import { addComment, setIssueOpenState } from "~/fns/issues"; import { useAction } from "~/hooks/use-action"; import { MarkdownEditor } from "./MarkdownEditor"; import { Button } from "~/ui/Button"; import { ErrorBanner } from "~/ui/Callout"; import { VerifyEmailHint } from "./VerifyEmailHint"; import { useEmailUnverified } from "~/hooks/use-viewer"; type Props = { owner: string; repo: string; number: number; state: "open" | "closed"; canToggle: boolean; merged?: boolean; }; export function CommentComposer({ owner, repo, number, state, canToggle, merged = false }: Props) { const [body, setBody] = useState(""); const comment = useAction(addComment); const toggle = useAction(setIssueOpenState); const unverified = useEmailUnverified(); if (unverified) return ; async function submit() { if (await comment.run({ data: { owner, repo, number, body, closeAfter: false } })) setBody(""); } return (
{canToggle && !merged && ( )}
); }