#3848 Fix editing comments on issues and PRs
Merged 5 years ago by pingou. Opened 5 years ago by pingou.

@@ -113,6 +113,7 @@ 

    field.find('.comment_body').html(data.comment_updated);

    field.find('.issue_actions').show();

    field.find('.issue_comment').show();

+   field.find('.edit_comment').remove();

  }

  

  process_event = function(data, requestid, username){

file modified
+18 -1
@@ -936,7 +936,14 @@ 

  

    /* Keep some variable in memory before sending them in case the SSE is down */

    var _url = form.action;

+   var _update = false;

    var _comment = $(form).find('#comment').val();

+   var _comment_id = null;

+   if (!_comment && form.update_comment) {

+     _update = true;

+     _comment_id = $(form.edit_comment).val();

+     _comment = $(form).find('#update_comment').val();

+   }

    var _commit_id = null;

    var _line = null;

    var _token = "{{ form.csrf_token.current_token }}";
@@ -969,11 +976,21 @@ 

                dataType: 'html',

                success: function(res) {

                  var _comment = emojione.toImage(res);

-                 var data = {

+                 if (_update) {

+                   var data = {

+                     comment_updated: _comment,

+                     comment_user: "{{ g.fas_user.username }}",

+                     comment_date: Date.now(),

+                     comment_id: _comment_id,

+                     avatar_url: "{{ g.fas_user.email | avatar_url(16) }}",

+                   }

+                 } else {

+                   var data = {

                      comment_added: _comment,

                      comment_user: "{{ g.fas_user.username }}",

                      comment_date: Date.now(),

                      avatar_url: "{{ g.fas_user.email | avatar_url(16) }}",

+                   }

                  }

                  process_event(

                      data,

@@ -1058,7 +1058,14 @@ 

    }

  

    /* Keep some variable in memory before sending them in case the SSE is down */

+   var _update = false;

    var _comment = $(form).find('#comment').val();

+   var _comment_id = null;

+   if (!_comment && form.update_comment) {

+     _update = true;

+     _comment_id = $(form.edit_comment).val();

+     _comment = $(form).find('#update_comment').val();

+   }

    var _commit_id = null;

    var _line = null;

    var _token = "{{ mergeform.csrf_token.current_token }}";
@@ -1087,6 +1094,10 @@ 

          }

          item.remove();

          if (!sse) {

+             if (!_comment){

+                 // Make the browser submit the form sync

+                 form.submit();

+             }

              console.log('no sse, adding the comment manually');

              $.ajax({

                url: "{{ url_for('ui_ns.markdown_preview') }}" ,
@@ -1098,13 +1109,23 @@ 

                dataType: 'html',

                success: function(res) {

                  var _comment = emojione.toImage(res);

-                 var data = {

+                 if (_update) {

+                   var data = {

+                     comment_updated: _comment,

+                     comment_user: "{{ g.fas_user.username }}",

+                     comment_date: Date.now(),

+                     comment_id: _comment_id,

+                     avatar_url: "{{ g.fas_user.email | avatar_url(16) }}",

+                   }

+                 } else {

+                   var data = {

                      comment_added: _comment,

                      comment_user: "{{ g.fas_user.username }}",

                      comment_date: Date.now(),

                      avatar_url: "{{ g.fas_user.email | avatar_url(16) }}",

                      commit_id: _commit_id,

                      line: _line,

+                   }

                  }

                  process_event(

                      data,

This commit fixes editing comments added via JS when the SSE is down/not
responding as well as fixes an issue where the edit box/form would stay
displayed after having submitted it.

Fixes https://pagure.io/pagure/issue/3800

Signed-off-by: Pierre-Yves Chibon pingou@pingoured.fr

rebased onto e321843

5 years ago

Thanks for the review :)

Pull-Request has been merged by pingou

5 years ago