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