diff --git a/packages/react/src/views/AttachmentHandler/Attachment.js b/packages/react/src/views/AttachmentHandler/Attachment.js
index ec752e9bcd..5e36c911fb 100644
--- a/packages/react/src/views/AttachmentHandler/Attachment.js
+++ b/packages/react/src/views/AttachmentHandler/Attachment.js
@@ -34,14 +34,48 @@ const Attachment = ({ attachment, host, type, variantStyles = {}, msg }) => {
/>
);
}
- if (attachment && attachment.image_url) {
+ if (attachment && (attachment.image_url || attachment.title_link)) {
+ const url = attachment.image_url || attachment.title_link;
+
+ const isGif =
+ url &&
+ (url.toLowerCase().endsWith('.gif') ||
+ (attachment.image_type &&
+ attachment.image_type.toLowerCase() === 'image/gif') ||
+ (attachment.description &&
+ attachment.description.toLowerCase().includes('gif')));
+
+ const imageUrl = url.startsWith('http') ? url : host + url;
+
+ if (url && url.includes('/file-upload/')) {
+ const fullUrl = `${host}/file-upload/${url.split('/file-upload/')[1]}`;
+
+ return (
+
+ );
+ }
+
return (
);
}
diff --git a/packages/react/src/views/AttachmentHandler/ImageAttachment.js b/packages/react/src/views/AttachmentHandler/ImageAttachment.js
index 84516ce65a..decf64bb5d 100644
--- a/packages/react/src/views/AttachmentHandler/ImageAttachment.js
+++ b/packages/react/src/views/AttachmentHandler/ImageAttachment.js
@@ -5,6 +5,7 @@ import { Box, Avatar, useTheme } from '@embeddedchat/ui-elements';
import AttachmentMetadata from './AttachmentMetadata';
import ImageGallery from '../ImageGallery/ImageGallery';
import RCContext from '../../context/RCInstance';
+import { imageWrapper, imageStyles } from './ImageAttachment.styles';
const ImageAttachment = ({
attachment,
@@ -13,9 +14,12 @@ const ImageAttachment = ({
author,
variantStyles = {},
msg,
+ isGif = false,
}) => {
const { RCInstance } = useContext(RCContext);
const [showGallery, setShowGallery] = useState(false);
+ const [imageError, setImageError] = useState(false);
+
const getUserAvatarUrl = (icon) => {
const instanceHost = RCInstance.getHost();
const URL = `${instanceHost}${icon}`;
@@ -35,6 +39,20 @@ const ImageAttachment = ({
setIsExpanded((prevState) => !prevState);
};
+ const handleImageClick = (e) => {
+ if (isGif) {
+ e.stopPropagation();
+ return;
+ }
+ setShowGallery(true);
+ };
+
+ const handleKeyPress = (e) => {
+ if (e.key === 'Enter' || e.key === ' ') {
+ handleImageClick(e);
+ }
+ };
+
return (
@{authorName}
>
- ) : (
- ''
- )}
+ ) : null}
{isExpanded && (
- setShowGallery(true)}>
+
+ {imageError && (
+
+ Failed to load image. URL: {host + attachment.image_url}
+
+ )}
+
)}
{attachment.attachments &&
attachment.attachments.map((nestedAttachment, index) => (
setShowGallery(true)}
+ onKeyPress={(e) => {
+ if (e.key === 'Enter' || e.key === ' ') {
+ setShowGallery(true);
+ }
+ }}
css={[
css`
cursor: pointer;
@@ -148,9 +198,7 @@ const ImageAttachment = ({
@{nestedAttachment.author_name}
>
- ) : (
- ''
- )}
+ ) : null}
{showGallery && (
diff --git a/packages/react/src/views/AttachmentHandler/ImageAttachment.styles.js b/packages/react/src/views/AttachmentHandler/ImageAttachment.styles.js
new file mode 100644
index 0000000000..2382e62709
--- /dev/null
+++ b/packages/react/src/views/AttachmentHandler/ImageAttachment.styles.js
@@ -0,0 +1,21 @@
+import { css } from '@emotion/react';
+
+export const imageWrapper = ({ isGif, theme }) => css`
+ width: ${isGif ? '200px' : '300px'};
+ height: ${isGif ? '200px' : 'auto'};
+ overflow: hidden;
+ border-radius: inherit;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ background-color: ${theme.colors.surface};
+`;
+
+export const imageStyles = ({ isGif }) => ({
+ width: isGif ? '200px' : '100%',
+ height: isGif ? '200px' : 'auto',
+ maxHeight: isGif ? '200px' : '200px',
+ objectFit: isGif ? 'cover' : 'scale-down',
+ borderRadius: 'inherit',
+ imageRendering: isGif ? 'auto' : 'inherit',
+});