Skip to content

Commit 7b1360a

Browse files
committed
fix: regenerate image preview URL on image attachment removal when editing a message
1 parent 996ddf6 commit 7b1360a

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/components/Attachment/AttachmentContainer.tsx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -109,19 +109,19 @@ export const GalleryContainer = ({
109109
>([]);
110110

111111
useLayoutEffect(() => {
112-
if (
113-
imageElements.current &&
114-
imageElements.current.every((element) => !!element) &&
115-
imageAttachmentSizeHandler
116-
) {
117-
const newConfigurations: ImageAttachmentConfiguration[] = [];
118-
imageElements.current.forEach((element, i) => {
119-
const config = imageAttachmentSizeHandler(attachment.images[i], element);
120-
newConfigurations.push(config);
121-
});
122-
setAttachmentConfigurations(newConfigurations);
112+
if (!imageElements.current || !imageAttachmentSizeHandler) return;
113+
const newConfigurations: ImageAttachmentConfiguration[] = [];
114+
const nonNullImageElements = imageElements.current.filter((e) => !!e);
115+
if (nonNullImageElements.length < imageElements.current.length) {
116+
imageElements.current = nonNullImageElements;
123117
}
124-
}, [imageElements, imageAttachmentSizeHandler, attachment]);
118+
imageElements.current.forEach((element, i) => {
119+
if (!element) return;
120+
const config = imageAttachmentSizeHandler(attachment.images[i], element);
121+
newConfigurations.push(config);
122+
});
123+
setAttachmentConfigurations(newConfigurations);
124+
}, [imageAttachmentSizeHandler, attachment]);
125125

126126
const images = attachment.images.map((image, i) => ({
127127
...image,
@@ -130,7 +130,7 @@ export const GalleryContainer = ({
130130
attachment.images[i]?.image_url || attachment.images[i]?.thumb_url || '',
131131
),
132132
}));
133-
133+
console.log(images, imageElements, attachmentConfigurations);
134134
return (
135135
<AttachmentWithinContainer attachment={attachment} componentType='gallery'>
136136
<Gallery images={images || []} innerRefs={imageElements} key='gallery' />

0 commit comments

Comments
 (0)