import type {
EnvironmentId,
UserInputAttachmentAnswerPayload,
UserInputAttachments,
} from "@t3tools/contracts";
import { Image, Linking, Pressable, View } from "react-native";
import { AppText as Text } from "../../components/AppText";
import { useAssetUrl } from "../../state/assets";
function AnswerFile(props: {
environmentId: EnvironmentId;
attachment: UserInputAttachments[string][number];
}) {
const url = useAssetUrl(props.environmentId, {
_tag: "attachment",
attachmentId: props.attachment.id,
});
return (
{
if (url) void Linking.openURL(url);
}}
className="gap-1"
>
{props.attachment.type === "image" && url ? (
) : null}
{props.attachment.name}
);
}
export function QuestionAnswerHistory(props: {
environmentId: EnvironmentId;
answer: UserInputAttachmentAnswerPayload;
}) {
return (
{[
...new Set([
...Object.keys(props.answer.answers),
...Object.keys(props.answer.attachmentsByQuestionId),
]),
].map((questionId) => (
{props.answer.questionTextById?.[questionId] ? (
{props.answer.questionTextById[questionId]}
) : null}
{[props.answer.answers[questionId]]
.flat()
.filter((value): value is string => typeof value === "string")
.join(", ")}
{(props.answer.attachmentsByQuestionId[questionId] ?? []).map((attachment) => (
))}
))}
);
}