@@ -116,121 +116,62 @@ export function PendingReviewCommentCard({
116116 ) ;
117117}
118118
119- const MARKER_AVATAR_LIMIT = 3 ;
120-
121- function ResolvedThreadsMarker ( {
119+ /** The conversations on one diff line. Resolved ones hide behind their authors' avatars. */
120+ export function InlineReviewThreads ( {
122121 threads,
123- autoFocus,
124- onOpen,
122+ renderThread,
125123} : {
126124 threads : ReadonlyArray < PullRequestReviewThread > ;
127- autoFocus : boolean ;
128- onOpen : ( ) => void ;
125+ renderThread : ( thread : PullRequestReviewThread , hidden : boolean ) => ReactNode ;
129126} ) {
127+ const [ shown , setShown ] = useState < ReadonlySet < string > > ( ( ) => new Set ( ) ) ;
128+ // A conversation seen open stays shown once resolved, so it does not vanish under the reader.
129+ const open = threads . filter ( ( thread ) => ! thread . isResolved ) ;
130+ if ( open . some ( ( thread ) => ! shown . has ( thread . id ) ) ) {
131+ setShown ( new Set ( [ ...shown , ...open . map ( ( thread ) => thread . id ) ] ) ) ;
132+ }
133+ const resolved = threads . filter ( ( thread ) => thread . isResolved ) ;
134+ const expanded = resolved . every ( ( thread ) => shown . has ( thread . id ) ) ;
130135 const authors = new Map < string , PullRequestActor | null > ( ) ;
131- for ( const thread of threads ) {
132- for ( const comment of thread . comments ) {
133- authors . set ( comment . author ?. login ?? "ghost" , comment . author ) ;
134- }
136+ for ( const comment of resolved . flatMap ( ( thread ) => thread . comments ) ) {
137+ authors . set ( comment . author ?. login ?? "ghost" , comment . author ) ;
135138 }
136139 if ( authors . size === 0 ) authors . set ( "ghost" , null ) ;
137140 const label =
138- threads . length === 1
139- ? "Show resolved conversation"
140- : `Show ${ threads . length } resolved conversations` ;
141- return (
142- < Tooltip >
143- < TooltipTrigger
144- render = {
145- < button
146- type = "button"
147- data-resolved-threads
148- aria-label = { label }
149- aria-expanded = { false }
150- autoFocus = { autoFocus }
151- // Sits on the commented line, which is the row above this zero-height annotation.
152- 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"
153- contentEditable = { false }
154- onPointerDown = { ( event ) => event . stopPropagation ( ) }
155- onClick = { onOpen }
156- />
157- }
158- >
159- { [ ...authors ] . slice ( 0 , MARKER_AVATAR_LIMIT ) . map ( ( [ login , author ] ) => (
160- < PullRequestActorAvatar key = { login } actor = { author } className = "ring-1 ring-background" />
161- ) ) }
162- </ TooltipTrigger >
163- < TooltipPopup side = "left" > { label } </ TooltipPopup >
164- </ Tooltip >
165- ) ;
166- }
167-
168- /** A conversation on a diff line: its line owns whether it is expanded or folded to the marker. */
169- export interface ReviewThreadFold {
170- readonly expanded : boolean ;
171- /** Folded cards stay mounted, so an unsent reply survives the fold. */
172- readonly folded : boolean ;
173- readonly focusHeader : boolean ;
174- readonly onToggle : ( ) => void ;
175- }
176-
177- /** The conversations on one diff line. Resolved ones show as avatars until opened. */
178- export function InlineReviewThreads ( {
179- threads,
180- renderThread,
181- } : {
182- threads : ReadonlyArray < PullRequestReviewThread > ;
183- renderThread : ( thread : PullRequestReviewThread , fold : ReviewThreadFold ) => ReactNode ;
184- } ) {
185- const [ choices , setChoices ] = useState < ReadonlyMap < string , boolean > > ( ( ) => new Map ( ) ) ;
186- // Folding swaps the focused control for another, so focus is handed to its replacement.
187- // Each collapse remounts the marker, so one already on the line takes focus too.
188- const [ focus , setFocus ] = useState <
189- { readonly marker : number } | { readonly threadId : string } | null
190- > ( null ) ;
191- const markerFocus = focus !== null && "marker" in focus ? focus . marker : 0 ;
192- // A conversation seen open starts expanded, so resolving it does not fold it under the reader.
193- const seenOpen = threads . filter ( ( thread ) => ! thread . isResolved && ! choices . has ( thread . id ) ) ;
194- if ( seenOpen . length > 0 ) {
195- setChoices ( new Map ( [ ...choices , ...seenOpen . map ( ( thread ) => [ thread . id , true ] as const ) ] ) ) ;
196- }
197- const isExpanded = ( thread : PullRequestReviewThread ) =>
198- choices . get ( thread . id ) ?? ! thread . isResolved ;
199- const folded = threads . filter ( ( thread ) => thread . isResolved && ! isExpanded ( thread ) ) ;
200- // A focus request lives only while its target is on the line, so a later remount cannot steal focus.
201- const focusTargetGone =
202- focus !== null &&
203- ( "marker" in focus
204- ? folded . length === 0
205- : ! threads . some ( ( thread ) => thread . id === focus . threadId && ! folded . includes ( thread ) ) ) ;
206- if ( focusTargetGone ) setFocus ( null ) ;
141+ resolved . length === 1 ? "Resolved conversation" : `${ resolved . length } resolved conversations` ;
207142 return (
208143 < >
209- { folded . length > 0 ? (
210- < ResolvedThreadsMarker
211- key = { markerFocus }
212- threads = { folded }
213- autoFocus = { markerFocus > 0 }
214- onOpen = { ( ) => {
215- setChoices (
216- new Map ( [ ...choices , ...folded . map ( ( thread ) => [ thread . id , true ] as const ) ] ) ,
217- ) ;
218- setFocus ( folded [ 0 ] ? { threadId : folded [ 0 ] . id } : null ) ;
219- } }
220- />
144+ { resolved . length > 0 ? (
145+ < Tooltip >
146+ < TooltipTrigger
147+ render = {
148+ < button
149+ type = "button"
150+ data-resolved-threads
151+ aria-label = { label }
152+ aria-expanded = { expanded }
153+ // Sits on the commented line, which is the row above this annotation.
154+ 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"
155+ contentEditable = { false }
156+ onPointerDown = { ( event ) => event . stopPropagation ( ) }
157+ onClick = { ( ) =>
158+ setShown ( new Set ( ( expanded ? open : threads ) . map ( ( thread ) => thread . id ) ) )
159+ }
160+ />
161+ }
162+ >
163+ { [ ...authors ] . slice ( 0 , 3 ) . map ( ( [ login , author ] ) => (
164+ < PullRequestActorAvatar
165+ key = { login }
166+ actor = { author }
167+ className = "ring-1 ring-background"
168+ />
169+ ) ) }
170+ </ TooltipTrigger >
171+ < TooltipPopup side = "left" > { label } </ TooltipPopup >
172+ </ Tooltip >
221173 ) : null }
222- { threads . map ( ( thread ) =>
223- renderThread ( thread , {
224- expanded : isExpanded ( thread ) ,
225- folded : folded . includes ( thread ) ,
226- focusHeader : focus !== null && "threadId" in focus && focus . threadId === thread . id ,
227- onToggle : ( ) => {
228- const expanded = ! isExpanded ( thread ) ;
229- setChoices ( new Map ( choices ) . set ( thread . id , expanded ) ) ;
230- if ( ! expanded && thread . isResolved ) setFocus ( { marker : markerFocus + 1 } ) ;
231- } ,
232- } ) ,
233- ) }
174+ { threads . map ( ( thread ) => renderThread ( thread , thread . isResolved && ! shown . has ( thread . id ) ) ) }
234175 </ >
235176 ) ;
236177}
@@ -255,7 +196,7 @@ export function ReviewThreadCard({
255196 onEditComment,
256197 onToggleResolved,
257198 onReacted,
258- fold ,
199+ hidden ,
259200} : {
260201 thread : PullRequestReviewThread ;
261202 workspaceRoot : string ;
@@ -280,10 +221,10 @@ export function ReviewThreadCard({
280221 onEditComment : ( commentId : string , body : string ) => Promise < boolean > ;
281222 onToggleResolved : ( ) => void ;
282223 onReacted : ( ) => void ;
283- fold ?: ReviewThreadFold ;
224+ /** Set on a diff line. Hidden draws nothing but stays mounted, so an unsent reply survives. */
225+ hidden ?: boolean ;
284226} ) {
285- const [ ownExpanded , setOwnExpanded ] = useState ( ! thread . isResolved ) ;
286- const expanded = fold ?. expanded ?? ownExpanded ;
227+ const [ expanded , setExpanded ] = useState ( hidden !== undefined || ! thread . isResolved ) ;
287228 const [ replying , setReplying ] = useState ( false ) ;
288229 const [ reply , setReply ] = useState ( "" ) ;
289230 const [ editingId , setEditingId ] = useState < string | null > ( null ) ;
@@ -356,7 +297,7 @@ export function ReviewThreadCard({
356297 } ) ) ;
357298 } ;
358299
359- if ( fold ?. folded ) return null ;
300+ if ( hidden ) return null ;
360301
361302 return (
362303 < div
@@ -374,8 +315,7 @@ export function ReviewThreadCard({
374315 type = "button"
375316 className = "hover:text-foreground"
376317 aria-expanded = { expanded }
377- autoFocus = { fold ?. focusHeader === true }
378- onClick = { ( ) => ( fold ? fold . onToggle ( ) : setOwnExpanded ( ( current ) => ! current ) ) }
318+ onClick = { ( ) => setExpanded ( ( current ) => ! current ) }
379319 >
380320 { thread . isResolved ? "Resolved" : "Open" } · { commentCount } { " " }
381321 { commentCount === 1 ? "comment" : "comments" }
0 commit comments