import type {
EnvironmentId,
UserInputAttachmentAnswerPayload,
UserInputAttachments,
} from "@t3tools/contracts";
import { Image, Linking, Pressable, View } from "react-native";
import { getQuestionAnswerText } from "@t3tools/client-runtime/work-log/user-input";
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.questionTextById ?? {}),
...Object.keys(props.answer.answers),
...Object.keys(props.answer.attachmentsByQuestionId),
]),
].map((questionId) => (
{props.answer.questionTextById?.[questionId] ? (
{props.answer.questionTextById[questionId]}
) : null}
{getQuestionAnswerText(props.answer.answers[questionId]) ? (
{getQuestionAnswerText(props.answer.answers[questionId])}
) : null}
{(props.answer.attachmentsByQuestionId[questionId] ?? []).map((attachment) => (
))}
))}
);
}