// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. // See License.txt for license information. import ReactDOM from 'react-dom'; import * as Utils from 'utils/utils.jsx'; import React from 'react'; import loadingGif from 'images/load.gif'; export default class FilePreview extends React.Component { constructor(props) { super(props); this.handleRemove = this.handleRemove.bind(this); } componentDidUpdate() { if (this.props.uploadsInProgress.length > 0) { ReactDOM.findDOMNode(this.refs[this.props.uploadsInProgress[0]]).scrollIntoView(); } } handleRemove(e) { var previewDiv = e.target.parentNode.parentNode; if (previewDiv.hasAttribute('data-filename')) { this.props.onRemove(previewDiv.getAttribute('data-filename')); } else if (previewDiv.hasAttribute('data-client-id')) { this.props.onRemove(previewDiv.getAttribute('data-client-id')); } } render() { var previews = []; this.props.files.forEach((fullFilename) => { var filename = fullFilename; var originalFilename = filename; var filenameSplit = filename.split('.'); var ext = filenameSplit[filenameSplit.length - 1]; var type = Utils.getFileType(ext); filename = Utils.getFileUrl(filename); if (type === 'image') { previews.push(
); } else { previews.push( ); } }); this.props.uploadsInProgress.forEach((clientId) => { previews.push( ); }); return (