@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
tsx 78 lines 2.6 KB
Raw
1 import type {
2 EnvironmentId,
3 UserInputAttachmentAnswerPayload,
4 UserInputAttachments,
5 } from "@t3tools/contracts";
6 import { Image } from "expo-image";
7 import { Pressable, View } from "react-native";
8 import { tryOpenExternalUrl } from "../../lib/openExternalUrl";
9 import { getQuestionAnswerText } from "@t3tools/client-runtime/work-log/user-input";
10 import { AppText as Text } from "../../components/ui/AppText";
11 import { assetImageSource } from "../../lib/assetImageSource";
12 import { useAssetUrl } from "../../state/assets";
13
14 function AnswerFile(props: {
15 environmentId: EnvironmentId;
16 attachment: UserInputAttachments[string][number];
17 }) {
18 const resource = { _tag: "attachment", attachmentId: props.attachment.id } as const;
19 const url = useAssetUrl(props.environmentId, resource);
20 return (
21 <Pressable
22 accessibilityRole="link"
23 accessibilityLabel={props.attachment.name}
24 disabled={!url}
25 onPress={() => {
26 if (url) void tryOpenExternalUrl(url);
27 }}
28 className="gap-1"
29 >
30 {props.attachment.type === "image" && url ? (
31 <Image
32 source={assetImageSource(props.environmentId, resource, url)}
33 cachePolicy="memory-disk"
34 style={{ width: 160, height: 96 }}
35 contentFit="contain"
36 />
37 ) : null}
38 <Text className="text-sm text-foreground underline">{props.attachment.name}</Text>
39 </Pressable>
40 );
41 }
42
43 export function QuestionAnswerHistory(props: {
44 environmentId: EnvironmentId;
45 answer: UserInputAttachmentAnswerPayload;
46 }) {
47 return (
48 <View className="gap-2">
49 {[
50 ...new Set([
51 ...Object.keys(props.answer.questionTextById ?? {}),
52 ...Object.keys(props.answer.answers),
53 ...Object.keys(props.answer.attachmentsByQuestionId),
54 ]),
55 ].map((questionId) => (
56 <View key={questionId} className="gap-1">
57 {props.answer.questionTextById?.[questionId] ? (
58 <Text className="text-sm text-foreground-muted">
59 {props.answer.questionTextById[questionId]}
60 </Text>
61 ) : null}
62 {getQuestionAnswerText(props.answer.answers[questionId]) ? (
63 <Text className="ml-3 text-sm text-foreground-muted">
64 {getQuestionAnswerText(props.answer.answers[questionId])}
65 </Text>
66 ) : null}
67 {(props.answer.attachmentsByQuestionId[questionId] ?? []).map((attachment) => (
68 <AnswerFile
69 key={attachment.id}
70 environmentId={props.environmentId}
71 attachment={attachment}
72 />
73 ))}
74 </View>
75 ))}
76 </View>
77 );
78 }