@@ -25,6 +25,7 @@ import {
2525import { Alert , Platform , ScrollView , View } from "react-native" ;
2626import { useSafeAreaInsets } from "react-native-safe-area-context" ;
2727import { useWorkspaceState } from "../../state/workspace" ;
28+ import { useEnvironmentShellState } from "../../state/shell" ;
2829import { restoredNewTaskDraftKey } from "../../state/new-task-draft-key" ;
2930import { clearPendingThreadCreationOutcome } from "../../state/pending-thread-creation" ;
3031import { recoverFailedThreadDraft } from "../../state/recover-failed-thread-draft" ;
@@ -88,6 +89,7 @@ import {
8889 ThreadInspectorContentStack ,
8990 type ThreadInspectorMode ,
9091} from "./thread-inspector-content-stack" ;
92+ import { threadRouteIsHydrating } from "./thread-route-hydration" ;
9193
9294interface ThreadInspectorSelection {
9395 readonly routeThreadIdentity : string | null ;
@@ -123,7 +125,11 @@ interface ThreadRouteScreenProps extends ThreadRouteScreenRouteProps {
123125 readonly renderInspector ?: ( headerInset : number ) => ReactNode ;
124126}
125127
126- function ThreadUnavailableScreen ( ) {
128+ /** Shows recovery only after the target route has reached a terminal unavailable state. */
129+ function ThreadUnavailableScreen ( props : {
130+ readonly actionLabel : string ;
131+ readonly onAction : ( ) => void ;
132+ } ) {
127133 return (
128134 < ScrollView
129135 contentInsetAdjustmentBehavior = "automatic"
@@ -138,6 +144,8 @@ function ThreadUnavailableScreen() {
138144 < EmptyState
139145 title = "Thread unavailable"
140146 detail = "This thread is not available in the current mobile snapshot."
147+ actionLabel = { props . actionLabel }
148+ onAction = { props . onAction }
141149 />
142150 </ ScrollView >
143151 ) ;
@@ -152,6 +160,9 @@ export function ThreadRouteScreen(props: ThreadRouteScreenProps) {
152160 const threadIdRaw = firstRouteParam ( params . threadId ) ;
153161 const environmentId = environmentIdRaw ? EnvironmentId . make ( environmentIdRaw ) : null ;
154162 const routeEnvironmentRuntime = useRemoteEnvironmentRuntime ( environmentId ) ;
163+ const routeEnvironmentShellState = useEnvironmentShellState ( environmentId ) ;
164+ const { onReconnectEnvironment } = useRemoteConnections ( ) ;
165+ const navigation = useNavigation ( ) ;
155166 const routeConnectionState =
156167 routeEnvironmentRuntime ?. connectionState ?? ( environmentId ? "available" : connectionState ) ;
157168 const routeThreadKey =
@@ -177,16 +188,36 @@ export function ThreadRouteScreen(props: ThreadRouteScreenProps) {
177188 return < ThreadRouteContent { ...props } selectedThreadDetailState = { selectedThreadDetailState } /> ;
178189 }
179190
180- const stillHydrating =
181- workspaceState . isLoadingConnections ||
182- routeConnectionState === "connecting" ||
183- routeConnectionState === "reconnecting" ;
191+ const stillHydrating = threadRouteIsHydrating ( {
192+ isLoadingConnections : workspaceState . isLoadingConnections ,
193+ connectionState : routeConnectionState ,
194+ shellStatus : routeEnvironmentShellState . status ,
195+ shellHasError : Option . isSome ( routeEnvironmentShellState . error ) ,
196+ detailStatus : selectedThreadDetailState . status ,
197+ detailHasError : Option . isSome ( selectedThreadDetailState . error ) ,
198+ } ) ;
184199
185200 if ( stillHydrating ) {
186201 return < OpeningThreadLoadingScreen /> ;
187202 }
188203
189- return < ThreadUnavailableScreen /> ;
204+ return (
205+ < ThreadUnavailableScreen
206+ actionLabel = {
207+ routeEnvironmentRuntime === null ? "Manage environments" : "Reconnect environment"
208+ }
209+ onAction = { ( ) => {
210+ if ( routeEnvironmentRuntime !== null ) {
211+ onReconnectEnvironment ( environmentId ) ;
212+ return ;
213+ }
214+ navigation . navigate ( "SettingsSheet" , {
215+ screen : "SettingsContent" ,
216+ params : { screen : "SettingsEnvironments" } ,
217+ } ) ;
218+ } }
219+ />
220+ ) ;
190221}
191222
192223function ThreadRouteContent (
0 commit comments