From 1cef3e42ceffe0f0e458d7720018b289cc2686df Mon Sep 17 00:00:00 2001
From: Hincu Petru <hincupetru@gmail.com>
Date: Mon, 17 Mar 2014 09:53:45 +0000
Subject: [PATCH] I save textarea value before rendering comments when clicked
 'show more..'

---
 Changelog.md                                            | 2 +-
 app/assets/javascripts/app/views/comment_stream_view.js | 6 ++++++
 spec/javascripts/app/views/comment_stream_view_spec.js  | 5 ++++-
 3 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/Changelog.md b/Changelog.md
index 3c5d535d22..fe35c254e1 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -28,7 +28,7 @@
 
 ## Bug fixes
 * Fix regression caused by using after_commit with nested '#save' which lead to an infinite recursion [#4715](https://github.com/diaspora/diaspora/issues/4715)
-
+* Save textarea value before rendering comments when clicked 'show more...' [#4514](https://github.com/diaspora/diaspora/issues/4514)
 # 0.3.0.0
 
 ## Pod statistics
diff --git a/app/assets/javascripts/app/views/comment_stream_view.js b/app/assets/javascripts/app/views/comment_stream_view.js
index 0a6bd11c6f..db30390ca6 100644
--- a/app/assets/javascripts/app/views/comment_stream_view.js
+++ b/app/assets/javascripts/app/views/comment_stream_view.js
@@ -19,6 +19,7 @@ app.views.CommentStream = app.views.Base.extend({
 
   setupBindings: function() {
     this.model.comments.bind('add', this.appendComment, this);
+    this.model.bind("commentsExpanded", this.storeTextareaValue, this);
     this.model.bind("commentsExpanded", this.render, this);
   },
 
@@ -28,6 +29,7 @@ app.views.CommentStream = app.views.Base.extend({
 
     // add autoexpanders to new comment textarea
     this.$("textarea").autoResize({'extraSpace' : 10});
+    this.$('textarea').val(this.textareaValue);
   },
 
   presenter: function(){
@@ -73,6 +75,10 @@ app.views.CommentStream = app.views.Base.extend({
     this.$("form").removeClass('hidden').addClass("open");
   },
 
+  storeTextareaValue: function(){
+    this.textareaValue = this.$('textarea').val();
+  },
+
   expandComments: function(evt){
     if(evt){ evt.preventDefault(); }
 
diff --git a/spec/javascripts/app/views/comment_stream_view_spec.js b/spec/javascripts/app/views/comment_stream_view_spec.js
index 22b2db68d5..fa009b92c0 100644
--- a/spec/javascripts/app/views/comment_stream_view_spec.js
+++ b/spec/javascripts/app/views/comment_stream_view_spec.js
@@ -98,7 +98,10 @@ describe("app.views.CommentStream", function(){
 
       this.view.expandComments();
 
-      mostRecentAjaxRequest().response({ comments : [] });
+      mostRecentAjaxRequest().response({ 
+        status: 200,
+        responseText: JSON.stringify([factory.comment()])
+      });
 
       expect(this.view.$("textarea").val()).toEqual("great post!");
     });
-- 
GitLab