From 4b74c873cc95973c5434988a41f5e06446a4e586 Mon Sep 17 00:00:00 2001
From: hmhealey <harrisonmhealey@gmail.com>
Date: Mon, 10 Aug 2015 08:52:50 -0400
Subject: Added the ability to cancel file uploads on comments

---
 web/react/components/create_comment.jsx | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

(limited to 'web/react/components/create_comment.jsx')

diff --git a/web/react/components/create_comment.jsx b/web/react/components/create_comment.jsx
index fa7162397..13ee6deb4 100644
--- a/web/react/components/create_comment.jsx
+++ b/web/react/components/create_comment.jsx
@@ -150,10 +150,18 @@ module.exports = React.createClass({
     },
     removePreview: function(filename) {
         var previews = this.state.previews;
-        for (var i = 0; i < previews.length; i++) {
-            if (previews[i] === filename) {
-                previews.splice(i, 1);
-                break;
+        var uploadsInProgress = this.state.uploadsInProgress;
+
+        // this can be either an uploaded file or an in progress upload that we need to remove
+        var index = previews.indexOf(filename);
+        if (index !== -1) {
+            previews.splice(index, 1);
+        } else {
+            index = uploadsInProgress.indexOf(filename);
+
+            if (index !== -1) {
+                uploadsInProgress.splice(index, 1);
+                this.refs.fileUpload.cancelUpload(filename);
             }
         }
 
@@ -162,9 +170,10 @@ module.exports = React.createClass({
             draft = { message: '', uploadsInProgress: []};
         }
         draft.previews = previews;
+        draft.uploadsInProgress = uploadsInProgress;
         PostStore.storeCommentDraft(this.props.rootId, draft);
 
-        this.setState({previews: previews});
+        this.setState({previews: previews, uploadsInProgress: uploadsInProgress});
     },
     getInitialState: function() {
         PostStore.clearCommentDraftUploads();
@@ -225,6 +234,7 @@ module.exports = React.createClass({
                             id="reply_textbox"
                             ref="textbox" />
                         <FileUpload
+                            ref='fileUpload'
                             getFileCount={this.getFileCount}
                             onUploadStart={this.handleUploadStart}
                             onFileUpload={this.handleFileUploadComplete}
-- 
cgit v1.2.3-1-g7c22

