mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
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:
@@ -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) {
|
||||
|
||||
@@ -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";
|
||||
|
||||
Reference in New Issue
Block a user