import { AppBskyEmbedImages } from "@atcute/client/lexicons"; import { X } from "lucide-react"; import { useState } from "preact/hooks"; export const getBlueskyCdnLink = ( did: string, cid: string, ext: string, type: string = "feed_fullsize", ) => { return `https://cdn.bsky.app/img/${type}/plain/${did}/${cid}@${ext}`; }; export const AppBskyEmbedImagesLayout = ({ did, images, }: { did: string; images: AppBskyEmbedImages.Image[]; }) => { const [selectedImage, setSelectedImage] = useState(null); const imageCount = images.length; // Different grid layouts based on number of images const gridClassName = { 1: "grid-cols-1", 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)} > 1 && "max-h-64"}`} style={{ aspectRatio: imageCount === 1 ? "" : "1/1", }} loading="lazy" />
))}
{selectedImage !== null && ( <> {/* Image Preview */}
setSelectedImage(null)} > {images[selectedImage].alt && (
Alt text: {images[selectedImage].alt}
)}
)} ); };