Compare commits

..

No commits in common. "07373f618064007afff165b2c7774cabf3148309" and "cd23e43a82d8e987642778f4d9843d021f1aa1f9" have entirely different histories.

4 changed files with 369 additions and 436 deletions

View File

@ -2,115 +2,84 @@ import { useState, useCallback } from "react";
// import { ImageGalleryAPI } from "../repositories/ImageGalleyRepository"; // import { ImageGalleryAPI } from "../repositories/ImageGalleyRepository";
import { ImageGalleryAPI } from "../repositories/ImageGalleryAPI"; import { ImageGalleryAPI } from "../repositories/ImageGalleryAPI";
// const PAGE_SIZE = 10;
// const useImageGallery = (selectedProjectId) => {
// const [images, setImages] = useState([]);
// const [allImagesData, setAllImagesData] = useState([]);
// const [pageNumber, setPageNumber] = useState(1);
// const [hasMore, setHasMore] = useState(true);
// const [loading, setLoading] = useState(false);
// const [loadingMore, setLoadingMore] = useState(false);
// const fetchImages = useCallback(async (page = 1, filters = {}, reset = false) => {
// if (!selectedProjectId) return;
// try {
// if (page === 1) {
// setLoading(true);
// } else {
// setLoadingMore(true);
// }
// const res = await ImageGalleryAPI.ImagesGet(
// selectedProjectId,
// filters,
// page,
// PAGE_SIZE
// );
// const newBatches = res.data || [];
// const receivedCount = newBatches.length;
// setImages((prev) => {
// if (page === 1 || reset) return newBatches;
// const uniqueNew = newBatches.filter(
// (batch) => !prev.some((b) => b.batchId === batch.batchId)
// );
// return [...prev, ...uniqueNew];
// });
// setAllImagesData((prev) => {
// if (page === 1 || reset) return newBatches;
// const uniqueAll = newBatches.filter(
// (batch) => !prev.some((b) => b.batchId === batch.batchId)
// );
// return [...prev, ...uniqueAll];
// });
// setHasMore(receivedCount === PAGE_SIZE);
// } catch (error) {
// console.error("Error fetching images:", error);
// if (page === 1) {
// setImages([]);
// setAllImagesData([]);
// }
// setHasMore(false);
// } finally {
// setLoading(false);
// setLoadingMore(false);
// }
// }, [selectedProjectId]);
// const resetGallery = useCallback(() => {
// setImages([]);
// setAllImagesData([]);
// setPageNumber(1);
// setHasMore(true);
// }, []);
// return {
// images,
// allImagesData,
// pageNumber,
// setPageNumber,
// hasMore,
// loading,
// loadingMore,
// fetchImages,
// resetGallery,
// };
// };
// export default useImageGallery;
import { useInfiniteQuery } from "@tanstack/react-query";
const PAGE_SIZE = 10; const PAGE_SIZE = 10;
const useImageGallery = (selectedProjectId, filters) => { const useImageGallery = (selectedProjectId) => {
const hasFilters = filters && Object.values(filters).some( const [images, setImages] = useState([]);
value => Array.isArray(value) ? value.length > 0 : value !== null && value !== "" const [allImagesData, setAllImagesData] = useState([]);
); const [pageNumber, setPageNumber] = useState(1);
const [hasMore, setHasMore] = useState(true);
const [loading, setLoading] = useState(false);
const [loadingMore, setLoadingMore] = useState(false);
const fetchImages = useCallback(async (page = 1, filters = {}, reset = false) => {
if (!selectedProjectId) return;
try {
if (page === 1) {
setLoading(true);
} else {
setLoadingMore(true);
}
return useInfiniteQuery({
queryKey: ["imageGallery", selectedProjectId, hasFilters ? filters : null],
enabled: !!selectedProjectId,
getNextPageParam: (lastPage, allPages) => {
if (!lastPage?.data?.length) return undefined;
return allPages.length + 1;
},
queryFn: async ({ pageParam = 1 }) => {
const res = await ImageGalleryAPI.ImagesGet( const res = await ImageGalleryAPI.ImagesGet(
selectedProjectId, selectedProjectId,
hasFilters ? filters : undefined, filters,
pageParam, page,
PAGE_SIZE PAGE_SIZE
); );
return res;
}, const newBatches = res.data || [];
}); const receivedCount = newBatches.length;
setImages((prev) => {
if (page === 1 || reset) return newBatches;
const uniqueNew = newBatches.filter(
(batch) => !prev.some((b) => b.batchId === batch.batchId)
);
return [...prev, ...uniqueNew];
});
setAllImagesData((prev) => {
if (page === 1 || reset) return newBatches;
const uniqueAll = newBatches.filter(
(batch) => !prev.some((b) => b.batchId === batch.batchId)
);
return [...prev, ...uniqueAll];
});
setHasMore(receivedCount === PAGE_SIZE);
} catch (error) {
console.error("Error fetching images:", error);
if (page === 1) {
setImages([]);
setAllImagesData([]);
}
setHasMore(false);
} finally {
setLoading(false);
setLoadingMore(false);
}
}, [selectedProjectId]);
const resetGallery = useCallback(() => {
setImages([]);
setAllImagesData([]);
setPageNumber(1);
setHasMore(true);
}, []);
return {
images,
allImagesData,
pageNumber,
setPageNumber,
hasMore,
loading,
loadingMore,
fetchImages,
resetGallery,
};
}; };
export default useImageGallery; export default useImageGallery;

View File

@ -16,20 +16,32 @@ import { setProjectId } from "../../slices/localVariablesSlice";
const SCROLL_THRESHOLD = 5; const SCROLL_THRESHOLD = 5;
const ImageGallery = () => { const ImageGallery = () => {
const selectedProjectId = useSelector( const selectedProjectId = useSelector((store) => store.localVariables.projectId);
(store) => store.localVariables.projectId
);
const dispatch = useDispatch();
const { projectNames } = useProjectName();
// Auto-select a project on mount const dispatch = useDispatch()
const { projectNames, loading: projectLoading, fetchData } = useProjectName();
useEffect(() => { useEffect(() => {
if (!selectedProjectId && projectNames?.length) { if(selectedProjectId == null){
dispatch(setProjectId(projectNames[0].id)); dispatch(setProjectId(projectNames[0]?.id));
} }
}, [selectedProjectId, projectNames, dispatch]); },[])
const {
images,
allImagesData,
pageNumber,
setPageNumber,
hasMore,
loading,
loadingMore,
fetchImages,
resetGallery,
} = useImageGallery(selectedProjectId);
const { openModal } = useModal();
const yesterday = moment().subtract(1, 'days').format('YYYY-MM-DD');
// Filter states
const [selectedFilters, setSelectedFilters] = useState({ const [selectedFilters, setSelectedFilters] = useState({
building: [], building: [],
floor: [], floor: [],
@ -40,6 +52,7 @@ const ImageGallery = () => {
startDate: "", startDate: "",
endDate: "", endDate: "",
}); });
const [appliedFilters, setAppliedFilters] = useState({ const [appliedFilters, setAppliedFilters] = useState({
buildingIds: null, buildingIds: null,
floorIds: null, floorIds: null,
@ -50,6 +63,7 @@ const ImageGallery = () => {
startDate: null, startDate: null,
endDate: null, endDate: null,
}); });
const [collapsedFilters, setCollapsedFilters] = useState({ const [collapsedFilters, setCollapsedFilters] = useState({
dateRange: false, dateRange: false,
building: false, building: false,
@ -59,6 +73,7 @@ const ImageGallery = () => {
workCategory: false, workCategory: false,
workArea: false, workArea: false,
}); });
const [isFilterPanelOpen, setIsFilterPanelOpen] = useState(false); const [isFilterPanelOpen, setIsFilterPanelOpen] = useState(false);
const [hoveredImage, setHoveredImage] = useState(null); const [hoveredImage, setHoveredImage] = useState(null);
@ -66,113 +81,133 @@ const ImageGallery = () => {
const loaderRef = useRef(null); const loaderRef = useRef(null);
const filterPanelRef = useRef(null); const filterPanelRef = useRef(null);
const filterButtonRef = useRef(null); const filterButtonRef = useRef(null);
const { openModal } = useModal();
const {
data,
fetchNextPage,
hasNextPage,
isLoading,
isFetchingNextPage,
refetch,
} = useImageGallery(selectedProjectId, appliedFilters);
const images = data?.pages.flatMap((page) => page.data) || [];
useEffect(() => { useEffect(() => {
const handleClick = (e) => { const handleClickOutside = (event) => {
if ( if (
filterPanelRef.current && filterPanelRef.current &&
!filterPanelRef.current.contains(e.target) && !filterPanelRef.current.contains(event.target) &&
filterButtonRef.current && filterButtonRef.current &&
!filterButtonRef.current.contains(e.target) !filterButtonRef.current.contains(event.target)
) { ) {
setIsFilterPanelOpen(false); setIsFilterPanelOpen(false);
} }
}; };
document.addEventListener("mousedown", handleClick);
return () => document.removeEventListener("mousedown", handleClick);
}, []);
useEffect(() => { if (isFilterPanelOpen) {
if (selectedProjectId) refetch(); document.addEventListener("mousedown", handleClickOutside);
}, [selectedProjectId, appliedFilters, refetch]); } else {
document.removeEventListener("mousedown", handleClickOutside);
useEffect(() => {
const handler = (data) => {
if (data.projectId === selectedProjectId) refetch();
};
eventBus.on("image_gallery", handler);
return () => eventBus.off("image_gallery", handler);
}, [selectedProjectId, refetch]);
useEffect(() => {
if (!loaderRef.current) return;
const observer = new IntersectionObserver(
([entry]) => {
if (entry.isIntersecting && hasNextPage && !isFetchingNextPage && !isLoading) {
fetchNextPage();
}
},
{ rootMargin: "200px", threshold: 0.1 }
);
observer.observe(loaderRef.current);
return () => {
if (loaderRef.current) {
observer.unobserve(loaderRef.current);
} }
};
}, [hasNextPage, isFetchingNextPage, isLoading, fetchNextPage]);
return () => {
document.removeEventListener("mousedown", handleClickOutside);
};
}, [isFilterPanelOpen]);
// Utility: derive filter options useEffect(() => {
const getUniqueValues = useCallback( if (!selectedProjectId) {
(idKey, nameKey) => { resetGallery();
const m = new Map(); return;
images.forEach((batch) => { }
const id = idKey === "floorIds" ? batch.floorIds : batch[idKey];
if (id && batch[nameKey] && !m.has(id)) { resetGallery();
m.set(id, batch[nameKey]); fetchImages(1, appliedFilters, true);
}, [selectedProjectId, appliedFilters]);
useEffect(() => {
const handleExternalEvent = (data) => {
if (selectedProjectId === data.projectId) {
resetGallery();
fetchImages(1, appliedFilters, true);
}
};
eventBus.on("image_gallery", handleExternalEvent);
return () => {
eventBus.off("image_gallery", handleExternalEvent);
};
}, [appliedFilters, fetchImages, selectedProjectId]);
useEffect(() => {
if (!loaderRef.current) return;
const observer = new IntersectionObserver(
(entries) => {
if (entries[0].isIntersecting && hasMore && !loadingMore && !loading) {
setPageNumber((prevPageNumber) => prevPageNumber + 1);
} }
}); },
return [...m.entries()].sort((a, b) => a[1].localeCompare(b[1])); {
}, root: null,
[images] rootMargin: "200px",
); threshold: 0.1,
}
);
const getUploadedBy = useCallback(() => { observer.observe(loaderRef.current);
const m = new Map();
images.forEach((batch) => { return () => {
batch.documents.forEach((doc) => { if (loaderRef.current) {
const name = `${doc.uploadedBy?.firstName || ""} ${ observer.unobserve(loaderRef.current);
doc.uploadedBy?.lastName || "" }
}`.trim(); };
if (doc.uploadedBy?.id && name && !m.has(doc.uploadedBy.id)) { }, [hasMore, loadingMore, loading]);
m.set(doc.uploadedBy.id, name);
useEffect(() => {
if (pageNumber > 1) {
fetchImages(pageNumber, appliedFilters);
}
}, [pageNumber]);
const getUniqueValuesWithIds = useCallback((idKey, nameKey) => {
const map = new Map();
allImagesData.forEach(batch => {
let id = idKey === "floorIds" ? batch.floorIds : batch[idKey];
const name = batch[nameKey];
if (id && name && !map.has(id)) {
map.set(id, name);
}
});
return Array.from(map.entries()).sort((a, b) => a[1].localeCompare(b[1]));
}, [allImagesData]);
const getUniqueUploadedByUsers = useCallback(() => {
const uniqueUsersMap = new Map();
allImagesData.forEach(batch => {
batch.documents.forEach(doc => {
if (doc.uploadedBy && doc.uploadedBy.id) {
const fullName = `${doc.uploadedBy.firstName || ""} ${doc.uploadedBy.lastName || ""}`.trim();
if (fullName) {
uniqueUsersMap.set(doc.uploadedBy.id, fullName);
}
} }
}); });
}); });
return [...m.entries()].sort((a, b) => a[1].localeCompare(b[1])); return Array.from(uniqueUsersMap.entries()).sort((a, b) => a[1].localeCompare(b[1]));
}, [images]); }, [allImagesData]);
const buildings = getUniqueValues("buildingId", "buildingName"); const buildings = getUniqueValuesWithIds("buildingId", "buildingName");
const floors = getUniqueValues("floorIds", "floorName"); const floors = getUniqueValuesWithIds("floorIds", "floorName");
const activities = getUniqueValues("activityId", "activityName"); const activities = getUniqueValuesWithIds("activityId", "activityName");
const workAreas = getUniqueValues("workAreaId", "workAreaName"); const workAreas = getUniqueValuesWithIds("workAreaId", "workAreaName");
const workCategories = getUniqueValues("workCategoryId", "workCategoryName"); const uploadedByUsers = getUniqueUploadedByUsers();
const uploadedByUsers = getUploadedBy(); const workCategories = getUniqueValuesWithIds("workCategoryId", "workCategoryName");
const toggleFilter = useCallback((type, id, name) => { const toggleFilter = useCallback((type, itemId, itemName) => {
setSelectedFilters((prev) => { setSelectedFilters((prev) => {
const arr = prev[type]; const current = prev[type];
const exists = arr.some(([x]) => x === id); const isSelected = current.some((item) => item[0] === itemId);
const updated = exists
? arr.filter(([x]) => x !== id) const newArray = isSelected
: [...arr, [id, name]]; ? current.filter((item) => item[0] !== itemId)
return { ...prev, [type]: updated }; : [...current, [itemId, itemName]];
return {
...prev,
[type]: newArray,
};
}); });
}, []); }, []);
@ -185,33 +220,48 @@ useEffect(() => {
}, []); }, []);
const toggleCollapse = useCallback((type) => { const toggleCollapse = useCallback((type) => {
setCollapsedFilters((prev) => ({ ...prev, [type]: !prev[type] })); setCollapsedFilters((prev) => ({
...prev,
[type]: !prev[type],
}));
}, []); }, []);
const handleApplyFilters = useCallback(() => { const handleApplyFilters = useCallback(() => {
const payload = { const payload = {
buildingIds: selectedFilters.building.map(([x]) => x) || null, buildingIds: selectedFilters.building.length ? selectedFilters.building.map((item) => item[0]) : null,
floorIds: selectedFilters.floor.map(([x]) => x) || null, floorIds: selectedFilters.floor.length ? selectedFilters.floor.map((item) => item[0]) : null,
activityIds: selectedFilters.activity.map(([x]) => x) || null, workAreaIds: selectedFilters.workArea.length ? selectedFilters.workArea.map((item) => item[0]) : null,
uploadedByIds: selectedFilters.uploadedBy.map(([x]) => x) || null, workCategoryIds: selectedFilters.workCategory.length ? selectedFilters.workCategory.map((item) => item[0]) : null,
workCategoryIds: selectedFilters.workCategory.map(([x]) => x) || null, activityIds: selectedFilters.activity.length ? selectedFilters.activity.map((item) => item[0]) : null,
workAreaIds: selectedFilters.workArea.map(([x]) => x) || null, uploadedByIds: selectedFilters.uploadedBy.length ? selectedFilters.uploadedBy.map((item) => item[0]) : null,
startDate: selectedFilters.startDate || null, startDate: selectedFilters.startDate || null,
endDate: selectedFilters.endDate || null, endDate: selectedFilters.endDate || null,
}; };
const changed = Object.keys(payload).some((key) => {
const oldVal = appliedFilters[key], const areFiltersChanged = Object.keys(payload).some(key => {
newVal = payload[key]; const oldVal = appliedFilters[key];
return Array.isArray(oldVal) const newVal = payload[key];
? oldVal.length !== newVal.length || if (Array.isArray(oldVal) && Array.isArray(newVal)) {
oldVal.some((x) => !newVal.includes(x)) if (oldVal.length !== newVal.length) return true;
: oldVal !== newVal; const oldSet = new Set(oldVal);
const newSet = new Set(newVal);
for (const item of newSet) {
if (!oldSet.has(item)) return true;
}
return false;
}
if ((oldVal === null && newVal === "") || (oldVal === "" && newVal === null)) return false;
return oldVal !== newVal;
}); });
if (changed) setAppliedFilters(payload);
if (areFiltersChanged) {
setAppliedFilters(payload);
resetGallery();
}
}, [selectedFilters, appliedFilters]); }, [selectedFilters, appliedFilters]);
const handleClear = useCallback(() => { const handleClearAllFilters = useCallback(() => {
setSelectedFilters({ const initialStateSelected = {
building: [], building: [],
floor: [], floor: [],
activity: [], activity: [],
@ -220,8 +270,10 @@ useEffect(() => {
workArea: [], workArea: [],
startDate: "", startDate: "",
endDate: "", endDate: "",
}); };
setAppliedFilters({ setSelectedFilters(initialStateSelected);
const initialStateApplied = {
buildingIds: null, buildingIds: null,
floorIds: null, floorIds: null,
activityIds: null, activityIds: null,
@ -230,70 +282,69 @@ useEffect(() => {
workAreaIds: null, workAreaIds: null,
startDate: null, startDate: null,
endDate: null, endDate: null,
}); };
setAppliedFilters(initialStateApplied);
resetGallery();
}, []); }, []);
const scrollLeft = useCallback( const scrollLeft = useCallback((key) => {
(key) => imageGroupRefs.current[key]?.scrollBy({ left: -200, behavior: "smooth" });
imageGroupRefs.current[key]?.scrollBy({ left: -200, behavior: "smooth" }), }, []);
[]
);
const scrollRight = useCallback(
(key) =>
imageGroupRefs.current[key]?.scrollBy({ left: 200, behavior: "smooth" }),
[]
);
const renderCategory = (label, items, type) => ( const scrollRight = useCallback((key) => {
<div imageGroupRefs.current[key]?.scrollBy({ left: 200, behavior: "smooth" });
className={`dropdown my-2 ${collapsedFilters[type] ? "collapsed" : ""}`} }, []);
>
<div const renderFilterCategory = (label, items, type) => (
className="dropdown-header bg-label-primary" <div className={`dropdown my-2 ${collapsedFilters[type] ? "collapsed" : ""}`}>
onClick={() => toggleCollapse(type)} <div className="dropdown-header bg-label-primary" onClick={() => toggleCollapse(type)}>
>
<strong>{label}</strong> <strong>{label}</strong>
<div className="header-controls"> <div className="header-controls">
{((type === "dateRange" && {type === "dateRange" && (selectedFilters.startDate || selectedFilters.endDate) && (
(selectedFilters.startDate || selectedFilters.endDate)) ||
(type !== "dateRange" && selectedFilters[type]?.length > 0)) && (
<button <button
className="clear-button" className="clear-button"
onClick={(e) => { onClick={(e) => {
e.stopPropagation(); e.stopPropagation();
setSelectedFilters((prev) => ({ setSelectedFilters((prev) => ({ ...prev, startDate: "", endDate: "" }));
...prev,
[type]: type === "dateRange" ? "" : [],
...(type === "dateRange" && { startDate: "", endDate: "" }),
}));
}} }}
> >
Clear Clear
</button> </button>
)} )}
<span className="collapse-icon"> {type !== "dateRange" && selectedFilters[type]?.length > 0 && (
{collapsedFilters[type] ? "+" : "-"} <button
</span> className="clear-button"
onClick={(e) => {
e.stopPropagation();
setSelectedFilters((prev) => ({ ...prev, [type]: [] }));
}}
>
Clear
</button>
)}
<span className="collapse-icon">{collapsedFilters[type] ? '+' : '-'}</span>
</div> </div>
</div> </div>
{!collapsedFilters[type] && ( {!collapsedFilters[type] && (
<div className="dropdown-content"> <div className="dropdown-content">
{type === "dateRange" ? ( {type === "dateRange" ? (
<DateRangePicker <div className="date-range-inputs">
onRangeChange={setDateRange} <DateRangePicker
endDateMode="today" onRangeChange={setDateRange}
startDate={selectedFilters.startDate} endDateMode="today"
endDate={selectedFilters.endDate} startDate={selectedFilters.startDate}
/> endDate={selectedFilters.endDate}
/>
</div>
) : ( ) : (
items.map(([id, name]) => ( items.map(([itemId, itemName]) => (
<label key={id}> <label key={itemId}>
<input <input
type="checkbox" type="checkbox"
checked={selectedFilters[type].some(([x]) => x === id)} checked={selectedFilters[type].some((item) => item[0] === itemId)}
onChange={() => toggleFilter(type, id, name)} onChange={() => toggleFilter(type, itemId, itemName)}
/> />
{name} {itemName}
</label> </label>
)) ))
)} )}
@ -303,193 +354,105 @@ useEffect(() => {
); );
return ( return (
<div <div className={`gallery-container container-fluid ${isFilterPanelOpen ? "filter-panel-open-end" : ""}`}>
className={`gallery-container container-fluid ${ <Breadcrumb data={[{ label: "Home", link: "/" }, { label: "Gallary", link: null }]} />
isFilterPanelOpen ? "filter-panel-open-end" : ""
}`}
>
<Breadcrumb data={[{ label: "Home", link: "/" }, { label: "Gallery" }]} />
<div className="main-content"> <div className="main-content">
<button <button
className={`filter-button btn-primary ${ className={`filter-button btn-primary ${isFilterPanelOpen ? "closed-icon" : ""}`}
isFilterPanelOpen ? "closed-icon" : "" onClick={() => setIsFilterPanelOpen(!isFilterPanelOpen)}
}`}
onClick={() => setIsFilterPanelOpen((p) => !p)}
ref={filterButtonRef} ref={filterButtonRef}
> >
{isFilterPanelOpen ? ( {isFilterPanelOpen ? <i className="fa-solid fa-times fs-5"></i> : <i className="fa-solid fa-filter ms-1 fs-5"></i>}
<i className="fa-solid fa-times fs-5" />
) : (
<i className="fa-solid fa-filter ms-1 fs-5" />
)}
</button> </button>
<div className="activity-section"> <div className="activity-section">
{isLoading ? ( {loading && pageNumber === 1 ? (
<div className="text-center"> <div className="spinner-container"><div className="spinner" /></div>
<p>Loading...</p> ) : images.length > 0 ? (
</div>
) : images.length ? (
images.map((batch) => { images.map((batch) => {
const doc = batch.documents[0]; const firstDoc = batch.documents[0];
const userName = `${doc.uploadedBy?.firstName || ""} ${ const userName = `${firstDoc?.uploadedBy?.firstName || ""} ${firstDoc?.uploadedBy?.lastName || ""}`.trim();
doc.uploadedBy?.lastName || "" const date = formatUTCToLocalTime(firstDoc?.uploadedAt);
}`.trim(); const showScrollButtons = batch.documents.length > SCROLL_THRESHOLD;
const date = formatUTCToLocalTime(doc.uploadedAt);
const hasArrows = batch.documents.length > SCROLL_THRESHOLD;
return ( return (
<div key={batch.batchId} className="grouped-section"> <div key={batch.batchId} className="grouped-section">
<div className="group-heading"> <div className="group-heading">
{/* Uploader Info */} <div className="d-flex flex-column">
<div className="d-flex align-items-center mb-1"> <div className="d-flex align-items-center mb-1">
<Avatar <Avatar size="xs" firstName={firstDoc?.uploadedBy?.firstName} lastName={firstDoc?.uploadedBy?.lastName} className="me-2" />
size="xs" <div className="d-flex flex-column align-items-start">
firstName={doc.uploadedBy?.firstName} <strong className="user-name-text">{userName}</strong>
lastName={doc.uploadedBy?.lastName} <span className="me-2">{date}</span>
className="me-2" </div>
/>
<div className="d-flex flex-column align-items-start">
<strong className="user-name-text">{userName}</strong>
<span className="text-muted small">{date}</span>
</div> </div>
</div> </div>
<div className="location-line">
{/* Location Info */} <div>{batch.buildingName} &gt; {batch.floorName} &gt; <strong>{batch.workAreaName || "Unknown"} &gt; {batch.activityName}</strong></div>
<div className="location-line text-secondary">
<div className="d-flex align-items-center flex-wrap gap-1 text-secondary">
{" "}
<span className="d-flex align-items-center">
<span>{batch.buildingName}</span>
<i className="bx bx-chevron-right " />
</span>
<span className="d-flex align-items-center">
<span>{batch.floorName}</span>
<i className="bx bx-chevron-right m" />
</span>
<span className="d-flex align-items-center ">
<span>{batch.workAreaName || "Unknown"}</span>
<i className="bx bx-chevron-right " />
<span>{batch.activityName}</span>
</span>
</div>
{batch.workCategoryName && ( {batch.workCategoryName && (
<span className="badge bg-label-primary ms-2"> <div className="work-category-display ms-2">
{batch.workCategoryName} <span className="badge bg-label-primary rounded-pill d-flex align-items-center gap-1">
</span> {batch.workCategoryName}
</span>
</div>
)} )}
</div> </div>
</div> </div>
<div className="image-group-wrapper"> <div className="image-group-wrapper">
{hasArrows && ( {showScrollButtons && <button className="scroll-arrow left-arrow" onClick={() => scrollLeft(batch.batchId)}>&#8249;</button>}
<button <div className="image-group-horizontal" ref={(el) => (imageGroupRefs.current[batch.batchId] = el)}>
className="scroll-arrow left-arrow" {batch.documents.map((doc, idx) => {
onClick={() => scrollLeft(batch.batchId)} const hoverDate = moment(doc.uploadedAt).format("DD-MM-YYYY");
> const hoverTime = moment(doc.uploadedAt).format("hh:mm A");
</button>
)}
<div
className="image-group-horizontal"
ref={(el) => (imageGroupRefs.current[batch.batchId] = el)}
>
{batch.documents.map((d, i) => {
const hoverDate = moment(d.uploadedAt).format(
"DD-MM-YYYY"
);
const hoverTime = moment(d.uploadedAt).format(
"hh:mm A"
);
return ( return (
<div <div key={doc.id} className="image-card" onClick={() => openModal(<ImagePop batch={batch} initialIndex={idx} />)} onMouseEnter={() => setHoveredImage(doc)} onMouseLeave={() => setHoveredImage(null)}>
key={d.id}
className="image-card"
onClick={() =>
openModal(
<ImagePop batch={batch} initialIndex={i} />
)
}
onMouseEnter={() => setHoveredImage(d)}
onMouseLeave={() => setHoveredImage(null)}
>
<div className="image-wrapper"> <div className="image-wrapper">
<img src={d.url} alt={`Image ${i + 1}`} /> <img src={doc.url} alt={`Image ${idx + 1}`} />
</div> </div>
{hoveredImage === d && ( {hoveredImage === doc && (
<div className="image-hover-description"> <div className="image-hover-description">
<p> <p><strong>Date:</strong> {hoverDate}</p>
<strong>Date:</strong> {hoverDate} <p><strong>Time:</strong> {hoverTime}</p>
</p> <p><strong>Activity:</strong> {batch.activityName}</p>
<p>
<strong>Time:</strong> {hoverTime}
</p>
<p>
<strong>Activity:</strong>{" "}
{batch.activityName}
</p>
</div> </div>
)} )}
</div> </div>
); );
})} })}
</div> </div>
{hasArrows && ( {showScrollButtons && <button className="scroll-arrow right-arrow" onClick={() => scrollRight(batch.batchId)}>&#8250;</button>}
<button
className="scroll-arrow right-arrow"
onClick={() => scrollRight(batch.batchId)}
>
<i className="bx bx-chevron-right"></i>
</button>
)}
</div> </div>
</div> </div>
); );
}) })
) : ( ) : (
<p className="text-center text-muted mt-5"> !loading && <p style={{ textAlign: "center", color: "#777", marginTop: "50px" }}>No images match the selected filters.</p>
No images match the selected filters.
</p>
)} )}
<div ref={loaderRef}> <div ref={loaderRef} style={{ height: '50px', margin: '20px 0', display: 'flex', justifyContent: 'center', alignItems: 'center' }}>
{isFetchingNextPage && hasNextPage && <p>Loading...</p>} {loadingMore && hasMore && <div className="spinner" />}
{!hasNextPage && !isLoading && images.length > 0 && ( {!hasMore && !loading && images.length > 0 && <p style={{ color: '#aaa' }}>You've reached the end of the images.</p>}
<p className="text-muted">
You've reached the end of the images.
</p>
)}
</div> </div>
</div> </div>
</div> </div>
<div <div className={`offcanvas offcanvas-end ${isFilterPanelOpen ? "show" : ""}`} tabIndex="-1" id="filterOffcanvas" aria-labelledby="filterOffcanvasLabel" ref={filterPanelRef}>
className={`offcanvas offcanvas-end ${isFilterPanelOpen ? "show" : ""}`}
ref={filterPanelRef}
>
<div className="offcanvas-header"> <div className="offcanvas-header">
<h5>Filters</h5> <h5 className="offcanvas-title" id="filterOffcanvasLabel">Filters</h5>
<button <button type="button" className="btn-close" onClick={() => setIsFilterPanelOpen(false)} aria-label="Close" />
className="btn-close"
onClick={() => setIsFilterPanelOpen(false)}
/>
</div> </div>
<div className="filter-actions mt-auto mx-2"> <div className="filter-actions mt-auto mx-2">
<button className="btn btn-secondary btn-xs" onClick={handleClear}> <button className="btn btn-secondary btn-xs" onClick={handleClearAllFilters}>Clear All</button>
Clear All <button className="btn btn-primary btn-xs" onClick={handleApplyFilters}>Apply Filters</button>
</button>
<button
className="btn btn-primary btn-xs"
onClick={handleApplyFilters}
>
Apply Filters
</button>
</div> </div>
<div className="offcanvas-body d-flex flex-column"> <div className="offcanvas-body d-flex flex-column">
{renderCategory("Date Range", [], "dateRange")} {renderFilterCategory("Date Range", [], "dateRange")}
{renderCategory("Building", buildings, "building")} {renderFilterCategory("Building", buildings, "building")}
{renderCategory("Floor", floors, "floor")} {renderFilterCategory("Floor", floors, "floor")}
{renderCategory("Work Area", workAreas, "workArea")} {renderFilterCategory("Work Area", workAreas, "workArea")}
{renderCategory("Activity", activities, "activity")} {renderFilterCategory("Activity", activities, "activity")}
{renderCategory("Uploaded By (User)", uploadedByUsers, "uploadedBy")} {renderFilterCategory("Uploaded By (User)", uploadedByUsers, "uploadedBy")}
{renderCategory("Work Category", workCategories, "workCategory")} {renderFilterCategory("Work Category", workCategories, "workCategory")}
</div> </div>
</div> </div>
</div> </div>

View File

@ -42,23 +42,14 @@
} }
/* Image Styles */ /* Image Styles */
.image-container {
aspect-ratio: 1 / 1; /* Square shape: width and height are equal */
width: 100%; /* or set a fixed width like 300px */
max-width: 400px; /* Optional: limit how large it grows */
border-radius: 10px;
overflow: hidden;
display: flex;
justify-content: center;
align-items: center;
background-color: #f5f5f5;
}
.modal-image { .modal-image {
width: 100%; max-width: 100%;
height: 100%; max-height: 70vh;
object-fit: cover; width: auto;
border-radius: 10px;
object-fit: contain;
margin-bottom: 20px;
flex-shrink: 0;
} }
/* Scrollable Container for Text Details */ /* Scrollable Container for Text Details */

View File

@ -54,34 +54,44 @@ const ImagePop = ({ batch, initialIndex = 0 }) => {
return ( return (
<div className="image-modal-overlay"> <div className="image-modal-overlay">
<div className="image-modal-content"> <div className="image-modal-content">
{/* Close button */}
<i className='bx bx-x close-button' onClick={closeModal}></i> <button className="close-button" onClick={closeModal}>
×
</button>
{/* Previous button, only shown if there's a previous image */}
{hasPrev && ( {hasPrev && (
<button className="nav-button prev-button" onClick={handlePrev}> <button className="nav-button prev-button" onClick={handlePrev}>
<i className='bx bx-chevron-left'></i> &#8249; {/* Unicode for single left angle quotation mark */}
</button> </button>
)} )}
<div className="image-container"> {/* The main image display */}
<img src={image.url} alt="Preview" className="modal-image" /> <img src={image.url} alt="Preview" className="modal-image" />
</div>
{/* Next button, only shown if there's a next image */}
{hasNext && ( {hasNext && (
<button className="nav-button next-button" onClick={handleNext}> <button className="nav-button next-button" onClick={handleNext}>
<i className='bx bx-chevron-right'></i> &#8250; {/* Unicode for single right angle quotation mark */}
</button> </button>
)} )}
{/* Image details */}
<div className="image-details"> <div className="image-details">
<p>
<div className="flex alig-items-center"> <i className='bx bxs-user'></i> <span className="text-muted">Uploaded By : </span> <span className="text-secondary">{fullName}</span></div> <strong>👤 Uploaded By:</strong> {fullName}
<div className="flex alig-items-center"> <i class='bx bxs-calendar' ></i> <span className="text-muted">Date : </span> <span className="text-secondary"> {date}</span></div> </p>
<div className="flex alig-items-center"> <i class='bx bx-map' ></i> <span className="text-muted">Uploaded By : </span> <span className="text-secondary">{buildingName} <i className='bx bx-chevron-right'></i> {floorName} <i className='bx bx-chevron-right'></i> <p>
{workAreaName || "Unknown"} <i className='bx bx-chevron-right'></i> {activityName}</span></div> <strong>📅 Date:</strong> {date}
<div className="flex alig-items-center"> <i className='bx bx-comment-dots'></i> <span className="text-muted">comment : </span> <span className="text-secondary">{batchComment}</span></div> </p>
<p>
<strong>🏢 Location:</strong> {buildingName} &gt; {floorName} &gt;{" "}
{workAreaName || "Unknown"} &gt; {activityName}
</p>
<p>
{/* Display the comment from the batch object */}
<strong>📝 Comments:</strong> {batchComment || "N/A"}
</p>
</div> </div>
</div> </div>
</div> </div>