From cc9dcca5e04d6bbb22b5817fd554ea25ee883e8d Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 3 Jun 2018 20:20:45 -0600 Subject: [PATCH] Update commentform.js --- resources/assets/js/components/commentform.js | 37 ++++++++++++++----- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/resources/assets/js/components/commentform.js b/resources/assets/js/components/commentform.js index fb61e9e89..c7de6b42e 100644 --- a/resources/assets/js/components/commentform.js +++ b/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 = '

' + pixelfed.user.username + ''+ commenttext + '

'; - 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 = '

' + username + ''+ commenttext + '1s

'; + + comments.prepend(comment); + commentform.val(''); commentform.blur(); - return true; - } catch(e) { - return false; - } + + }) + .catch(function (res) { + + }); + }); }); \ No newline at end of file