Skip to content

Commit e64b7f1

Browse files
committed
fix(mobile): center link sheets and keep confirmation visible
1 parent d1909d6 commit e64b7f1

3 files changed

Lines changed: 72 additions & 26 deletions

File tree

‎apps/mobile/src/Stack.tsx‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ import { GitConfirmSheet } from "./features/threads/git/GitConfirmSheet";
6262
import { GitOverviewSheet } from "./features/threads/git/GitOverviewSheet";
6363
import { ThreadPullRequestsSheet } from "./features/threads/ThreadPullRequestsSheet";
6464
import { ThreadAgentsSheet } from "./features/threads/ThreadAgentsSheet";
65+
import { LinkRequestRouteScreen } from "./features/threads/LinkRequestCard";
6566
import { ThreadBackgroundWorkSheet } from "./features/threads/ThreadBackgroundWorkSheet";
6667
import { ThreadQueueSheet } from "./features/threads/ThreadQueueControl";
6768
import {
@@ -677,6 +678,10 @@ const RootStackConfig = createWorkspaceStackNavigator({
677678
screen: ThreadAgentsSheet,
678679
options: sheetRoute({ detent: 0.5, androidMaxDetent: 0.9 }),
679680
}),
681+
ThreadLinkRequest: createNativeStackScreen({
682+
screen: LinkRequestRouteScreen,
683+
options: sheetRoute({ detent: 0.5, androidMaxDetent: 0.9 }),
684+
}),
680685
GitOverview: createNativeStackScreen({
681686
screen: GitOverviewSheet,
682687
linking: `${THREAD_LINKING_PREFIX}/git`,

‎apps/mobile/src/features/layout/workspace-overlay-routes.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const LISTED_OVERLAY_ROUTES: ReadonlySet<string> = new Set([
2828
"SettingsAuth",
2929
"SettingsWaitlist",
3030
"ThreadAgents",
31+
"ThreadLinkRequest",
3132
"ThreadBackgroundWork",
3233
"ThreadPullRequests",
3334
"ThreadQueue",

‎apps/mobile/src/features/threads/LinkRequestCard.tsx‎

Lines changed: 66 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { pipe } from "effect/Function";
22
import { useAtomValue } from "@effect/atom-react";
3+
import { useNavigation, type StaticScreenProps } from "@react-navigation/native";
34
import {
45
type LinkableMachine,
56
linkRequestAnswerInput,
@@ -20,6 +21,8 @@ import {
2021
type AuthMcpClientAccess,
2122
type EnvironmentId,
2223
type OrchestrationV2ProjectedTurnItem,
24+
type ThreadId,
25+
type TurnItemId,
2326
} from "@t3tools/contracts";
2427
import * as Option from "effect/Option";
2528
import * as Result from "effect/Result";
@@ -37,7 +40,10 @@ import { useAtomCommand } from "../../state/use-atom-command";
3740
import { ListChoiceRow as SettingsChoiceRow } from "../../components/ui/ListChoiceRow";
3841
import { SettingsSection } from "../settings/components/SettingsSection";
3942
import { Button } from "../../components/ui/Button";
40-
import { Sheet } from "../../components/ui/Sheet";
43+
import { ScreenContent } from "../../components/ui/ScreenContent";
44+
import { SheetHeader } from "../../components/ui/SheetHeader";
45+
import { useHardwareBack } from "../../lib/backHandler";
46+
import { useEnvironmentThread } from "../../state/threads";
4147
import { RUNTIME_MODE_CHOICES } from "./thread-settings-options";
4248

4349
/** The same five levels as web's access picker: read-only, then the runtime modes. */
@@ -104,7 +110,7 @@ function PendingLinkRequest(props: {
104110
readonly item: LinkRequestItem;
105111
}) {
106112
const { item } = props;
107-
const [open, setOpen] = useState(false);
113+
const navigation = useNavigation();
108114
const [declining, setDeclining] = useState(false);
109115
const [error, setError] = useState<string | null>(null);
110116
const answer = useAtomCommand(peerLinkEnvironment.answerRequest, {
@@ -161,7 +167,13 @@ function PendingLinkRequest(props: {
161167
<Button
162168
label={picksMachine(item) ? "Choose machine…" : "Review link…"}
163169
disabled={declining}
164-
onPress={() => setOpen(true)}
170+
onPress={() =>
171+
navigation.navigate("ThreadLinkRequest", {
172+
environmentId: props.environmentId,
173+
threadId: item.threadId,
174+
itemId: item.id,
175+
})
176+
}
165177
tone="primary"
166178
fullWidth
167179
/>
@@ -183,13 +195,33 @@ function PendingLinkRequest(props: {
183195
Only a session that manages access here can answer this.
184196
</Text>
185197
)}
186-
{open ? (
187-
<LinkRequestSheet
188-
environmentId={props.environmentId}
189-
item={item}
190-
onClose={() => setOpen(false)}
191-
/>
192-
) : null}
198+
</View>
199+
);
200+
}
201+
202+
export function LinkRequestRouteScreen({
203+
route,
204+
}: StaticScreenProps<{
205+
readonly environmentId: EnvironmentId;
206+
readonly threadId: ThreadId;
207+
readonly itemId: TurnItemId;
208+
}>) {
209+
const navigation = useNavigation();
210+
const thread = useEnvironmentThread(route.params.environmentId, route.params.threadId);
211+
const item = Option.getOrNull(thread.data)?.turnItems.find(
212+
(item) => item.id === route.params.itemId,
213+
);
214+
const close = () => navigation.goBack();
215+
return item?.type === "link_request" && item.linkStatus === "pending" ? (
216+
<LinkRequestSheet environmentId={route.params.environmentId} item={item} onClose={close} />
217+
) : (
218+
<View className="flex-1 bg-sheet">
219+
<SheetHeader title="Link a machine" onClose={close} />
220+
<ScreenContent>
221+
<Text className="p-5 text-sm text-foreground-muted">
222+
This link request is no longer pending.
223+
</Text>
224+
</ScreenContent>
193225
</View>
194226
);
195227
}
@@ -244,6 +276,7 @@ function LinkRequestSheet(props: {
244276
const [mintFailed, setMintFailed] = useState<ReadonlySet<EnvironmentId>>(new Set());
245277
// Submit then a tap can both run before a re-render; this guard is synchronous.
246278
const inFlight = useRef(false);
279+
useHardwareBack(busy, () => true);
247280
const answer = useAtomCommand(peerLinkEnvironment.answerRequest, {
248281
label: "answer link request",
249282
// The failure cause holds the request, and with it the code; keep it out of the console.
@@ -316,19 +349,16 @@ function LinkRequestSheet(props: {
316349
}
317350
};
318351

319-
return (
320-
<Sheet
321-
title={pickMachine ? "Link a machine" : `Link ${targetName}`}
322-
onClose={props.onClose}
323-
// An answer that lands after a close would still link, and would close a reopened sheet.
324-
dismissDisabled={busy}
325-
>
352+
const content = (
353+
<ScreenContent>
326354
<ScrollView
355+
nestedScrollEnabled
327356
className="flex-1 bg-sheet-solid"
328357
contentInsetAdjustmentBehavior="automatic"
329358
contentContainerClassName="gap-5 p-5"
330359
contentContainerStyle={{ paddingBottom: insets.bottom + 20 }}
331360
keyboardShouldPersistTaps="handled"
361+
automaticallyAdjustKeyboardInsets
332362
>
333363
<View className="gap-1">
334364
<Text className="font-sans text-sm leading-5 text-foreground-muted">
@@ -445,16 +475,26 @@ function LinkRequestSheet(props: {
445475
{error}
446476
</Text>
447477
) : null}
448-
<Button
449-
label={busy ? "Linking…" : useExisting ? "Use this link" : "Link"}
450-
disabled={busy || !ready}
451-
onPress={() => void submit()}
452-
tone="primary"
453-
fullWidth
454-
/>
455-
<Button label="Cancel" tone="secondary" disabled={busy} onPress={props.onClose} fullWidth />
456478
</ScrollView>
457-
</Sheet>
479+
</ScreenContent>
480+
);
481+
482+
return (
483+
<View collapsable={false} className="flex-1 bg-sheet android:flex-col-reverse">
484+
{content}
485+
<SheetHeader
486+
title={pickMachine ? "Link a machine" : `Link ${targetName}`}
487+
onCancel={props.onClose}
488+
// An answer that lands after a close would still link, and would close a reopened sheet.
489+
dismissDisabled={busy}
490+
confirm={{
491+
label: busy ? "Linking…" : useExisting ? "Use this link" : "Link",
492+
disabled: busy || !ready,
493+
loading: busy,
494+
onPress: () => void submit(),
495+
}}
496+
/>
497+
</View>
458498
);
459499
}
460500

0 commit comments

Comments
 (0)