1- import type { ComponentType } from 'react' ;
1+ import { type ComponentType , useMemo } from 'react' ;
22import React from 'react' ;
33import {
44 isLocalAttachment ,
@@ -8,12 +8,12 @@ import {
88 isLocalVideoAttachment ,
99 isLocalVoiceRecordingAttachment ,
1010 isScrapedContent ,
11+ isVoiceRecordingAttachment ,
1112} from 'stream-chat' ;
1213import {
1314 UnsupportedAttachmentPreview as DefaultUnknownAttachmentPreview ,
1415 type UnsupportedAttachmentPreviewProps ,
1516} from './UnsupportedAttachmentPreview' ;
16- import { type VoiceRecordingPreviewProps } from './VoiceRecordingPreview' ;
1717import {
1818 FileAttachmentPreview as DefaultFileAttachmentPreview ,
1919 type FileAttachmentPreviewProps ,
@@ -40,7 +40,6 @@ export type AttachmentPreviewListProps = {
4040 ImageAttachmentPreview ?: ComponentType < ImageAttachmentPreviewProps > ;
4141 UnsupportedAttachmentPreview ?: ComponentType < UnsupportedAttachmentPreviewProps > ;
4242 VideoAttachmentPreview ?: ComponentType < MediaAttachmentPreviewProps > ;
43- VoiceRecordingPreview ?: ComponentType < VoiceRecordingPreviewProps > ;
4443} ;
4544
4645export const AttachmentPreviewList = ( {
@@ -50,21 +49,20 @@ export const AttachmentPreviewList = ({
5049 ImageAttachmentPreview = MediaAttachmentPreview ,
5150 UnsupportedAttachmentPreview = DefaultUnknownAttachmentPreview ,
5251 VideoAttachmentPreview = MediaAttachmentPreview ,
53- VoiceRecordingPreview = DefaultAudioAttachmentPreview ,
5452} : AttachmentPreviewListProps ) => {
5553 const messageComposer = useMessageComposer ( ) ;
5654
5755 // todo: we could also allow to attach poll to a message composition
5856 const { attachments, location } = useAttachmentsForPreview ( ) ;
57+ const filteredAttachments = useMemo (
58+ ( ) => attachments . filter ( ( a ) => ! isVoiceRecordingAttachment ( a ) ) ,
59+ [ attachments ] ,
60+ ) ;
5961
60- if ( ! attachments . length && ! location ) return null ;
62+ if ( ! filteredAttachments . length && ! location ) return null ;
6163
6264 return (
6365 < div className = 'str-chat__attachment-preview-list' >
64- { /*<div*/ }
65- { /* className='str-chat__attachment-list-scroll-container'*/ }
66- { /* data-testid='attachment-list-scroll-container'*/ }
67- { /*>*/ }
6866 { location && (
6967 < GeolocationPreview
7068 location = { location }
@@ -79,16 +77,9 @@ export const AttachmentPreviewList = ({
7977 ) }
8078 { attachments . map ( ( attachment ) => {
8179 if ( isScrapedContent ( attachment ) ) return null ;
82- if ( isLocalVoiceRecordingAttachment ( attachment ) ) {
83- return (
84- < VoiceRecordingPreview
85- attachment = { attachment }
86- handleRetry = { messageComposer . attachmentManager . uploadAttachment }
87- key = { attachment . localMetadata . id || attachment . asset_url }
88- removeAttachments = { messageComposer . attachmentManager . removeAttachments }
89- />
90- ) ;
91- } else if ( isLocalAudioAttachment ( attachment ) ) {
80+ // Voice recordings are rendered in the dedicated slot above (VoiceRecordingPreviewSlot)
81+ if ( isLocalVoiceRecordingAttachment ( attachment ) ) return null ;
82+ if ( isLocalAudioAttachment ( attachment ) ) {
9283 return (
9384 < AudioAttachmentPreview
9485 attachment = { attachment }
@@ -136,7 +127,6 @@ export const AttachmentPreviewList = ({
136127 }
137128 return null ;
138129 } ) }
139- { /*</div>*/ }
140130 </ div >
141131 ) ;
142132} ;
0 commit comments