diff --git a/src/components/ImageGallery/ImageGalleryListView.jsx b/src/components/ImageGallery/ImageGalleryListView.jsx index 157fbafa..3d16ff6c 100644 --- a/src/components/ImageGallery/ImageGalleryListView.jsx +++ b/src/components/ImageGallery/ImageGalleryListView.jsx @@ -1,4 +1,4 @@ -import React, { useRef, useState, useCallback } from "react"; +import React, { useRef, useState, useCallback, useEffect } from "react"; import Avatar from "../../components/common/Avatar"; import ImagePopup from "./ImagePopup"; @@ -14,8 +14,23 @@ const ImageGalleryListView = ({ moment, }) => { const [hoveredImage, setHoveredImage] = useState(null); + const [scrollThreshold, setScrollThreshold] = useState(5); const imageGroupRefs = useRef({}); + useEffect(() => { + const updateThreshold = () => { + if (window.innerWidth >= 1400) setScrollThreshold(6); // xl screens + else if (window.innerWidth >= 992) setScrollThreshold(5); // lg + else if (window.innerWidth >= 768) setScrollThreshold(4); // md + else setScrollThreshold(3); // sm & xs + }; + updateThreshold(); + window.addEventListener("resize", updateThreshold); + return () => window.removeEventListener("resize", updateThreshold); + }, []); + + + const scrollLeft = useCallback( (key) => imageGroupRefs.current[key]?.scrollBy({ left: -200, behavior: "smooth" }), @@ -37,11 +52,10 @@ const ImageGalleryListView = ({ ) : images.length ? ( images.map((batch) => { const doc = batch.documents[0]; - const userName = `${doc.uploadedBy?.firstName || ""} ${ - doc.uploadedBy?.lastName || "" - }`.trim(); + const userName = `${doc.uploadedBy?.firstName || ""} ${doc.uploadedBy?.lastName || "" + }`.trim(); const date = formatUTCToLocalTime(doc.uploadedAt); - const hasArrows = batch.documents.length > SCROLL_THRESHOLD; + const hasArrows = batch.documents.length > scrollThreshold; return (
diff --git a/src/components/ImageGallery/ImagePopup.jsx b/src/components/ImageGallery/ImagePopup.jsx index 9d773195..f197c778 100644 --- a/src/components/ImageGallery/ImagePopup.jsx +++ b/src/components/ImageGallery/ImagePopup.jsx @@ -1,90 +1,128 @@ import React, { useState, useEffect } from "react"; -import "./ImagePopup.css" import { useModal } from "./ModalContext"; -import moment from "moment"; import { formatUTCToLocalTime } from "../../utils/dateUtils"; const ImagePopup = ({ batch, initialIndex = 0 }) => { const { closeModal } = useModal(); const [currentIndex, setCurrentIndex] = useState(initialIndex); - // Effect to update currentIndex if the initialIndex prop changes useEffect(() => { setCurrentIndex(initialIndex); }, [initialIndex, batch]); - // If no batch or documents are provided, don't render if (!batch || !batch.documents || batch.documents.length === 0) return null; - // Get the current image document from the batch's documents array const image = batch.documents[currentIndex]; - - // Fallback if for some reason the image at the current index doesn't exist if (!image) return null; - // Format details for display from the individual image document const fullName = `${image.uploadedBy?.firstName || ""} ${image.uploadedBy?.lastName || "" }`.trim(); const date = formatUTCToLocalTime(image.uploadedAt); - // Location and category details from the 'batch' object (as previously corrected) const buildingName = batch.buildingName; const floorName = batch.floorName; const workAreaName = batch.workAreaName; const activityName = batch.activityName; const batchComment = batch.comment; - // Handler for navigating to the previous image const handlePrev = () => { setCurrentIndex((prevIndex) => Math.max(0, prevIndex - 1)); }; - // Handler for navigating to the next image const handleNext = () => { setCurrentIndex((prevIndex) => Math.min(batch.documents.length - 1, prevIndex + 1) ); }; - // Determine if previous/next buttons should be enabled/visible const hasPrev = currentIndex > 0; const hasNext = currentIndex < batch.documents.length - 1; return ( -
-
+
+
+
+ {/* Header */} +
+
Image Preview
+ +
- + {/* Body */} +
+
+ {hasPrev && ( + + )} - {hasPrev && ( - - )} + Preview -
- Preview -
+ {hasNext && ( + + )} +
- {hasNext && ( - - )} + {/* Details */} +
+

+ + Uploaded By: + {fullName} +

-
- -
Uploaded By : {fullName}
-
Date : {date}
-
Uploaded By : {buildingName} {floorName} - {workAreaName || "Unknown"} {activityName}
-
comment : {batchComment}
+

+ + Date: + {date} +

+

+ + Location: + + {buildingName} {floorName}{" "} + {workAreaName || "Unknown"}{" "} + {activityName} + +

+

+ + Comment: + {batchComment} +

+
+
); }; -export default ImagePopup; \ No newline at end of file +export default ImagePopup; diff --git a/src/pages/ImageGallery/ImageGalleryPage.jsx b/src/pages/ImageGallery/ImageGalleryPage.jsx index 46c6c86a..e5e9b52d 100644 --- a/src/pages/ImageGallery/ImageGalleryPage.jsx +++ b/src/pages/ImageGallery/ImageGalleryPage.jsx @@ -218,24 +218,50 @@ const ImageGalleryPage = () => { )}
+ {/* Filter Chips */} {/* Filter Chips */} {appliedFiltersChips.length > 0 && ( -
- Filters: - {appliedFiltersChips.map((chip, idx) => ( - - {chip.label} : {chip.value} -
+ ); + })} + + {/* Date Range */} + {appliedFiltersChips.some(c => c.label === "Date Range") && ( +
+ Date Range: + {appliedFiltersChips.filter(c => c.label === "Date Range").map((chip, idx) => ( + + {chip.value} +
+ )}
)} - {/* Gallery */} {isLoading ? (