FIX: Improvements to like button for archived topics (#17951)

* FIX: Do not allow to remove like if topic is archived

* FIX: Always show like button

The like button used to be hidden if the topic was archived and it had
no likes. This commit changes that to always show the like button, but
with a not-allowed cursor if the topic is archived.
This commit is contained in:
Bianca Nenciu
2022-08-22 14:58:02 +03:00
committed by GitHub
parent 33a2624f09
commit ec8306835d
6 changed files with 58 additions and 41 deletions

View File

@@ -255,12 +255,10 @@ export default function transformPost(
if (likeAction) {
postAtts.liked = likeAction.acted;
postAtts.canToggleLike = likeAction.get("canToggle");
postAtts.showLike = postAtts.liked || postAtts.canToggleLike;
postAtts.showLike = true;
postAtts.likeCount = likeAction.count;
}
if (!currentUser) {
postAtts.showLike = !topic.archived;
} else if (!currentUser) {
postAtts.showLike = true;
}
if (postAtts.post_number === 1) {

View File

@@ -147,41 +147,45 @@ function likeCount(attrs, state) {
registerButton("like-count", likeCount);
registerButton("like", (attrs) => {
if (!attrs.showLike) {
return likeCount(attrs);
registerButton(
"like",
(attrs, _state, _siteSettings, _settings, currentUser) => {
if (!attrs.showLike) {
return likeCount(attrs);
}
const className = attrs.liked
? "toggle-like has-like fade-out"
: "toggle-like like";
const button = {
action: "like",
icon: attrs.liked ? "d-liked" : "d-unliked",
className,
before: "like-count",
data: {
"post-id": attrs.id,
},
};
// If the user has already liked the post and doesn't have permission
// to undo that operation, then indicate via the title that they've liked it
// and disable the button. Otherwise, set the title even if the user
// is anonymous (meaning they don't currently have permission to like);
// this is important for accessibility.
if (attrs.liked && !attrs.canToggleLike) {
button.title = "post.controls.has_liked";
} else {
button.title = attrs.liked
? "post.controls.undo_like"
: "post.controls.like";
}
if (currentUser && !attrs.canToggleLike) {
button.disabled = true;
}
return button;
}
const className = attrs.liked
? "toggle-like has-like fade-out"
: "toggle-like like";
const button = {
action: "like",
icon: attrs.liked ? "d-liked" : "d-unliked",
className,
before: "like-count",
data: {
"post-id": attrs.id,
},
};
// If the user has already liked the post and doesn't have permission
// to undo that operation, then indicate via the title that they've liked it
// and disable the button. Otherwise, set the title even if the user
// is anonymous (meaning they don't currently have permission to like);
// this is important for accessibility.
if (attrs.liked && !attrs.canToggleLike) {
button.title = "post.controls.has_liked";
button.disabled = true;
} else {
button.title = attrs.liked
? "post.controls.undo_like"
: "post.controls.like";
}
return button;
});
);
registerButton("flag-count", (attrs) => {
let className = "button-count";