UNPKG

stream-chat-react

Version:

React components to create chat conversations or livestream style chat

26 lines (25 loc) 2.37 kB
import React from 'react'; import { isLocalUploadAttachment } from 'stream-chat'; import { CloseIcon, DownloadIcon, LoadingIndicatorIcon, RetryIcon } from '../icons'; import { FileIcon } from '../../ReactFileUtilities'; import { useTranslationContext } from '../../../context'; export const UnsupportedAttachmentPreview = ({ attachment, handleRetry, removeAttachments, }) => { const { t } = useTranslationContext('UnsupportedAttachmentPreview'); const title = attachment.title ?? t('Unsupported attachment'); return (React.createElement("div", { className: 'str-chat__attachment-preview-unsupported', "data-testid": 'attachment-preview-unknown' }, React.createElement("div", { className: 'str-chat__attachment-preview-file-icon' }, React.createElement(FileIcon, { filename: title, mimeType: attachment.mime_type })), 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)), isLocalUploadAttachment(attachment) && ['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-title', title: title }, title), attachment.localMetadata?.uploadState === 'finished' && !!attachment.asset_url && (React.createElement("a", { className: 'str-chat__attachment-preview-file-download', download: true, href: attachment.asset_url, rel: 'noreferrer', target: '_blank' }, React.createElement(DownloadIcon, null))), attachment.localMetadata?.uploadState === 'uploading' && (React.createElement(LoadingIndicatorIcon, { size: 17 }))))); };