import { X } from "lucide-react"; import { useState } from "preact/hooks"; import { getBlueskyCdnLink } from "./appBskyEmbedImages"; export default function BlobLayout({ did, dollar_link: ref, mimeType, author_pds: pds, }: { did: string; dollar_link?: string; mimeType?: string; author_pds?: string; }) { if (mimeType === undefined || ref === undefined) return <>Unsupported blob type; if (mimeType?.includes("image")) { return ImageGridLayout({ images: [ { url: getBlueskyCdnLink(did, ref, "jpeg"), }, ], }); } if (pds == "") return `blob from ${did} with cid ${ref}`; return ( Download {mimeType} file at{" "} {pds?.replace("https://", "").replace("/", "")} ({ref}) ); } interface ImageInfo { url: string; alt?: string; } export const ImageGridLayout = ({ images }: { images: ImageInfo[] }) => { const [selectedImage, setSelectedImage] = useState(null); const imageCount = images.length; // Different grid layouts based on number of images const gridClassName = { 1: "grid-cols-2", 2: "grid-cols-2", 3: "grid-cols-2", 4: "grid-cols-2", }[Math.min(imageCount, 4)] || "grid-cols-2"; return ( <>
{images.map((image, i) => (
setSelectedImage(i)} > {image.alt 1 && "max-h-64"}`} style={{ aspectRatio: imageCount === 1 ? "" : "1/1", }} loading="lazy" />
))}
{selectedImage !== null && ( <> {/* Image Preview */}
setSelectedImage(null)} > {images[selectedImage].alt {images[selectedImage].alt && (
Alt text: {images[selectedImage].alt}
)}
)} ); };