import React, { useRef, useState, useCallback, useEffect } from "react"; import Avatar from "../../components/common/Avatar"; import ImagePopup from "./ImagePopup"; const ImageGalleryListView = ({ images, isLoading, isFetchingNextPage, hasNextPage, loaderRef, openModal, formatUTCToLocalTime, moment, }) => { const [hoveredImage, setHoveredImage] = useState(null); const [scrollThreshold, setScrollThreshold] = useState(5); const imageGroupRefs = useRef({}); useEffect(() => { const updateThreshold = () => { if (window.innerWidth >= 1400) setScrollThreshold(6); else if (window.innerWidth >= 992) setScrollThreshold(5); else if (window.innerWidth >= 768) setScrollThreshold(4); else setScrollThreshold(3); }; updateThreshold(); window.addEventListener("resize", updateThreshold); return () => window.removeEventListener("resize", updateThreshold); }, []); const scrollLeft = useCallback( (key) => imageGroupRefs.current[key]?.scrollBy({ left: -200, behavior: "smooth" }), [] ); const scrollRight = useCallback( (key) => imageGroupRefs.current[key]?.scrollBy({ left: 200, behavior: "smooth" }), [] ); if (!images.length && !isLoading) { return

No images match the selected filters.

; } return (
{images.map((batch) => { if (!batch.documents?.length) return null; // skip empty batches const doc = batch.documents[0]; const userName = `${doc.uploadedBy?.firstName || ""} ${doc.uploadedBy?.lastName || ""}`.trim(); const date = formatUTCToLocalTime(doc.uploadedAt); const hasArrows = batch.documents.length > scrollThreshold; return (
{userName} {date}
{batch.buildingName} {batch.floorName} {batch.workAreaName || "Unknown"} {batch.activityName}
{batch.workCategoryName && ( {batch.workCategoryName} )}
{hasArrows && ( )}
(imageGroupRefs.current[batch.batchId] = el)} > {batch.documents.map((d, i) => { const hoverDate = moment(d.uploadedAt).format("DD MMMM, YYYY"); const hoverTime = moment(d.uploadedAt).format("hh:mm A"); return (
openModal()} onMouseEnter={() => setHoveredImage(d)} onMouseLeave={() => setHoveredImage(null)} >
{`Image
{hoveredImage === d && (

Date: {hoverDate}

Time: {hoverTime}

Activity: {batch.activityName}

)}
); })}
{hasArrows && ( )}
); })}
{isFetchingNextPage && hasNextPage &&

Loading...

} {!hasNextPage && !isLoading && images.length > 0 && (

You've reached the end of the images.

)}
); }; export default ImageGalleryListView;