chatbot-template/components/custom/preview-attachment.tsx

44 lines
1.2 KiB
TypeScript
Raw Normal View History

import { Attachment } from 'ai';
2024-10-11 18:00:22 +05:30
import { LoaderIcon } from './icons';
2024-10-11 18:00:22 +05:30
export const PreviewAttachment = ({
attachment,
isUploading = false,
}: {
attachment: Attachment;
isUploading?: boolean;
}) => {
const { name, url, contentType } = attachment;
return (
2024-11-07 01:14:11 +03:00
<div className="flex flex-col gap-2">
<div className="w-20 aspect-video bg-muted rounded-md relative flex flex-col items-center justify-center">
2024-10-11 18:00:22 +05:30
{contentType ? (
contentType.startsWith('image') ? (
2024-10-11 18:00:22 +05:30
// NOTE: it is recommended to use next/image for images
// eslint-disable-next-line @next/next/no-img-element
<img
2024-10-11 18:00:22 +05:30
key={url}
src={url}
alt={name ?? 'An image attachment'}
2024-10-11 18:00:22 +05:30
className="rounded-md size-full object-cover"
/>
2024-10-11 18:00:22 +05:30
) : (
<div className=""></div>
)
) : (
<div className=""></div>
)}
{isUploading && (
<div className="animate-spin absolute text-zinc-500">
<LoaderIcon />
</div>
)}
</div>
<div className="text-xs text-zinc-500 max-w-16 truncate">{name}</div>
</div>
2024-10-11 18:00:22 +05:30
);
};