in apps/chat/src/components/Chat/MessageAttachment.tsx [69:153]
__html: sanitize(attachment.data || ''),
}}
></span>
</div>
);
}
if (attachment.type === 'text/plain') {
return (
<div className="max-w-full overflow-hidden">
<span className="prose whitespace-pre-wrap text-sm">
{attachment.data}
</span>
</div>
);
}
if (attachment.type === 'text/markdown' || !attachment.type) {
return (
<ChatMDComponent
isShowResponseLoader={false}
content={attachment.data}
isInner={isInner}
/>
);
}
if (attachment.type === PLOTLY_CONTENT_TYPE) {
return (
<PlotlyComponent plotlyData={attachment.data as unknown as PlotParams} />
);
}
return null;
};
interface AttachmentUrlRendererProps {
attachmentUrl: string | undefined;
attachmentType: MIMEType;
}
const AttachmentUrlRenderer = ({
attachmentUrl,
attachmentType,
}: AttachmentUrlRendererProps) => {
if (!attachmentUrl) {
return null;
}
if (IMAGE_TYPES_SET.has(attachmentType)) {
return (
<img
src={attachmentUrl}
className="m-0 aspect-auto w-full"
alt="Attachment image"
/>
);
}
return null;
};
interface ChartAttachmentUrlRendererProps {
attachmentUrl: string | undefined;
}
const ChartAttachmentUrlRenderer = ({
attachmentUrl,
}: ChartAttachmentUrlRendererProps) => {
const dispatch = useAppDispatch();
const loadedCharts = useAppSelector(
ConversationsSelectors.selectLoadedCharts,
);
const chartLoading = useAppSelector(
ConversationsSelectors.selectChartLoading,
);
const chart = attachmentUrl
? loadedCharts.find((loadedChart) =>
loadedChart.url.endsWith(attachmentUrl),
)?.data
: undefined;
useEffect(() => {
if (attachmentUrl && !chart) {
dispatch(
ConversationsActions.getChartAttachment({