Open History to see the last commit
1import type { EnvironmentId, ThreadId } from "@t3tools/contracts";
2import { T, useGT } from "gt-react-native";
3import { Platform, Pressable, ScrollView, View } from "react-native";
4
5import { AppText as Text } from "../../components/ui/AppText";
6import { SymbolView } from "../../components/ui/AppSymbol";
7import { Menu } from "../../components/ui/Menu";
8import { cn } from "../../lib/cn";
9import { useSideChats } from "../../state/entities";
10import { useThreadListActions } from "../home/useThreadListActions";
11import { useOpenLinkedThread } from "./useOpenLinkedThread";
12
13/**
14 * The thread's side chats. Each opens as a normal thread, so its approvals and questions can be
15 * answered from the phone; a long press deletes one.
16 */
17export function ThreadSideChatsRow(props: {
18 readonly environmentId: EnvironmentId;
19 readonly threadId: ThreadId;
20}) {
21 const sideChats = useSideChats({ environmentId: props.environmentId, threadId: props.threadId });
22 const openLinkedThread = useOpenLinkedThread();
23 const { confirmDeleteThread } = useThreadListActions();
24 const gt = useGT();
25 if (sideChats.length === 0) return null;
26 return (
27 <View
28 className={cn(
29 "flex-row items-center gap-2 py-2 pl-4",
30 Platform.OS === "android" ? "bg-thread-canvas" : "bg-screen",
31 )}
32 >
33 <SymbolView
34 name="bubble.left.and.bubble.right"
35 size={12}
36 tintColorClassName="accent-foreground-muted"
37 />
38 <Text className="text-xs text-foreground-muted">
39 <T>Side chats</T>
40 </Text>
41 <ScrollView horizontal showsHorizontalScrollIndicator={false} className="flex-1">
42 <View className="flex-row gap-1 pr-4">
43 {sideChats.map((sideChat) => {
44 const needs =
45 sideChat.hasPendingApprovals || sideChat.pendingSubagentRequest === "approval"
46 ? "approval"
47 : sideChat.hasPendingUserInput || sideChat.pendingSubagentRequest
48 ? "input"
49 : null;
50 return (
51 <Menu
52 key={sideChat.id}
53 shouldOpenOnLongPress
54 title={sideChat.title}
55 actions={[
56 {
57 id: "delete",
58 title: gt`Delete side chat`,
59 image: "trash",
60 attributes: { destructive: true },
61 },
62 ]}
63 onPressAction={({ nativeEvent }) => {
64 if (nativeEvent.event === "delete") confirmDeleteThread(sideChat);
65 }}
66 >
67 <Pressable
68 accessibilityRole="button"
69 accessibilityLabel={
70 needs === null
71 ? gt`Open side chat ${{ title: sideChat.title }}`
72 : needs === "approval"
73 ? gt`Open side chat ${{ title: sideChat.title }}, needs approval`
74 : gt`Open side chat ${{ title: sideChat.title }}, needs input`
75 }
76 className="max-w-48 flex-row items-center gap-1.5 rounded-full bg-subtle px-2.5 py-1"
77 accessibilityActions={[{ name: "delete", label: gt`Delete side chat` }]}
78 onAccessibilityAction={(event) => {
79 if (event.nativeEvent.actionName === "delete") confirmDeleteThread(sideChat);
80 }}
81 onPress={() =>
82 openLinkedThread({ environmentId: props.environmentId, threadId: sideChat.id })
83 }
84 >
85 {needs === null ? null : (
86 <View
87 className={cn(
88 "h-1.5 w-1.5 shrink-0 rounded-full",
89 needs === "approval"
90 ? "bg-warning-foreground"
91 : "bg-adaptive-indigo-600-300",
92 )}
93 />
94 )}
95 <Text className="shrink text-xs text-foreground" numberOfLines={1}>
96 {sideChat.title}
97 </Text>
98 </Pressable>
99 </Menu>
100 );
101 })}
102 </View>
103 </ScrollView>
104 </View>
105 );
106}