Skip to content

Commit

Permalink
fix: prevent showing link previews in AttachmentPreviewList
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinCupela committed May 22, 2024
1 parent 28b6dfd commit f805971
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
isLocalImageAttachment,
isLocalMediaAttachment,
isLocalVoiceRecordingAttachment,
isScrapedContent,
} from '../../Attachment';
import { useMessageInputContext } from '../../../context';

Expand Down Expand Up @@ -66,6 +67,7 @@ export const AttachmentPreviewList = <
data-testid='attachment-list-scroll-container'
>
{attachments.map((attachment) => {
if (isScrapedContent(attachment)) return null;
if (isLocalVoiceRecordingAttachment(attachment)) {
return (
<VoiceRecordingPreview
Expand Down
8 changes: 5 additions & 3 deletions src/components/MessageInput/MessageInputFlat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,11 @@ const MessageInputV2 = <
</div>
<div className='str-chat__message-textarea-container'>
{displayQuotedMessage && <QuotedMessagePreview quotedMessage={quotedMessage} />}
{isUploadEnabled && !!(numberOfUploads || attachments.length) && (
<AttachmentPreviewList />
)}
{isUploadEnabled &&
!!(
numberOfUploads ||
(attachments.length && attachments.length !== linkPreviews.size)
) && <AttachmentPreviewList />}

<div className='str-chat__message-textarea-with-emoji-picker'>
<ChatAutoComplete />
Expand Down
11 changes: 11 additions & 0 deletions src/components/MessageInput/__tests__/MessageInput.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,17 @@ function axeNoViolations(container) {
});
});

// todo: adjust tests once merged PR: feat: remove legacy style components #2394
it.todo('should show attachment previews if at least 1 file uploaded');
it.todo('should show attachment previews if at least one non-scraped attachments available');
it.todo('should not show scraped content in attachment previews');
it.todo(
'should not show attachment previews if no files uploaded and no attachments available',
);
it.todo(
'should not show attachment previews if no files uploaded and attachments available are only link previews',
);

// TODO: Check if pasting plaintext is not prevented -> tricky because recreating exact event is hard
// TODO: Remove image/file -> difficult because there is no easy selector and components are in react-file-utils
});
Expand Down

0 comments on commit f805971

Please sign in to comment.