import { memo } from "react"; import { cn } from "@/lib/utils"; import { Attachment } from "@/types/proto/api/v1/attachment_service"; import { getAttachmentType, getAttachmentUrl } from "@/utils/attachment"; import MemoAttachment from "./MemoAttachment"; import showPreviewImageDialog from "./PreviewImageDialog"; const MemoAttachmentListView = ({ attachments = [] }: { attachments: Attachment[] }) => { const mediaAttachments: Attachment[] = []; const otherAttachments: Attachment[] = []; attachments.forEach((attachment) => { const type = getAttachmentType(attachment); if (type === "image/*" || type === "video/*") { mediaAttachments.push(attachment); return; } otherAttachments.push(attachment); }); const handleImageClick = (imgUrl: string) => { const imgUrls = mediaAttachments .filter((attachment) => getAttachmentType(attachment) === "image/*") .map((attachment) => getAttachmentUrl(attachment)); const index = imgUrls.findIndex((url) => url === imgUrl); showPreviewImageDialog(imgUrls, index); }; const MediaCard = ({ attachment, className }: { attachment: Attachment; className?: string }) => { const type = getAttachmentType(attachment); const attachmentUrl = getAttachmentUrl(attachment); if (type === "image/*") { return ( handleImageClick(attachmentUrl)} decoding="async" loading="lazy" /> ); } else if (type === "video/*") { return (