// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. // See License.txt for license information. import FileStore from 'stores/file_store.jsx'; 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(id) { this.props.onRemove(id); } render() { var previews = []; this.props.fileInfos.forEach((info) => { const type = Utils.getFileType(info.extension); let className = 'file-preview'; let previewImage; if (type === 'image') { previewImage = ( ); } else { className += ' custom-file'; previewImage =
; } previews.push(
{previewImage}
); }); this.props.uploadsInProgress.forEach((clientId) => { previews.push(
); }); return (
{previews}
); } } FilePreview.defaultProps = { fileInfos: [], uploadsInProgress: [] }; FilePreview.propTypes = { onRemove: React.PropTypes.func.isRequired, fileInfos: React.PropTypes.arrayOf(React.PropTypes.object).isRequired, uploadsInProgress: React.PropTypes.array };