stream-chat-react
Version:
React components to create chat conversations or livestream style chat
29 lines (28 loc) • 2.59 kB
JavaScript
import React from 'react';
import { PlayButton } from '../../Attachment';
import { RecordingTimer } from '../../MediaRecorder';
import { CloseIcon, LoadingIndicatorIcon, RetryIcon } from '../icons';
import { FileIcon } from '../../ReactFileUtilities';
import { useAudioController } from '../../Attachment/hooks/useAudioController';
import { useTranslationContext } from '../../../context';
export const VoiceRecordingPreview = ({ attachment, handleRetry, removeAttachments, }) => {
const { t } = useTranslationContext();
const { audioRef, isPlaying, secondsElapsed, togglePlay } = useAudioController({
mimeType: attachment.mime_type,
});
return (React.createElement("div", { className: 'str-chat__attachment-preview-voice-recording', "data-testid": 'attachment-preview-voice-recording' },
React.createElement("audio", { ref: audioRef },
React.createElement("source", { "data-testid": 'audio-source', src: attachment.asset_url, type: attachment.mime_type })),
React.createElement(PlayButton, { isPlaying: isPlaying, onClick: togglePlay }),
React.createElement("button", { "aria-label": t('aria/Remove attachment'), className: 'str-chat__attachment-preview-delete', "data-testid": 'file-preview-item-delete-button', disabled: attachment.localMetadata?.uploadState === 'uploading', onClick: () => attachment.localMetadata?.id && removeAttachments([attachment.localMetadata.id]) },
React.createElement(CloseIcon, null)),
['blocked', 'failed'].includes(attachment.localMetadata?.uploadState) &&
!!handleRetry && (React.createElement("button", { className: 'str-chat__attachment-preview-error str-chat__attachment-preview-error-file', "data-testid": 'file-preview-item-retry-button', onClick: () => handleRetry(attachment) },
React.createElement(RetryIcon, null))),
React.createElement("div", { className: 'str-chat__attachment-preview-metadata' },
React.createElement("div", { className: 'str-chat__attachment-preview-file-name', title: attachment.title }, attachment.title),
typeof attachment.duration !== 'undefined' && (React.createElement(RecordingTimer, { durationSeconds: secondsElapsed || attachment.duration })),
attachment.localMetadata?.uploadState === 'uploading' && (React.createElement(LoadingIndicatorIcon, { size: 17 }))),
React.createElement("div", { className: 'str-chat__attachment-preview-file-icon' },
React.createElement(FileIcon, { filename: attachment.title, mimeType: attachment.mime_type }))));
};