FIX: Your own likes were missing on posts

This commit is contained in:
Robin Ward 2019-05-06 20:03:34 -04:00
parent 20f84a364b
commit 47995d2d89
2 changed files with 32 additions and 26 deletions

View File

@ -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;
}
},

View File

@ -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);