From 12896bd23eeba79884245c1c29fdc568cf21a7fa Mon Sep 17 00:00:00 2001
From: Christopher Speller <crspeller@gmail.com>
Date: Mon, 14 Mar 2016 08:50:46 -0400
Subject: Converting to Webpack. Stage 1.

---
 webapp/components/file_preview.jsx | 121 +++++++++++++++++++++++++++++++++++++
 1 file changed, 121 insertions(+)
 create mode 100644 webapp/components/file_preview.jsx

(limited to 'webapp/components/file_preview.jsx')

diff --git a/webapp/components/file_preview.jsx b/webapp/components/file_preview.jsx
new file mode 100644
index 000000000..40c8b81d6
--- /dev/null
+++ b/webapp/components/file_preview.jsx
@@ -0,0 +1,121 @@
+// 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(
+                    <div
+                        key={filename}
+                        className='file-preview'
+                        data-filename={originalFilename}
+                    >
+                        <img
+                            className='file-preview__image'
+                            src={filename}
+                        />
+                        <a
+                            className='file-preview__remove'
+                            onClick={this.handleRemove}
+                        >
+                            <i className='glyphicon glyphicon-remove'/>
+                        </a>
+                    </div>
+                );
+            } else {
+                previews.push(
+                    <div
+                        key={filename}
+                        className='file-preview custom-file'
+                        data-filename={originalFilename}
+                    >
+                        <div className={'file-icon ' + Utils.getIconClassName(type)}/>
+                        <a
+                            className='file-preview__remove'
+                            onClick={this.handleRemove}
+                        >
+                            <i className='glyphicon glyphicon-remove'/>
+                        </a>
+                    </div>
+                );
+            }
+        });
+
+        this.props.uploadsInProgress.forEach((clientId) => {
+            previews.push(
+                <div
+                    ref={clientId}
+                    key={clientId}
+                    className='file-preview'
+                    data-client-id={clientId}
+                >
+                    <img
+                        className='spinner'
+                        src={loadingGif}
+                    />
+                    <a
+                        className='file-preview__remove'
+                        onClick={this.handleRemove}
+                    >
+                        <i className='glyphicon glyphicon-remove'/>
+                    </a>
+                </div>
+            );
+        });
+
+        return (
+            <div className='file-preview__container'>
+                {previews}
+            </div>
+        );
+    }
+}
+
+FilePreview.defaultProps = {
+    files: [],
+    uploadsInProgress: []
+};
+FilePreview.propTypes = {
+    onRemove: React.PropTypes.func.isRequired,
+    files: React.PropTypes.array,
+    uploadsInProgress: React.PropTypes.array
+};
-- 
cgit v1.2.3-1-g7c22

