From 47995d2d899da4a0726ef3b9004bcfd4edf7e9b1 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Mon, 6 May 2019 20:03:34 -0400 Subject: [PATCH] FIX: Your own likes were missing on posts --- .../discourse/widgets/post-menu.js.es6 | 56 ++++++++++--------- test/javascripts/widgets/post-test.js.es6 | 2 +- 2 files changed, 32 insertions(+), 26 deletions(-) diff --git a/app/assets/javascripts/discourse/widgets/post-menu.js.es6 b/app/assets/javascripts/discourse/widgets/post-menu.js.es6 index ebb94fcf9a7..b613806ea43 100644 --- a/app/assets/javascripts/discourse/widgets/post-menu.js.es6 +++ b/app/assets/javascripts/discourse/widgets/post-menu.js.es6 @@ -52,9 +52,36 @@ export function buildButton(name, widget) { } } +function likeCount(attrs) { + const count = attrs.likeCount; + + if (count > 0) { + const title = attrs.liked + ? count === 1 + ? "post.has_likes_title_only_you" + : "post.has_likes_title_you" + : "post.has_likes_title"; + const icon = attrs.yours ? "d-liked" : ""; + const additionalClass = attrs.yours ? "my-likes" : "regular-likes"; + + return { + action: "toggleWhoLiked", + title, + className: `button-count like-count highlight-action ${additionalClass}`, + contents: count, + icon, + iconRight: true, + addContainer: attrs.yours, + titleOptions: { count: attrs.liked ? count - 1 : count } + }; + } +} + +registerButton("like-count", likeCount); + registerButton("like", attrs => { if (!attrs.showLike) { - return; + return likeCount(attrs); } const className = attrs.liked @@ -85,30 +112,6 @@ registerButton("like", attrs => { return button; }); -registerButton("like-count", attrs => { - const count = attrs.likeCount; - - if (count > 0) { - const title = attrs.liked - ? count === 1 - ? "post.has_likes_title_only_you" - : "post.has_likes_title_you" - : "post.has_likes_title"; - const icon = attrs.yours ? "d-liked" : ""; - const additionalClass = attrs.yours ? "my-likes" : "regular-likes"; - - return { - action: "toggleWhoLiked", - title, - className: `button-count like-count highlight-action ${additionalClass}`, - contents: count, - icon, - iconRight: true, - titleOptions: { count: attrs.liked ? count - 1 : count } - }; - } -}); - registerButton("flag-count", attrs => { let className = "button-count"; if (attrs.reviewableScorePendingCount > 0) { @@ -344,7 +347,10 @@ export default createWidget("post-menu", { if (buttonAtts.before) { let before = this.attachButton(buttonAtts.before); return h("div.double-button", [before, button]); + } else if (buttonAtts.addContainer) { + return h("div.double-button", [button]); } + return button; } }, diff --git a/test/javascripts/widgets/post-test.js.es6 b/test/javascripts/widgets/post-test.js.es6 index e8511f54516..f3aeec4028a 100644 --- a/test/javascripts/widgets/post-test.js.es6 +++ b/test/javascripts/widgets/post-test.js.es6 @@ -144,7 +144,7 @@ widgetTest("like count button", { actions_summary: [{ id: 2, count: 1, hidden: false, can_act: true }] }); this.set("post", post); - this.set("args", { likeCount: 1, showLike: true }); + this.set("args", { likeCount: 1 }); }, async test(assert) { assert.ok(find("button.like-count").length === 1);