|
9 | 9 | * summary as a comment or the reverse. |
10 | 10 | */ |
11 | 11 | import type { EnvironmentId, PullRequestDetailView, PullRequestRef } from "@t3tools/contracts"; |
12 | | -import { MessageSquareIcon, XIcon } from "lucide-react"; |
| 12 | +import { MessageSquareIcon, Trash2Icon, XIcon } from "lucide-react"; |
13 | 13 | import { useRef, useState } from "react"; |
14 | 14 |
|
15 | 15 | import { Button } from "../ui/button"; |
@@ -48,6 +48,7 @@ export function PullRequestComposer({ |
48 | 48 | const commentRef = useRef<HTMLTextAreaElement>(null); |
49 | 49 | const reviewRef = useRef<HTMLTextAreaElement>(null); |
50 | 50 | const pendingComments = usePendingReviewComments(reference); |
| 51 | + const clearComments = usePullRequestReviewStore((store) => store.clear); |
51 | 52 | // A summary typed but not sent is review work too, and it outlives the popover. Selected as a |
52 | 53 | // boolean rather than the text, so typing one does not re-render the composer per keystroke. |
53 | 54 | const reviewKey = pullRequestReviewKey(reference); |
@@ -104,6 +105,7 @@ export function PullRequestComposer({ |
104 | 105 | ) : null} |
105 | 106 | </PopoverTrigger> |
106 | 107 | <PopoverPopup |
| 108 | + keepMounted |
107 | 109 | side="top" |
108 | 110 | align="end" |
109 | 111 | sideOffset={8} |
@@ -132,16 +134,28 @@ export function PullRequestComposer({ |
132 | 134 | {mode === "review" ? "Review pull request" : "Comment on pull request"} |
133 | 135 | </PopoverTitle> |
134 | 136 | )} |
135 | | - <PopoverClose |
136 | | - render={<Button size="icon-xs" variant="ghost" />} |
137 | | - aria-label="Close composer" |
138 | | - > |
139 | | - <XIcon className="size-3.5" /> |
140 | | - </PopoverClose> |
| 137 | + <div className="flex items-center gap-1"> |
| 138 | + {mode === "review" && pendingComments.length > 0 ? ( |
| 139 | + <Button |
| 140 | + size="icon-xs" |
| 141 | + variant="ghost" |
| 142 | + aria-label="Discard pending line comments" |
| 143 | + title="Discard pending line comments" |
| 144 | + onClick={() => clearComments(reviewKey)} |
| 145 | + > |
| 146 | + <Trash2Icon className="size-3.5" /> |
| 147 | + </Button> |
| 148 | + ) : null} |
| 149 | + <PopoverClose |
| 150 | + render={<Button size="icon-xs" variant="ghost" />} |
| 151 | + aria-label="Close composer" |
| 152 | + > |
| 153 | + <XIcon className="size-3.5" /> |
| 154 | + </PopoverClose> |
| 155 | + </div> |
141 | 156 | </div> |
142 | | - {/* Both panes stay mounted and the inactive one is only hidden. Unmounting would drop |
143 | | - the comment draft on every toggle, and reset the submit guard of a form whose request |
144 | | - is still in flight — enough to send the same review twice. */} |
| 157 | + {/* Keep both forms mounted across toggles and dismissal so drafts and in-flight |
| 158 | + submit guards survive closing and reopening the composer. */} |
145 | 159 | {verdicts.length > 0 ? ( |
146 | 160 | <div hidden={mode !== "review"}> |
147 | 161 | <PullRequestReviewForm |
|
0 commit comments