Open History to see the last commit
1import * as Haptics from "expo-haptics";
2import { SymbolView } from "expo-symbols";
3import type { EnvironmentId, ThreadId } from "@t3tools/contracts";
4import { useNavigation } from "@react-navigation/native";
5import { useMemo, useState } from "react";
6import { Linking, Pressable, ScrollView, type ColorValue, View } from "react-native";
7
8import { AppText as Text } from "../../components/AppText";
9import type { ThreadFeedActivity } from "../../lib/threadActivity";
10import { buildThreadActivityInspector } from "../../lib/threadActivityInspector";
11import { resolveWorkspaceRelativeFilePath } from "../files/filePath";
12import { threadEnvironment } from "../../state/threads";
13import { useAtomCommand } from "../../state/use-atom-command";
14import { useV2ItemSupport } from "../../state/v2-item-support";
15import { buildThreadActivityFileParams } from "./threadActivityFileNavigation";
16
17export function ThreadActivityInspector(props: {
18 readonly activity: ThreadFeedActivity;
19 readonly currentThreadId: ThreadId;
20 readonly environmentId: EnvironmentId;
21 readonly iconColor: ColorValue;
22 readonly workspaceRoot?: string | null;
23}) {
24 const navigation = useNavigation();
25 const row = props.activity.projectedItem;
26 const support = useV2ItemSupport({
27 environmentId: props.environmentId,
28 sourceThreadId: row.sourceThreadId,
29 sourceItemId: row.sourceItemId,
30 });
31 const model = useMemo(
32 () => buildThreadActivityInspector(props.activity, support, props.currentThreadId),
33 [props.activity, props.currentThreadId, support],
34 );
35 const revertCheckpoint = useAtomCommand(threadEnvironment.revertCheckpoint, {
36 label: "checkpoint rollback",
37 reportFailure: true,
38 });
39 const [rollingBack, setRollingBack] = useState(false);
40
41 return (
42 <View className="gap-3">
43 <View className="flex-row flex-wrap gap-x-4 gap-y-2 rounded-lg border border-adaptive-neutral-300-a60-white-a12 bg-adaptive-black-a2p5-white-a2p5 p-2.5">
44 {model.fields.map((field) => (
45 <View key={`${field.label}:${field.value}`} className="min-w-[42%] flex-1 gap-0.5">
46 <Text className="font-t3-medium text-3xs uppercase tracking-wide text-foreground-muted opacity-60">
47 {field.label}
48 </Text>
49 <Text selectable className="text-2xs leading-4 text-foreground">
50 {field.value}
51 </Text>
52 </View>
53 ))}
54 </View>
55
56 {model.blocks.map((block) => (
57 <View key={`${block.label}:${block.value}`} className="gap-1">
58 <Text className="font-t3-medium text-3xs uppercase tracking-wide text-foreground-muted opacity-60">
59 {block.label}
60 </Text>
61 <ScrollView
62 nestedScrollEnabled
63 directionalLockEnabled
64 showsVerticalScrollIndicator
65 style={{ maxHeight: 240 }}
66 contentContainerStyle={{ paddingRight: 8 }}
67 >
68 <Text
69 selectable
70 className="text-2xs leading-[17px] text-foreground-muted"
71 style={block.monospaced ? { fontFamily: "ui-monospace" } : undefined}
72 >
73 {block.value}
74 </Text>
75 </ScrollView>
76 </View>
77 ))}
78
79 {model.fileLinks.length > 0 ? (
80 <View className="gap-1">
81 <Text className="font-t3-medium text-3xs uppercase tracking-wide text-foreground-muted opacity-60">
82 Files
83 </Text>
84 {model.fileLinks.map((link) => {
85 const relativePath =
86 resolveWorkspaceRelativeFilePath(props.workspaceRoot, link.path) ??
87 (link.path.startsWith("/") ? null : link.path);
88 return (
89 <Pressable
90 key={`${link.path}:${link.line ?? 0}:${link.label}`}
91 accessibilityRole={relativePath ? "link" : undefined}
92 disabled={relativePath === null}
93 onPress={() => {
94 if (!relativePath) return;
95 void Haptics.selectionAsync();
96 navigation.navigate(
97 "ThreadFile",
98 buildThreadActivityFileParams({
99 environmentId: props.environmentId,
100 currentThreadId: props.currentThreadId,
101 activitySourceThreadId: row.sourceThreadId,
102 relativePath,
103 line: link.line,
104 }),
105 );
106 }}
107 className="min-h-9 flex-row items-center gap-2 rounded-md border border-adaptive-neutral-300-a60-white-a12 px-2.5 py-1.5"
108 >
109 <SymbolView
110 name="doc.text"
111 size={13}
112 tintColor={props.iconColor}
113 type="monochrome"
114 />
115 <Text className="min-w-0 flex-1 text-2xs leading-4 text-foreground">
116 {link.label}
117 </Text>
118 </Pressable>
119 );
120 })}
121 </View>
122 ) : null}
123
124 {model.webLinks.length > 0 ? (
125 <View className="gap-1">
126 <Text className="font-t3-medium text-3xs uppercase tracking-wide text-foreground-muted opacity-60">
127 Sources
128 </Text>
129 {model.webLinks.map((link) => (
130 <Pressable
131 key={link.url}
132 accessibilityRole="link"
133 onPress={() => void Linking.openURL(link.url)}
134 className="min-h-9 flex-row items-center gap-2 rounded-md border border-adaptive-neutral-300-a60-white-a12 px-2.5 py-1.5"
135 >
136 <SymbolView
137 name="arrow.up.right.square"
138 size={13}
139 tintColor={props.iconColor}
140 type="monochrome"
141 />
142 <Text className="min-w-0 flex-1 text-2xs leading-4 text-foreground">
143 {link.label}
144 </Text>
145 </Pressable>
146 ))}
147 </View>
148 ) : null}
149
150 {model.rollbackTarget ? (
151 <Pressable
152 accessibilityRole="button"
153 accessibilityLabel="Roll back to this checkpoint"
154 disabled={rollingBack}
155 onPress={() => {
156 setRollingBack(true);
157 void Haptics.selectionAsync();
158 void revertCheckpoint({
159 environmentId: props.environmentId,
160 input: {
161 threadId: model.rollbackTarget!.threadId,
162 checkpointId: model.rollbackTarget!.checkpointId,
163 scopeId: model.rollbackTarget!.scopeId,
164 },
165 }).finally(() => setRollingBack(false));
166 }}
167 className="min-h-10 flex-row items-center justify-center gap-2 rounded-lg border border-adaptive-neutral-300-a60-white-a12 px-3 py-2"
168 >
169 <SymbolView
170 name={rollingBack ? "hourglass" : "arrow.counterclockwise"}
171 size={14}
172 tintColor={props.iconColor}
173 type="monochrome"
174 />
175 <Text className="font-t3-medium text-xs text-foreground">
176 {rollingBack ? "Rolling back…" : "Roll back to checkpoint"}
177 </Text>
178 </Pressable>
179 ) : null}
180
181 <View className="gap-1 border-t border-adaptive-neutral-300-a60-white-a12 pt-2">
182 <Text className="font-t3-medium text-3xs uppercase tracking-wide text-foreground-muted opacity-60">
183 Structured details
184 </Text>
185 <ScrollView
186 nestedScrollEnabled
187 directionalLockEnabled
188 showsVerticalScrollIndicator
189 style={{ maxHeight: 280 }}
190 contentContainerStyle={{ paddingRight: 8 }}
191 >
192 <Text
193 selectable
194 className="text-2xs leading-[17px] text-foreground-muted"
195 style={{ fontFamily: "ui-monospace" }}
196 >
197 {model.structuredDetails}
198 </Text>
199 </ScrollView>
200 </View>
201 </View>
202 );
203}