The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import type { EnvironmentId, ThreadId } from "@t3tools/contracts"; |
| 2 | import { T, useGT } from "gt-react-native"; |
| 3 | import { Platform, Pressable, ScrollView, View } from "react-native"; |
| 4 | |
| 5 | import { AppText as Text } from "../../components/ui/AppText"; |
| 6 | import { SymbolView } from "../../components/ui/AppSymbol"; |
| 7 | import { cn } from "../../lib/cn"; |
| 8 | import { useSideChats } from "../../state/entities"; |
| 9 | import { useOpenLinkedThread } from "./useOpenLinkedThread"; |
| 10 | |
| 11 | /** |
| 12 | * The thread's side chats, started on web or desktop. Each opens as a normal thread, so its |
| 13 | * approvals and questions can be answered from the phone. |
| 14 | */ |
| 15 | export function ThreadSideChatsRow(props: { |
| 16 | readonly environmentId: EnvironmentId; |
| 17 | readonly threadId: ThreadId; |
| 18 | }) { |
| 19 | const sideChats = useSideChats({ environmentId: props.environmentId, threadId: props.threadId }); |
| 20 | const openLinkedThread = useOpenLinkedThread(); |
| 21 | const gt = useGT(); |
| 22 | if (sideChats.length === 0) return null; |
| 23 | return ( |
| 24 | <View |
| 25 | className={cn( |
| 26 | "flex-row items-center gap-2 py-2 pl-4", |
| 27 | Platform.OS === "android" ? "bg-thread-canvas" : "bg-screen", |
| 28 | )} |
| 29 | > |
| 30 | <SymbolView |
| 31 | name="bubble.left.and.bubble.right" |
| 32 | size={12} |
| 33 | tintColorClassName="accent-foreground-muted" |
| 34 | /> |
| 35 | <Text className="text-xs text-foreground-muted"> |
| 36 | <T>Side chats</T> |
| 37 | </Text> |
| 38 | <ScrollView horizontal showsHorizontalScrollIndicator={false} className="flex-1"> |
| 39 | <View className="flex-row gap-1 pr-4"> |
| 40 | {sideChats.map((sideChat) => { |
| 41 | const needs = |
| 42 | sideChat.hasPendingApprovals || sideChat.pendingSubagentRequest === "approval" |
| 43 | ? "approval" |
| 44 | : sideChat.hasPendingUserInput || sideChat.pendingSubagentRequest |
| 45 | ? "input" |
| 46 | : null; |
| 47 | return ( |
| 48 | <Pressable |
| 49 | key={sideChat.id} |
| 50 | accessibilityRole="button" |
| 51 | accessibilityLabel={ |
| 52 | needs === null |
| 53 | ? gt("Open side chat {title}", { title: sideChat.title }) |
| 54 | : needs === "approval" |
| 55 | ? gt("Open side chat {title}, needs approval", { title: sideChat.title }) |
| 56 | : gt("Open side chat {title}, needs input", { title: sideChat.title }) |
| 57 | } |
| 58 | className="max-w-48 flex-row items-center gap-1.5 rounded-full bg-subtle px-2.5 py-1" |
| 59 | onPress={() => |
| 60 | openLinkedThread({ environmentId: props.environmentId, threadId: sideChat.id }) |
| 61 | } |
| 62 | > |
| 63 | {needs === null ? null : ( |
| 64 | <View |
| 65 | className={cn( |
| 66 | "h-1.5 w-1.5 shrink-0 rounded-full", |
| 67 | needs === "approval" ? "bg-warning-foreground" : "bg-adaptive-indigo-600-300", |
| 68 | )} |
| 69 | /> |
| 70 | )} |
| 71 | <Text className="shrink text-xs text-foreground" numberOfLines={1}> |
| 72 | {sideChat.title} |
| 73 | </Text> |
| 74 | </Pressable> |
| 75 | ); |
| 76 | })} |
| 77 | </View> |
| 78 | </ScrollView> |
| 79 | </View> |
| 80 | ); |
| 81 | } |