From a15ef53c7074b2aff07b08bb9c3923ab0ef0570d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Wed, 16 Dec 2020 11:12:13 -0500 Subject: [PATCH] feat: add new client side hooks --- public/src/client/topic/postTools.js | 9 ++++++++- public/src/client/topic/votes.js | 20 ++++++++++++++------ public/src/modules/share.js | 4 ++++ 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/public/src/client/topic/postTools.js b/public/src/client/topic/postTools.js index b483c653b1..7661bb19be 100644 --- a/public/src/client/topic/postTools.js +++ b/public/src/client/topic/postTools.js @@ -338,7 +338,13 @@ define('forum/topic/postTools', [ function bookmarkPost(button, pid) { var method = button.attr('data-bookmarked') === 'false' ? 'put' : 'del'; - api[method](`/posts/${pid}/bookmark`, undefined, undefined, 'default'); + api[method](`/posts/${pid}/bookmark`, undefined, function (err) { + if (err) { + return app.alertError(err); + } + var type = method === 'put' ? 'bookmark' : 'unbookmark'; + $(window).trigger('action:post.' + type, { pid: pid }); + }); return false; } @@ -429,6 +435,7 @@ define('forum/topic/postTools', [ $(window).trigger('action:composer.topic.new', { cid: ajaxify.data.cid, body: body, + fromStaleTopic: true, }); }); }, diff --git a/public/src/client/topic/votes.js b/public/src/client/topic/votes.js index 731b7f63ba..076ff1ef5c 100644 --- a/public/src/client/topic/votes.js +++ b/public/src/client/topic/votes.js @@ -58,14 +58,22 @@ define('forum/topic/votes', [ var currentState = post.find(className).length; const method = currentState ? 'del' : 'put'; - api[method](`/posts/${post.attr('data-pid')}/vote`, { + var pid = post.attr('data-pid'); + api[method](`/posts/${pid}/vote`, { delta: delta, - }).catch((err) => { - app.alertError(err.message); - - if (err.message === '[[error:not-logged-in]]') { - ajaxify.go('login'); + }, function (err) { + if (err) { + if (err.message === '[[error:not-logged-in]]') { + ajaxify.go('login'); + return; + } + return app.alertError(err.message); } + $(window).trigger('action:post.toggleVote', { + pid: pid, + delta: delta, + unvote: method === 'del', + }); }); return false; diff --git a/public/src/modules/share.js b/public/src/modules/share.js index fe45f26d0f..e8d4633e08 100644 --- a/public/src/modules/share.js +++ b/public/src/modules/share.js @@ -9,6 +9,10 @@ define('share', function () { function openShare(url, urlToPost, width, height) { window.open(url + encodeURIComponent(baseUrl + config.relative_path + urlToPost), '_blank', 'width=' + width + ',height=' + height + ',scrollbars=no,status=no'); + $(window).trigger('action:share.open', { + url: url, + urlToPost: urlToPost, + }); return false; }