Răsfoiți Sursa

Update commentform.js

Daniel Supernault 7 ani în urmă
părinte
comite
cc9dcca5e0
1 a modificat fișierele cu 28 adăugiri și 9 ștergeri
  1. 28 9
      resources/assets/js/components/commentform.js

+ 28 - 9
resources/assets/js/components/commentform.js

@@ -1,5 +1,10 @@
 $(document).ready(function() {
 
+  $('.status-comment-focus').on('click', function(el) {
+    var el = $(this).parents().eq(2).find('input[name="comment"]');
+    el.focus();
+  });
+
   $('.comment-form').submit(function(e, data) {
     e.preventDefault();
 
@@ -8,18 +13,32 @@ $(document).ready(function() {
     let commentform = el.find('input[name="comment"]');
     let commenttext = commentform.val();
     let item = {item: id, comment: commenttext};
-    try {
-      axios.post('/i/comment', item);
-      var comments = el.parent().parent().find('.comments');
-      var comment = '<p class="mb-0"><span class="font-weight-bold pr-1">' + pixelfed.user.username + '</span><span class="comment-text">'+ commenttext + '</span></p>';
-      comments.prepend(comment);
 
+    axios.post('/i/comment', item)
+    .then(function (res) {
+
+      var username = res.data.username;
+      var permalink = res.data.url;
+      var profile = res.data.profile;
+
+      if($('.status-container').length == 1) {
+        var comments = el.parents().eq(3).find('.comments');
+      } else {
+        var comments = el.parents().eq(2).find('.comments');
+      }
+
+      var comment = '<p class="mb-0"><span class="font-weight-bold pr-1"><bdi><a class="text-dark" href="' + profile + '">' + username + '</a></bdi></span><span class="comment-text">'+ commenttext + '</span><span class="float-right"><a href="' + permalink + '" class="text-dark small font-weight-bold">1s</a></span></p>';
+
+      comments.prepend(comment);
+      
       commentform.val('');
       commentform.blur();
-      return true;
-    } catch(e) {
-      return false;
-    }
+
+    })
+    .catch(function (res) {
+      
+    });
+ 
   });
 
 });