The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 03:37 UTC
| 1 | import { EnvironmentId, ThreadId } from "@t3tools/contracts"; |
| 2 | import { useNavigation } from "@react-navigation/native"; |
| 3 | import { useAdaptiveWorkspaceLayout } from "../adaptive-workspace-context"; |
| 4 | import { startOpeningEnvironmentThread } from "../../../state/threads"; |
| 5 | import { |
| 6 | selectWorkspaceDetail, |
| 7 | type WorkspaceDetail, |
| 8 | type WorkspaceDetailSheet, |
| 9 | } from "./workspace-detail-selection"; |
| 10 | |
| 11 | const first = (value: string | readonly string[] | undefined) => |
| 12 | typeof value === "string" ? value : value?.[0]; |
| 13 | |
| 14 | /** Starts loading a selected thread before navigation commits; see `startOpeningEnvironmentThread`. */ |
| 15 | export function startOpeningDetail(detail: WorkspaceDetail) { |
| 16 | if (detail.name !== "Thread") return; |
| 17 | const environmentId = first(detail.params?.environmentId); |
| 18 | const threadId = first(detail.params?.threadId); |
| 19 | if (environmentId && threadId) { |
| 20 | startOpeningEnvironmentThread(EnvironmentId.make(environmentId), ThreadId.make(threadId)); |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | /** |
| 25 | * Shows a page in the detail column the way selecting its list row does. Inside the workspace |
| 26 | * layout this also settles its panes; outside it, the root stack's router still does the rest. |
| 27 | */ |
| 28 | export function useSelectWorkspaceDetail() { |
| 29 | const navigation = useNavigation(); |
| 30 | const { selectDetail } = useAdaptiveWorkspaceLayout(); |
| 31 | return ( |
| 32 | selectDetail ?? |
| 33 | ((detail: WorkspaceDetail, sheet?: WorkspaceDetailSheet) => { |
| 34 | startOpeningDetail(detail); |
| 35 | navigation.dispatch(selectWorkspaceDetail(detail, sheet)); |
| 36 | }) |
| 37 | ); |
| 38 | } |