Skip to content

A platform for community discussion. Free, open, simple.

DEV: map reactions plugin heart to d-icon aliases (#36467)

Krisd404f281f4ea
diff --git a/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-actions.gjs b/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-actions.gjs
index be4d8773192..d371a0f07ff 100644
--- a/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-actions.gjs
+++ b/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-actions.gjs
@@ -103,8 +103,8 @@ function scaleReactionAnimation(mainReaction, start, end, complete) {
step(now) {
$(this)
.css("transform", `scale(${now})`)
- .addClass("far-heart")
- .removeClass("heart");
+ .addClass("d-icon-d-unliked")
+ .removeClass("d-icon-d-liked");
},
duration: 150,
},
diff --git a/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-reaction-button.gjs b/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-reaction-button.gjs
index 7129df62c9b..d423440fdee 100644
--- a/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-reaction-button.gjs
+++ b/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-reaction-button.gjs
@@ -59,6 +59,25 @@ export default class ReactionsReactionButton extends Component {
this.args.scheduleCollapse("collapseReactionsPicker");
}
+ get likedIcon() {
+ const icon = this.siteSettings.discourse_reactions_like_icon;
+ // Map "heart" to the d-liked alias to follow core replacement pattern
+ if (icon === "heart") {
+ return "d-liked";
+ }
+ return icon;
+ }
+
+ get unlikedIcon() {
+ const icon = this.siteSettings.discourse_reactions_like_icon;
+ // Map "heart" to the d-unliked alias to follow core replacement pattern
+ if (icon === "heart") {
+ return "d-unliked";
+ }
+
+ return `far-${icon}`;
+ }
+
get title() {
if (!this.currentUser) {
return i18n("discourse_reactions.main_reaction.unauthenticated");
@@ -118,7 +137,7 @@ export default class ReactionsReactionButton extends Component {
<DButton
class="btn-toggle-reaction-like btn-flat btn-icon no-text reaction-button"
@translatedTitle={{this.title}}
- @icon={{this.siteSettings.discourse_reactions_like_icon}}
+ @icon={{this.likedIcon}}
/>
{{else if @post.current_user_reaction}}
<DButton
@@ -135,10 +154,7 @@ export default class ReactionsReactionButton extends Component {
<DButton
class="btn-toggle-reaction-like btn-flat btn-icon no-text reaction-button"
@translatedTitle={{this.title}}
- @icon={{concat
- "far-"
- this.siteSettings.discourse_reactions_like_icon
- }}
+ @icon={{this.unlikedIcon}}
/>
{{/if}}
</div>
diff --git a/plugins/discourse-reactions/test/javascripts/acceptance/discourse-reactions-icon-aliases-test.gjs b/plugins/discourse-reactions/test/javascripts/acceptance/discourse-reactions-icon-aliases-test.gjs
new file mode 100644
index 00000000000..d1e448fb57e
--- /dev/null
+++ b/plugins/discourse-reactions/test/javascripts/acceptance/discourse-reactions-icon-aliases-test.gjs
@@ -0,0 +1,40 @@
+import { visit } from "@ember/test-helpers";
+import { test } from "qunit";
+import { acceptance } from "discourse/tests/helpers/qunit-helpers";
+import ReactionsTopics from "../fixtures/reactions-topic-fixtures";
+
+acceptance(`Discourse Reactions - Icon Aliases`, function (needs) {
+ needs.user();
+
+ needs.settings({
+ discourse_reactions_enabled: true,
+ discourse_reactions_enabled_reactions: "otter|open_mouth",
+ discourse_reactions_reaction_for_like: "heart",
+ discourse_reactions_like_icon: "heart",
+ });
+
+ needs.pretender((server, helper) => {
+ const topicPath = "/t/374.json";
+ server.get(topicPath, () => helper.response(ReactionsTopics[topicPath]));
+ });
+
+ test("uses d-liked alias when user has reacted with default heart icon", async function (assert) {
+ await visit("/t/topic_with_reactions_and_likes/374");
+
+ assert
+ .dom("#post_3 .discourse-reactions-reaction-button .d-icon-d-liked")
+ .exists(
+ "reaction button uses d-liked alias when user has reacted with heart"
+ );
+ });
+
+ test("uses d-unliked alias when user has not reacted with default heart icon", async function (assert) {
+ await visit("/t/topic_with_reactions_and_likes/374");
+
+ assert
+ .dom("#post_2 .discourse-reactions-reaction-button .d-icon-d-unliked")
+ .exists(
+ "reaction button uses d-unliked alias when user has not reacted with heart"
+ );
+ });
+});