The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import type { |
| 2 | EnvironmentId, |
| 3 | PullRequestDetailView, |
| 4 | PullRequestRef, |
| 5 | PullRequestConversationThread, |
| 6 | } from "@t3tools/contracts"; |
| 7 | import { canResolvePullRequestThread } from "@t3tools/client-runtime/pull-request-editing"; |
| 8 | import { msg, useGT } from "gt-react"; |
| 9 | import { useState } from "react"; |
| 10 | |
| 11 | import { m } from "~/i18n/messages"; |
| 12 | |
| 13 | import { pullRequestEnvironment } from "~/state/pullRequests"; |
| 14 | import { useAtomCommand } from "~/state/use-atom-command"; |
| 15 | |
| 16 | import { Button } from "../ui/button"; |
| 17 | import { toastManager } from "../ui/toast"; |
| 18 | |
| 19 | /** |
| 20 | * Resolves or unresolves a thread from the conversation, so threads without a diff line (such as |
| 21 | * GitLab overview threads) can be resolved too. Callers put it on the thread's first comment only. |
| 22 | */ |
| 23 | export function PullRequestResolveThreadButton({ |
| 24 | environmentId, |
| 25 | reference, |
| 26 | detail, |
| 27 | thread, |
| 28 | onRefresh, |
| 29 | }: { |
| 30 | environmentId: EnvironmentId; |
| 31 | reference: PullRequestRef; |
| 32 | detail: PullRequestDetailView; |
| 33 | thread: Pick<PullRequestConversationThread, "id" | "isResolved" | "canResolve">; |
| 34 | onRefresh: () => void; |
| 35 | }) { |
| 36 | const gt = useGT(); |
| 37 | const [pending, setPending] = useState(false); |
| 38 | const setThreadResolution = useAtomCommand(pullRequestEnvironment.setThreadResolution, { |
| 39 | reportFailure: false, |
| 40 | }); |
| 41 | if (!detail.capabilities.review.resolve || !canResolvePullRequestThread(detail, thread)) { |
| 42 | return null; |
| 43 | } |
| 44 | |
| 45 | const toggle = async () => { |
| 46 | setPending(true); |
| 47 | const result = await setThreadResolution({ |
| 48 | environmentId, |
| 49 | input: { ...reference, threadId: thread.id, resolved: !thread.isResolved }, |
| 50 | }); |
| 51 | setPending(false); |
| 52 | if (result._tag === "Failure") { |
| 53 | toastManager.add({ type: "error", title: m(msg("The conversation could not be updated")) }); |
| 54 | return; |
| 55 | } |
| 56 | onRefresh(); |
| 57 | }; |
| 58 | |
| 59 | return ( |
| 60 | <Button |
| 61 | size="xs" |
| 62 | variant="ghost" |
| 63 | className="shrink-0" |
| 64 | disabled={pending} |
| 65 | onClick={() => void toggle()} |
| 66 | > |
| 67 | {thread.isResolved ? gt("Unresolve") : gt("Resolve")} |
| 68 | </Button> |
| 69 | ); |
| 70 | } |