11import { RefreshIcon } from "~/components/ui/refresh-icon" ;
22import { Spinner } from "~/components/ui/spinner" ;
3- import { scopeThreadRef } from "@t3tools/client-runtime/environment" ;
4- import { pullRequestHostOf , resolveEnvironmentMachineKind , ThreadId } from "@t3tools/contracts" ;
3+ import { pullRequestHostOf , resolveEnvironmentMachineKind } from "@t3tools/contracts" ;
54import type {
65 EnvironmentId ,
76 ProjectId ,
@@ -120,8 +119,12 @@ import { Menu, MenuPopup, MenuRadioGroup, MenuRadioItem, MenuTrigger } from "../
120119import { SidebarInset } from "../components/ui/sidebar" ;
121120import { Tooltip , TooltipPopup , TooltipTrigger } from "../components/ui/tooltip" ;
122121import { useLiveRefresh } from "../hooks/useLiveRefresh" ;
122+ import { useOpenPanelPullRequestUrl } from "../hooks/useOpenPanelPullRequestUrl" ;
123+ import { writeTextToClipboard } from "../hooks/useCopyToClipboard" ;
124+ import { toastManager } from "../components/ui/toast" ;
123125import { usePanelAnimationSettings , usePanelPresence } from "../panelAnimations" ;
124126import {
127+ PULL_REQUESTS_PANEL_REF ,
125128 pullRequestSurfaceId ,
126129 selectActiveRightPanelSurface ,
127130 selectSelectedRightPanelSurface ,
@@ -205,15 +208,6 @@ const PAGE_SIZE = 99;
205208const MAX_PAGE_SIZE = 500 ;
206209/** Stable empty map so the memos below do not see a new object on every render. */
207210const EMPTY_VIEWERS : PullRequestListResult [ "viewers" ] = { } ;
208- /** The list owns one environment-scoped right panel rather than borrowing a real thread's. */
209- const PULL_REQUESTS_PANEL_ID = ThreadId . make ( "pull-requests-panel" ) ;
210- /**
211- * A fixed sentinel, not a real server: the panel is one workspace-level surface list (each
212- * surface already carries the server it was read from), so its store key must not move when a
213- * capable server disconnects or reconnects. Real environment ids are server-generated UUIDs, so
214- * this string can never collide with one.
215- */
216- const PULL_REQUESTS_PANEL_ENVIRONMENT_ID = "pull-requests-panel" as EnvironmentId ;
217211/** Stable so a read that is not wanted right now does not re-key on every render. */
218212const NO_LIST_TARGETS : ReadonlyArray < EnvironmentQueryTarget < PullRequestListInput > > = [ ] ;
219213const EMPTY_PREVIEW_SESSIONS = { } ;
@@ -424,13 +418,8 @@ function PullRequestsRouteView() {
424418 // read from, so tabs from two of them sit side by side instead of replacing each other. Its ref
425419 // uses a fixed sentinel environment, not whichever server happens to sort first, so the tab
426420 // strip survives a capable server disconnecting or losing the pull-requests capability.
427- const rightPanelRef = useMemo (
428- ( ) =>
429- capableEnvironments . length === 0
430- ? null
431- : scopeThreadRef ( PULL_REQUESTS_PANEL_ENVIRONMENT_ID , PULL_REQUESTS_PANEL_ID ) ,
432- [ capableEnvironments . length ] ,
433- ) ;
421+ const rightPanelRef = capableEnvironments . length === 0 ? null : PULL_REQUESTS_PANEL_REF ;
422+ const openPanelPullRequestUrl = useOpenPanelPullRequestUrl ( rightPanelRef ) ;
434423 const rightPanelState = useRightPanelStore ( ( state ) =>
435424 selectThreadRightPanelState ( state . byThreadKey , rightPanelRef ) ,
436425 ) ;
@@ -453,7 +442,7 @@ function PullRequestsRouteView() {
453442 rightPanelState . isOpen && selectedPullRequestSurface !== null ,
454443 rightPanelPresenceValue ,
455444 panelAnimationsActive ,
456- rightPanelRef === null ? null : PULL_REQUESTS_PANEL_ID ,
445+ rightPanelRef ?. threadId ?? null ,
457446 panelAnimationDurationMs ,
458447 ) ;
459448 const rightPanelPresent = rightPanelPresence . present ;
@@ -1852,8 +1841,27 @@ function PullRequestsRouteView() {
18521841 selectSurfaceInUrl ( null ) ;
18531842 } ;
18541843
1855- // This page has no ChatView, so the shared panel handles `rightPanel.close`
1856- // itself. With nothing open the event falls through to its native meaning.
1844+ // This page has no ChatView, so it handles the shared panel shortcuts itself.
1845+ const copyPullRequestFromShortcut = useEffectEvent ( ( event : KeyboardEvent ) => {
1846+ if ( ! openPanelPullRequestUrl ) return ;
1847+ event . preventDefault ( ) ;
1848+ event . stopPropagation ( ) ;
1849+ if ( event . repeat ) return ;
1850+ const url = openPanelPullRequestUrl ;
1851+ void writeTextToClipboard ( url , "pull request link" ) . then (
1852+ ( didCopy ) => {
1853+ if ( didCopy )
1854+ toastManager . add ( { type : "success" , title : "PR link copied" , description : url } ) ;
1855+ } ,
1856+ ( error ) => {
1857+ toastManager . add ( {
1858+ type : "error" ,
1859+ title : "Failed to copy PR link" ,
1860+ description : error instanceof Error ? error . message : "An error occurred." ,
1861+ } ) ;
1862+ } ,
1863+ ) ;
1864+ } ) ;
18571865 const closeActiveSurfaceFromShortcut = useEffectEvent ( ( event : KeyboardEvent ) => {
18581866 if ( activePullRequestSurface === null ) return ;
18591867 event . preventDefault ( ) ;
@@ -1867,6 +1875,7 @@ function PullRequestsRouteView() {
18671875 context : { terminalFocus : isTerminalFocused ( ) } ,
18681876 } ) ;
18691877 if ( command === "rightPanel.close" ) closeActiveSurfaceFromShortcut ( event ) ;
1878+ if ( command === "thread.copyReference" ) copyPullRequestFromShortcut ( event ) ;
18701879 } ;
18711880 window . addEventListener ( "keydown" , onKeyDown ) ;
18721881 return ( ) => window . removeEventListener ( "keydown" , onKeyDown ) ;
0 commit comments