Open History to see the last commit
1import type { EnvironmentId, ThreadId } from "@t3tools/contracts";
2import { 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 className="flex-row items-center gap-2 pb-2 pl-4">
23 <SymbolView
24 name="bubble.left.and.bubble.right"
25 size={12}
26 tintColorClassName="accent-foreground-muted"
27 />
28 <Text className="text-xs text-foreground-muted">Side chats</Text>
29 <ScrollView horizontal showsHorizontalScrollIndicator={false} className="flex-1">
30 <View className="flex-row gap-1 pr-4">
31 {sideChats.map((sideChat) => {
32 const needs =
33 sideChat.hasPendingApprovals || sideChat.pendingSubagentRequest === "approval"
34 ? "approval"
35 : sideChat.hasPendingUserInput || sideChat.pendingSubagentRequest
36 ? "input"
37 : null;
38 return (
39 <Pressable
40 key={sideChat.id}
41 accessibilityRole="button"
42 accessibilityLabel={`Open side chat ${sideChat.title}${needs === null ? "" : `, needs ${needs}`}`}
43 className="max-w-48 flex-row items-center gap-1.5 rounded-full bg-subtle px-2.5 py-1"
44 onPress={() =>
45 openLinkedThread({ environmentId: props.environmentId, threadId: sideChat.id })
46 }
47 >
48 {needs === null ? null : (
49 <View
50 className={cn(
51 "h-1.5 w-1.5 shrink-0 rounded-full",
52 needs === "approval" ? "bg-warning-foreground" : "bg-adaptive-indigo-600-300",
53 )}
54 />
55 )}
56 <Text className="shrink text-xs text-foreground" numberOfLines={1}>
57 {sideChat.title}
58 </Text>
59 </Pressable>
60 );
61 })}
62 </View>
63 </ScrollView>
64 </View>
65 );
66}