From be317fe8d9477fc666fca4cea13eb200a9ee7583 Mon Sep 17 00:00:00 2001 From: Gaagul Gigi Date: Wed, 18 Oct 2023 16:14:46 +0530 Subject: [PATCH 1/2] Fixed inconsistency with attachment previews --- src/components/Attachments/Attachment.jsx | 18 ++++---- src/components/Attachments/Preview.jsx | 54 +++++++++++++---------- src/components/Attachments/index.jsx | 27 +++++------- src/components/Attachments/utils.js | 34 ++++++++++++++ 4 files changed, 85 insertions(+), 48 deletions(-) diff --git a/src/components/Attachments/Attachment.jsx b/src/components/Attachments/Attachment.jsx index aae5595d..117e383d 100644 --- a/src/components/Attachments/Attachment.jsx +++ b/src/components/Attachments/Attachment.jsx @@ -19,7 +19,7 @@ import directUploadsApi from "apis/direct_uploads"; import { ATTACHMENT_OPTIONS } from "./constants"; import FileIcon from "./FileIcon"; -import { downloadFile } from "./utils"; +import { checkPreviewAvailability, downloadFile } from "./utils"; const { Menu, MenuItem } = Dropdown; @@ -113,6 +113,13 @@ const Attachment = ({ } }; + const handleAttachmentSelection = () => { + const contentType = attachment?.contentType; + const hasPreview = checkPreviewAvailability(contentType); + + hasPreview ? setSelectedAttachment(attachment) : handleDownload(); + }; + return ( <>
@@ -146,16 +153,11 @@ const Attachment = ({ <>
setSelectedAttachment(attachment)} + onClick={handleAttachmentSelection} > - setSelectedAttachment(attachment)} - > - {attachment.filename} - + {attachment.filename}
downloadFile(url, filename); const setPreview = () => { - switch (contentType.split("/")[0]) { - case "image": - return ; - case "video": - return