From 0846c1c710115f8324b1147fd570e99f43492581 Mon Sep 17 00:00:00 2001 From: AntonJames-Sistence Date: Wed, 28 Aug 2024 12:06:06 -0400 Subject: [PATCH] Add maxImageLength variable to enhance reusability and enable different breakpoints for masonry grid; apply minor style improvements for handling more than 3 images in the Masonry layout --- src/SessionMessages/SessionMessage/MessageFiles.tsx | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/SessionMessages/SessionMessage/MessageFiles.tsx b/src/SessionMessages/SessionMessage/MessageFiles.tsx index 5d281a5..863b3e8 100644 --- a/src/SessionMessages/SessionMessage/MessageFiles.tsx +++ b/src/SessionMessages/SessionMessage/MessageFiles.tsx @@ -38,10 +38,13 @@ export const MessageFiles: FC = ({ files, children }) => { } ); + const maxImageLength = 3; + const truncateImages = !expanded && imageFiles.length > maxImageLength; + // Renders the image files based on the current expansion state const renderImageFiles = (images: ConversationFile[]) => { - return !expanded && imageFiles.length > 3 - ? images.slice(0, 3).map((image, index) => ( + return truncateImages + ? images.slice(0, maxImageLength).map((image, index) => (
= ({ files, children }) => { alt={image.name} className="relative w-full h-full object-cover rounded-lg" /> - {index === 2 && ( + {index === maxImageLength - 1 && (
setExpanded(true)} > - +{(imageFiles.length - 3).toLocaleString()} + +{(imageFiles.length - maxImageLength).toLocaleString()}
)}
@@ -72,7 +75,7 @@ export const MessageFiles: FC = ({ files, children }) => {
{imageFiles.length > 0 && renderImageFiles(imageFiles)}