import React from 'react'; import { FormattedMessage } from 'react-intl'; import SendMessage from '../widgets/send-message.jsx'; import { bytesToHumanSize } from '../lib/strformat.js'; // Get material icon name from mime type. function iconFromMime(mime) { // If more icons become available in material icons, add them to this mime-to-icon mapping. const mimeToIcon = {default: 'insert_drive_file', image: 'image', text: 'description', video: 'theaters'}; return mimeToIcon[mime] || mimeToIcon[(mime || '').split('/')[0]] || mimeToIcon['default']; } export default class DocPreview extends React.PureComponent { constructor(props) { super(props); this.handleSendDoc = this.handleSendDoc.bind(this); } handleSendDoc(caption) { this.props.onClose(); this.props.onSendMessage(this.props.content.file); } render() { if (!this.props.content) { return null; } return (
{this.props.content.filename} {e.preventDefault(); this.props.onClose();}}>close
{iconFromMime(this.props.content.type)}
{this.props.content.type || 'application/octet-stream'}
{bytesToHumanSize(this.props.content.size)}
); } };