From d3d054ad32551ce91198608d7a0a6d804eaa508d Mon Sep 17 00:00:00 2001 From: TerryM Date: Wed, 27 May 2026 13:37:14 +0800 Subject: [PATCH] Toggle lightbox captions on image click --- .../messageStream/overlays/ImageLightbox.tsx | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/components/messageStream/overlays/ImageLightbox.tsx b/src/components/messageStream/overlays/ImageLightbox.tsx index 7f48097..a9aaa3a 100644 --- a/src/components/messageStream/overlays/ImageLightbox.tsx +++ b/src/components/messageStream/overlays/ImageLightbox.tsx @@ -84,6 +84,7 @@ function LightboxView({ onClose: () => void; }) { const [index, setIndex] = useState(startIndex); + const [isCaptionVisible, setIsCaptionVisible] = useState(true); const touchStartX = useRef(null); const goPrev = useCallback( @@ -110,8 +111,13 @@ function LightboxView({ }; }, [goPrev, goNext, onClose]); + useEffect(() => { + setIsCaptionVisible(true); + }, [captionText, index]); + const current = images[index]; const caption = captionText?.trim(); + const showCaption = !!caption && isCaptionVisible; if (!current) return null; return createPortal( @@ -165,12 +171,15 @@ function LightboxView({
e.stopPropagation()} + className="flex h-full w-full items-center justify-center" + onClick={(e) => { + e.stopPropagation(); + if (caption) setIsCaptionVisible((visible) => !visible); + }} onTouchStart={(e) => { touchStartX.current = e.touches[0].clientX; }} @@ -187,13 +196,13 @@ function LightboxView({ {current.filename}
- {caption ? ( + {showCaption ? (
e.stopPropagation()}