-
Notifications
You must be signed in to change notification settings - Fork 298
Expand file tree
/
Copy pathVoiceRecordingPreviewSlot.tsx
More file actions
38 lines (34 loc) · 1.42 KB
/
VoiceRecordingPreviewSlot.tsx
File metadata and controls
38 lines (34 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import type { ComponentType } from 'react';
import React from 'react';
import { isLocalVoiceRecordingAttachment } from 'stream-chat';
import { useAttachmentsForPreview, useMessageComposer } from '../hooks';
import { AudioAttachmentPreview } from './AudioAttachmentPreview';
import type { VoiceRecordingPreviewProps } from './VoiceRecordingPreview';
export type VoiceRecordingPreviewSlotProps = {
/** Custom UI component for each voice recording preview in the slot; defaults to AudioAttachmentPreview */
VoiceRecordingPreview?: ComponentType<VoiceRecordingPreviewProps>;
};
/**
* Dedicated slot for voice recording preview(s), rendered apart from the main attachment preview list
*/
export const VoiceRecordingPreviewSlot = ({
VoiceRecordingPreview = AudioAttachmentPreview,
}: VoiceRecordingPreviewSlotProps) => {
const messageComposer = useMessageComposer();
const { attachments } = useAttachmentsForPreview();
const voiceAttachments = attachments.filter(isLocalVoiceRecordingAttachment);
const firstVoice = voiceAttachments[0];
if (!firstVoice) return null;
return (
<div
className='str-chat__message-composer-voice-preview-slot'
data-testid='voice-preview-slot'
>
<VoiceRecordingPreview
attachment={firstVoice}
handleRetry={messageComposer.attachmentManager.uploadAttachment}
removeAttachments={messageComposer.attachmentManager.removeAttachments}
/>
</div>
);
};