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