11import type {
22 EnvironmentId ,
3+ PullRequestActor ,
34 PullRequestDiffSide ,
45 PullRequestRef ,
56 PullRequestReviewPosition ,
@@ -15,22 +16,23 @@ import {
1516 CircleCheckIcon ,
1617 CircleIcon ,
1718} from "lucide-react" ;
18- import { useRef , useState } from "react" ;
19+ import { type ReactNode , useRef , useState } from "react" ;
1920import { settlePromise , squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime" ;
2021
2122import { RelativeTime } from "~/components/RelativeTime" ;
2223import { cn } from "~/lib/utils" ;
2324import { SpeechTextField , TextFieldSpeechControls } from "~/speech/useTextFieldSpeech" ;
2425
2526import { Button } from "../ui/button" ;
27+ import { Tooltip , TooltipPopup , TooltipTrigger } from "../ui/tooltip" ;
2628import { PullRequestEditButton } from "./PullRequestEditButton" ;
2729import { isCommentSubmitShortcut } from "../diffs/commentSubmitShortcut" ;
2830import {
2931 editPullRequestThreadComment ,
3032 mergePullRequestThreadComments ,
3133 visibleBody ,
3234} from "./pullRequestDetail.logic" ;
33- import { PullRequestActorLabel } from "./pullRequestPresentation" ;
35+ import { PullRequestActorAvatar , PullRequestActorLabel } from "./pullRequestPresentation" ;
3436import { PullRequestMarkdown } from "./PullRequestMarkdown" ;
3537import { PullRequestMarkdownEditor } from "./PullRequestMarkdownEditor" ;
3638import { PullRequestReactionBar } from "./PullRequestReactions" ;
@@ -114,6 +116,86 @@ export function PendingReviewCommentCard({
114116 ) ;
115117}
116118
119+ const MARKER_AVATAR_LIMIT = 3 ;
120+
121+ function ResolvedThreadsMarker ( {
122+ threads,
123+ onOpen,
124+ } : {
125+ threads : ReadonlyArray < PullRequestReviewThread > ;
126+ onOpen : ( ) => void ;
127+ } ) {
128+ const authors = new Map < string , PullRequestActor | null > ( ) ;
129+ for ( const thread of threads ) {
130+ for ( const comment of thread . comments ) {
131+ authors . set ( comment . author ?. login ?? "ghost" , comment . author ) ;
132+ }
133+ }
134+ if ( authors . size === 0 ) authors . set ( "ghost" , null ) ;
135+ const label =
136+ threads . length === 1
137+ ? "Show resolved conversation"
138+ : `Show ${ threads . length } resolved conversations` ;
139+ return (
140+ < Tooltip >
141+ < TooltipTrigger
142+ render = {
143+ < button
144+ type = "button"
145+ data-resolved-threads
146+ aria-label = { label }
147+ aria-expanded = { false }
148+ // Sits on the commented line, which is the row above this zero-height annotation.
149+ className = "absolute right-3 bottom-full flex h-[var(--diffs-line-height,20px)] cursor-pointer items-center -space-x-1 rounded-full outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset"
150+ contentEditable = { false }
151+ onPointerDown = { ( event ) => event . stopPropagation ( ) }
152+ onClick = { onOpen }
153+ />
154+ }
155+ >
156+ { [ ...authors ] . slice ( 0 , MARKER_AVATAR_LIMIT ) . map ( ( [ login , author ] ) => (
157+ < PullRequestActorAvatar key = { login } actor = { author } className = "ring-1 ring-background" />
158+ ) ) }
159+ </ TooltipTrigger >
160+ < TooltipPopup side = "left" > { label } </ TooltipPopup >
161+ </ Tooltip >
162+ ) ;
163+ }
164+
165+ /** The conversations on one diff line. Resolved ones show as avatars until opened. */
166+ export function InlineReviewThreads ( {
167+ threads,
168+ renderThread,
169+ } : {
170+ threads : ReadonlyArray < PullRequestReviewThread > ;
171+ renderThread : ( thread : PullRequestReviewThread , onCollapse : ( ) => void ) => ReactNode ;
172+ } ) {
173+ const [ opened , setOpened ] = useState < ReadonlySet < string > > ( ( ) => new Set ( ) ) ;
174+ // A conversation resolved while open stays open until the reader collapses it.
175+ const seenOpen = threads . filter ( ( thread ) => ! thread . isResolved && ! opened . has ( thread . id ) ) ;
176+ if ( seenOpen . length > 0 ) {
177+ setOpened ( new Set ( [ ...opened , ...seenOpen . map ( ( thread ) => thread . id ) ] ) ) ;
178+ }
179+ const folded = threads . filter ( ( thread ) => thread . isResolved && ! opened . has ( thread . id ) ) ;
180+ return (
181+ < >
182+ { folded . length > 0 ? (
183+ < ResolvedThreadsMarker
184+ threads = { folded }
185+ onOpen = { ( ) => setOpened ( new Set ( [ ...opened , ...folded . map ( ( thread ) => thread . id ) ] ) ) }
186+ />
187+ ) : null }
188+ { threads . map ( ( thread ) =>
189+ folded . includes ( thread )
190+ ? null
191+ : renderThread ( thread , ( ) =>
192+ setOpened ( ( current ) => new Set ( [ ...current ] . filter ( ( id ) => id !== thread . id ) ) ) ,
193+ ) ,
194+ ) }
195+ </ >
196+ ) ;
197+ }
198+
117199export function ReviewThreadCard ( {
118200 thread,
119201 workspaceRoot,
@@ -134,6 +216,7 @@ export function ReviewThreadCard({
134216 onEditComment,
135217 onToggleResolved,
136218 onReacted,
219+ onCollapse,
137220} : {
138221 thread : PullRequestReviewThread ;
139222 workspaceRoot : string ;
@@ -158,8 +241,10 @@ export function ReviewThreadCard({
158241 onEditComment : ( commentId : string , body : string ) => Promise < boolean > ;
159242 onToggleResolved : ( ) => void ;
160243 onReacted : ( ) => void ;
244+ /** Given on a diff line, where a resolved conversation folds away to its avatar marker. */
245+ onCollapse ?: ( ) => void ;
161246} ) {
162- const [ expanded , setExpanded ] = useState ( ! thread . isResolved ) ;
247+ const [ expanded , setExpanded ] = useState ( onCollapse !== undefined || ! thread . isResolved ) ;
163248 const [ replying , setReplying ] = useState ( false ) ;
164249 const [ reply , setReply ] = useState ( "" ) ;
165250 const [ editingId , setEditingId ] = useState < string | null > ( null ) ;
@@ -248,7 +333,10 @@ export function ReviewThreadCard({
248333 type = "button"
249334 className = "hover:text-foreground"
250335 aria-expanded = { expanded }
251- onClick = { ( ) => setExpanded ( ( current ) => ! current ) }
336+ onClick = { ( ) => {
337+ if ( expanded && thread . isResolved && onCollapse ) onCollapse ( ) ;
338+ else setExpanded ( ( current ) => ! current ) ;
339+ } }
252340 >
253341 { thread . isResolved ? "Resolved" : "Open" } · { commentCount } { " " }
254342 { commentCount === 1 ? "comment" : "comments" }
0 commit comments