(props: Props)
| 23 | } |
| 24 | |
| 25 | const AttachmentIcon = (props: Props) => { |
| 26 | const { attachment } = props; |
| 27 | const [previewImage, setPreviewImage] = useState<{ open: boolean; urls: string[]; index: number }>({ |
| 28 | open: false, |
| 29 | urls: [], |
| 30 | index: 0, |
| 31 | }); |
| 32 | const resourceType = getAttachmentType(attachment); |
| 33 | const attachmentUrl = getAttachmentUrl(attachment); |
| 34 | const className = cn("w-full h-auto", props.className); |
| 35 | const strokeWidth = props.strokeWidth; |
| 36 | |
| 37 | const previewResource = () => { |
| 38 | window.open(attachmentUrl); |
| 39 | }; |
| 40 | |
| 41 | const handleImageClick = () => { |
| 42 | setPreviewImage({ open: true, urls: [attachmentUrl], index: 0 }); |
| 43 | }; |
| 44 | |
| 45 | if (resourceType === "image/*") { |
| 46 | return ( |
| 47 | <> |
| 48 | <SquareDiv className={cn(className, "flex items-center justify-center overflow-clip")}> |
| 49 | <img |
| 50 | className="min-w-full min-h-full object-cover" |
| 51 | src={getAttachmentThumbnailUrl(attachment)} |
| 52 | onClick={handleImageClick} |
| 53 | onError={(e) => { |
| 54 | // Fallback to original image if thumbnail fails |
| 55 | const target = e.target as HTMLImageElement; |
| 56 | if (target.src.includes("?thumbnail=true")) { |
| 57 | console.warn("Thumbnail failed, falling back to original image:", attachmentUrl); |
| 58 | target.src = attachmentUrl; |
| 59 | } |
| 60 | }} |
| 61 | decoding="async" |
| 62 | loading="lazy" |
| 63 | /> |
| 64 | </SquareDiv> |
| 65 | |
| 66 | <PreviewImageDialog |
| 67 | open={previewImage.open} |
| 68 | onOpenChange={(open) => setPreviewImage((prev) => ({ ...prev, open }))} |
| 69 | imgUrls={previewImage.urls} |
| 70 | initialIndex={previewImage.index} |
| 71 | /> |
| 72 | </> |
| 73 | ); |
| 74 | } |
| 75 | |
| 76 | const getAttachmentIcon = () => { |
| 77 | switch (resourceType) { |
| 78 | case "video/*": |
| 79 | return <FileVideo2Icon strokeWidth={strokeWidth} className="w-full h-auto" />; |
| 80 | case "audio/*": |
| 81 | return <FileAudioIcon strokeWidth={strokeWidth} className="w-full h-auto" />; |
| 82 | case "text/*": |
nothing calls this directly
no test coverage detected