import React from 'react'; import { FormattedMessage } from 'react-intl'; import SendMessage from '../widgets/send-message.jsx'; import { bytesToHumanSize, shortenFileName } 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); this.handleKeyDown = this.handleKeyDown.bind(this); } componentDidMount() { document.addEventListener('keydown', this.handleKeyDown); } componentWillUnmount() { document.removeEventListener('keydown', this.handleKeyDown); } handleKeyDown(e) { e.preventDefault(); if (e.key === 'Escape') { this.props.onClose(); } } handleSendDoc(caption) { this.props.onClose(); this.props.onSendMessage(this.props.content.file); } render() { if (!this.props.content) { return null; } return (
{this.props.content.name} {e.preventDefault(); this.props.onClose();}}>close
{iconFromMime(this.props.content.type)}
{shortenFileName(this.props.content.name, 24) || '-'}
{this.props.content.type || 'application/octet-stream'}
{bytesToHumanSize(this.props.content.size)}
); } };