11import { ThreadDetailsControl } from "./ThreadDetailsControl" ;
2- import type { EnvironmentId , ThreadPullRequestLink } from "@t3tools/contracts" ;
2+ import type { EnvironmentId , ScopedThreadRef , ThreadPullRequestLink } from "@t3tools/contracts" ;
33import {
44 resolveThreadPullRequestChains ,
55 threadPullRequestKeyOf ,
@@ -11,6 +11,8 @@ import { useState, type ComponentProps, type MouseEvent as ReactMouseEvent } fro
1111import { findProjectOnChangeRequestHost , parseChangeRequestUrl } from "~/lib/openPullRequestLink" ;
1212
1313import { useProjects } from "~/state/entities" ;
14+ import { threadEnvironment } from "~/state/threads" ;
15+ import { useAtomCommand } from "~/state/use-atom-command" ;
1416
1517import { pullRequestListLines } from "../pullRequest/pullRequestListLines" ;
1618import { MorphIcon } from "~/components/MorphIcon" ;
@@ -23,11 +25,13 @@ function ThreadDetailsPrLinkRow({
2325 link,
2426 onOpen,
2527 onActed,
28+ onStopWatching,
2629} : {
2730 environmentId : EnvironmentId ;
2831 link : ThreadPullRequestLink ;
2932 onOpen : ( event : ReactMouseEvent < HTMLElement > ) => void ;
3033 onActed ?: ( ( ) => void ) | undefined ;
34+ onStopWatching ?: ( ( ) => void ) | undefined ;
3135} ) {
3236 const projects = useProjects ( ) ;
3337 const parsed = parseChangeRequestUrl ( link . url ) ;
@@ -51,33 +55,53 @@ function ThreadDetailsPrLinkRow({
5155 label = { `#${ link . number } ${ link . snapshot === null ? "" : `: ${ link . snapshot . title } ` } ` }
5256 openAriaLabel = { link . url }
5357 onOpen = { onOpen }
58+ onStopWatching = { onStopWatching }
5459 { ...( onActed ? { onActed } : { } ) }
5560 />
5661 ) ;
5762}
5863
5964export function ThreadDetailsPrRows ( {
65+ threadRef,
6066 links,
6167 currentLink,
6268 onOpenLink,
6369 ...row
6470} : ComponentProps < typeof ThreadDetailsPrRow > & {
71+ threadRef : ScopedThreadRef ;
6572 links : ReadonlyArray < ThreadPullRequestLink > ;
6673 currentLink : ThreadPullRequestLink | null ;
6774 onOpenLink : ( event : ReactMouseEvent < HTMLElement > , url : string ) => void ;
6875} ) {
6976 const [ expanded , setExpanded ] = useState ( false ) ;
77+ const watch = useAtomCommand ( threadEnvironment . watchPullRequest , { reportFailure : true } ) ;
78+ // Only watched links get the eye; the row hides it once the server records the stop.
79+ const stopWatching = ( link : ThreadPullRequestLink | null ) =>
80+ link ?. watch === undefined
81+ ? undefined
82+ : ( ) =>
83+ void watch ( {
84+ environmentId : threadRef . environmentId ,
85+ input : {
86+ threadId : threadRef . threadId ,
87+ host : link . host ,
88+ repository : link . repository ,
89+ number : link . number ,
90+ watching : false ,
91+ } ,
92+ } ) ;
93+ const currentRow = < ThreadDetailsPrRow { ...row } onStopWatching = { stopWatching ( currentLink ) } /> ;
7094 const rest =
7195 currentLink === null
7296 ? [ ]
7397 : pullRequestListLines ( resolveThreadPullRequestChains ( visibleThreadPullRequests ( links ) ) )
7498 . map ( ( line ) => line . link )
7599 . filter ( ( link ) => threadPullRequestKeyOf ( link ) !== threadPullRequestKeyOf ( currentLink ) ) ;
76- if ( rest . length === 0 ) return < ThreadDetailsPrRow { ... row } /> ;
100+ if ( rest . length === 0 ) return currentRow ;
77101
78102 return (
79103 < >
80- < ThreadDetailsPrRow { ... row } />
104+ { currentRow }
81105 { expanded
82106 ? rest . map ( ( link ) => (
83107 < ThreadDetailsPrLinkRow
@@ -86,6 +110,7 @@ export function ThreadDetailsPrRows({
86110 link = { link }
87111 onOpen = { ( event ) => onOpenLink ( event , link . url ) }
88112 onActed = { row . onActed }
113+ onStopWatching = { stopWatching ( link ) }
89114 />
90115 ) )
91116 : null }
0 commit comments