MCPcopy Create free account
hub / github.com/developersdigest/llm-answer-engine / ImagesComponent

Function ImagesComponent

components/answer/ImagesComponent.tsx:33–154  ·  view source on GitHub ↗
({ images })

Source from the content-addressed store, hash-verified

31}
32
33const ImagesComponent: React.FC<ImagesComponentProps> = ({ images }) => {
34 const [loadedImages, setLoadedImages] = useState<boolean[]>([]);
35 const [isOpen, setIsOpen] = useState(false);
36 const [photoIndex, setPhotoIndex] = useState(0);
37
38 useEffect(() => {
39 setLoadedImages(Array(images.length).fill(false));
40 }, [images]);
41
42 const handleImageLoad = (index: number) => {
43 setLoadedImages((prevLoadedImages) => {
44 const updatedLoadedImages = [...prevLoadedImages];
45 updatedLoadedImages[index] = true;
46 return updatedLoadedImages;
47 });
48 };
49
50 const ImagesSkeleton = () => (
51 <div className="w-full p-1 ">
52 <div className="w-full overflow-hidden aspect-video mt-5">
53 <div className="w-full h-full bg-gray-300 dark:bg-gray-700 rounded animate-pulse"></div>
54 </div>
55 </div>
56 );
57
58 const currentImage = images[photoIndex];
59
60 return (
61 <div className="bg-white dark:bg-gray-800 shadow-lg rounded-lg mt-4 w-full px-2 flex items-center justify-center">
62 <Carousel
63 plugins={[
64 Autoplay({
65 delay: 2000,
66 }),
67 ]}
68 opts={{
69 align: "start",
70 }}
71 orientation="vertical"
72 className="w-full max-w-xs"
73 >
74 <CarouselContent className="h-[175px]">
75 {images.length === 0 ? (
76 <ImagesSkeleton />
77 ) : (
78 images.map((image, index) => (
79 <CarouselItem key={image.link} className="py-5 md:basis-1/2">
80 <div className="p-1">
81 <Card>
82 <CardContent className="flex items-center justify-center p-0 h-[150px]">
83 <div
84 className="relative w-full h-full cursor-pointer"
85 onClick={() => {
86 setPhotoIndex(index);
87 setIsOpen(true);
88 }}
89 >
90 {!loadedImages[index] && (

Callers

nothing calls this directly

Calls 1

handleImageLoadFunction · 0.70

Tested by

no test coverage detected