Open History to see the last commit
1import type {
2 EnvironmentId,
3 UserInputAttachmentAnswerPayload,
4 UserInputAttachments,
5} from "@t3tools/contracts";
6import { Image, Linking, Pressable, View } from "react-native";
7import { AppText as Text } from "../../components/AppText";
8import { useAssetUrl } from "../../state/assets";
9
10function AnswerFile(props: {
11 environmentId: EnvironmentId;
12 attachment: UserInputAttachments[string][number];
13}) {
14 const url = useAssetUrl(props.environmentId, {
15 _tag: "attachment",
16 attachmentId: props.attachment.id,
17 });
18 return (
19 <Pressable
20 accessibilityRole="link"
21 accessibilityLabel={props.attachment.name}
22 disabled={!url}
23 onPress={() => {
24 if (url) void Linking.openURL(url);
25 }}
26 className="gap-1"
27 >
28 {props.attachment.type === "image" && url ? (
29 <Image source={{ uri: url }} style={{ width: 160, height: 96 }} resizeMode="contain" />
30 ) : null}
31 <Text className="text-sm text-foreground underline">{props.attachment.name}</Text>
32 </Pressable>
33 );
34}
35
36export function QuestionAnswerHistory(props: {
37 environmentId: EnvironmentId;
38 answer: UserInputAttachmentAnswerPayload;
39}) {
40 return (
41 <View className="gap-2">
42 {[
43 ...new Set([
44 ...Object.keys(props.answer.answers),
45 ...Object.keys(props.answer.attachmentsByQuestionId),
46 ]),
47 ].map((questionId) => (
48 <View key={questionId} className="gap-1">
49 {props.answer.questionTextById?.[questionId] ? (
50 <Text className="text-sm text-foreground-muted">
51 {props.answer.questionTextById[questionId]}
52 </Text>
53 ) : null}
54 <Text className="text-sm text-foreground">
55 {[props.answer.answers[questionId]]
56 .flat()
57 .filter((value): value is string => typeof value === "string")
58 .join(", ")}
59 </Text>
60 {(props.answer.attachmentsByQuestionId[questionId] ?? []).map((attachment) => (
61 <AnswerFile
62 key={attachment.id}
63 environmentId={props.environmentId}
64 attachment={attachment}
65 />
66 ))}
67 </View>
68 ))}
69 </View>
70 );
71}