A platform for community discussion. Free, open, simple.
DEV: move new post reactions to upcoming change (#39450)
David Battersbyd1fe9a4b10c2
diff --git a/app/assets/stylesheets/common/base/topic-post.scss b/app/assets/stylesheets/common/base/topic-post.scssindex 7bacb7b7ddf..de00ec3ed1b 100644--- a/app/assets/stylesheets/common/base/topic-post.scss+++ b/app/assets/stylesheets/common/base/topic-post.scss@@ -429,12 +429,12 @@ nav.post-controls {}}- &__like-count {- color: var(--d-post-control-text-color) !important;- gap: var(--space-2);-- &.has-liked .d-icon {- color: var(--danger);+ &__double-button {+ .discourse-no-touch & {+ &:not(.has-liked):hover {+ --d-post-control-background--hover: var(--love-low);+ --d-button-flat-icon-color--hover: var(--love);+ }}}}@@ -584,6 +584,17 @@ nav.post-controls {}}+ .post-action-menu__like-count {+ display: inline-flex;+ align-items: center;+ color: var(--d-post-control-text-color) !important;+ gap: var(--space-2);++ &.has-liked .d-icon {+ color: var(--danger);+ }+ }+.btn.show-replies {--border-width: 1px;font-size: inherit;diff --git a/config/locales/server.en.yml b/config/locales/server.en.ymlindex 37b66461192..852a1cce929 100644--- a/config/locales/server.en.yml+++ b/config/locales/server.en.yml@@ -2766,6 +2766,7 @@ en:lazy_load_categories_groups: "Lazy load category information only for users of these groups. This improves performance on sites with many categories."enable_auto_grid_images: "Automatically wraps images in [grid] tags when 3 or more images are uploaded in the composer."enable_new_checkbox_style: "Enable the redesigned checkbox style for FormKit checkboxes."+ enable_new_post_reactions_menu: "Enable the redesigned post likes and reactions menu, with infinite scroll and a native mobile experience."impersonate_without_logout: "Allow admins to impersonate a user without having to log out of their admin account."experimental_impersonation_time_limit_minutes: "How long before an impersonation session is automatically ended."page_loading_indicator: "Configure the loading indicator which appears during page navigations within Discourse. 'Spinner' is a full page indicator. 'Slider' shows a narrow bar at the top of the screen."diff --git a/config/site_settings.yml b/config/site_settings.ymlindex 82d88c599ee..882ba57dd61 100644--- a/config/site_settings.yml+++ b/config/site_settings.yml@@ -4323,6 +4323,14 @@ experimental:upcoming_change:status: "alpha"impact: "feature,all_members"+ enable_new_post_reactions_menu:+ default: false+ client: true+ hidden: true+ area: "experimental"+ upcoming_change:+ status: "alpha"+ impact: "feature,all_members"rename_faq_to_guidelines:default: falsehidden: truediff --git a/frontend/discourse/app/components/post/menu.gjs b/frontend/discourse/app/components/post/menu.gjsindex 979ce2c9aec..a01b393b248 100644--- a/frontend/discourse/app/components/post/menu.gjs+++ b/frontend/discourse/app/components/post/menu.gjs@@ -33,7 +33,6 @@ import PostMenuDeleteButton from "./menu/buttons/delete";import PostMenuEditButton from "./menu/buttons/edit";import PostMenuFlagButton from "./menu/buttons/flag";import PostMenuLikeButton from "./menu/buttons/like";-import PostMenuLikeCountButton from "./menu/buttons/like-count";import PostMenuReadButton from "./menu/buttons/read";import PostMenuRepliesButton from "./menu/buttons/replies";import PostMenuReplyButton from "./menu/buttons/reply";@@ -51,7 +50,6 @@ const buttonKeys = Object.freeze({EDIT: "edit",FLAG: "flag",LIKE: "like",- LIKE_COUNT: "likeCount",READ: "read",REPLIES: "replies",REPLY: "reply",@@ -68,7 +66,6 @@ const coreButtonComponents = new Map([[buttonKeys.EDIT, PostMenuEditButton],[buttonKeys.FLAG, PostMenuFlagButton],[buttonKeys.LIKE, PostMenuLikeButton],- [buttonKeys.LIKE_COUNT, PostMenuLikeCountButton],[buttonKeys.READ, PostMenuReadButton],[buttonKeys.REPLIES, PostMenuRepliesButton],[buttonKeys.REPLY, PostMenuReplyButton],diff --git a/frontend/discourse/app/components/post/menu/buttons/like-count.gjs b/frontend/discourse/app/components/post/menu/buttons/like-count.gjsdeleted file mode 100644index c9c668b74ab..00000000000--- a/frontend/discourse/app/components/post/menu/buttons/like-count.gjs+++ /dev/null@@ -1,12 +0,0 @@-import Component from "@glimmer/component";-import LikedUsersList from "../liked-users-list";--export default class PostMenuLikeCountButton extends Component {- static extraControls = true;-- static shouldRender(args) {- return args.post.likeCount > 0;- }-- <template><LikedUsersList ...attributes @post={{@post}} /></template>-}diff --git a/frontend/discourse/app/components/post/menu/buttons/like.gjs b/frontend/discourse/app/components/post/menu/buttons/like.gjsindex 15944fc9695..3f233eb90a1 100644--- a/frontend/discourse/app/components/post/menu/buttons/like.gjs+++ b/frontend/discourse/app/components/post/menu/buttons/like.gjs@@ -6,10 +6,11 @@ import DButton from "discourse/components/d-button";import concatClass from "discourse/helpers/concat-class";import discourseLater from "discourse/lib/later";import { applyValueTransformer } from "discourse/lib/transformer";+import LikedUsersList from "../liked-users-list";export default class PostMenuLikeButton extends Component {static shouldRender(args) {- const show = args.post.showLike;+ const show = args.post.showLike || args.post.likeCount > 0;return applyValueTransformer("like-button-render-decision", show, {post: args.post,});@@ -58,22 +59,39 @@ export default class PostMenuLikeButton extends Component {}<template>- <DButton- class={{concatClass- "post-action-menu__like"- "toggle-like"- "btn-icon"- (if this.isAnimated "heart-animation")- (if @post.liked "has-like" "like")- }}- ...attributes- data-post-id={{@post.id}}- disabled={{this.disabled}}- @action={{this.toggleLike}}- @icon={{this.likeButtonIcon}}- @label={{if @showLabel "post.controls.like_action"}}- @title={{this.title}}- @ariaLabel={{this.title}}- />+ {{#if @post.showLike}}+ <div+ class={{concatClass+ "double-button"+ (if @post.liked "has-liked" "")+ "post-action-menu__double-button"+ }}+ >+ {{#if @post.likeCount}}+ <LikedUsersList ...attributes @post={{@post}} />+ {{/if}}+ <DButton+ class={{concatClass+ "post-action-menu__like"+ "toggle-like"+ "btn-icon"+ (if this.isAnimated "heart-animation")+ (if @post.liked "has-like" "like")+ }}+ ...attributes+ data-post-id={{@post.id}}+ disabled={{this.disabled}}+ @action={{this.toggleLike}}+ @icon={{this.likeButtonIcon}}+ @label={{if @showLabel "post.controls.like_action"}}+ @title={{this.title}}+ @ariaLabel={{this.title}}+ />+ </div>+ {{else}}+ <div class="double-button">+ <LikedUsersList ...attributes @post={{@post}} />+ </div>+ {{/if}}</template>}diff --git a/frontend/discourse/app/components/post/menu/liked-users-list.gjs b/frontend/discourse/app/components/post/menu/liked-users-list.gjsindex ad915325c29..4c123f211e3 100644--- a/frontend/discourse/app/components/post/menu/liked-users-list.gjs+++ b/frontend/discourse/app/components/post/menu/liked-users-list.gjs@@ -1,26 +1,48 @@import Component from "@glimmer/component";+import { tracked } from "@glimmer/tracking";import { on } from "@ember/modifier";import { action } from "@ember/object";import { service } from "@ember/service";+import ConditionalLoadingSpinner from "discourse/components/conditional-loading-spinner";+import DButton from "discourse/components/d-button";+import PluginOutlet from "discourse/components/plugin-outlet";+import UserAvatar from "discourse/components/user-avatar";+import DMenu from "discourse/float-kit/components/d-menu";import concatClass from "discourse/helpers/concat-class";import icon from "discourse/helpers/d-icon";+import lazyHash from "discourse/helpers/lazy-hash";import { i18n } from "discourse-i18n";import PostLikedUsersMenu from "./liked-users-menu";+const LIKE_ACTION = 2; // The action type ID for "like" in Discourse+const DISPLAY_MAX_USERS = 8; // will show X users, then a button to show one more row of X;const MENU_IDENTIFIER = "post-liked-users-menu";export default class LikedUsersList extends Component {@service menu;+ @service siteSettings;+ @service store;++ @tracked likedUsers;+ @tracked loadingLikedUsers = false;+ @tracked slicedUsersVisible = false;++ get useNewMenu() {+ return this.siteSettings.enable_new_post_reactions_menu;+ }get buttonIcon() {- return this.args.post.liked || this.args.post.yours- ? "d-liked"- : "d-unliked";+ return this.args.post.yours ? "d-liked" : null;}@actiontogglePopup(event) {- this.menu.show(event.currentTarget, {+ const target = event.currentTarget;+ const virtualElement = {+ getBoundingClientRect: () => target.getBoundingClientRect(),+ };++ this.menu.show(virtualElement, {identifier: MENU_IDENTIFIER,component: PostLikedUsersMenu,modalForMobile: true,@@ -32,26 +54,172 @@ export default class LikedUsersList extends Component {});}+ @action+ async fetchLikedUsers() {+ if (this.loadingLikedUsers) {+ return;+ }++ this.loadingLikedUsers = true;++ try {+ this.likedUsers = await this.store.find("post-action-user", {+ id: this.args.post.id,+ post_action_type_id: LIKE_ACTION,+ });+ } finally {+ this.loadingLikedUsers = false;+ }+ }++ @action+ toggleSlicedUsersVisiblity() {+ this.slicedUsersVisible = !this.slicedUsersVisible;+ }++ get icon() {+ if (!this.args.post.showLike) {+ return this.args.post.yours ? "d-liked" : "d-unliked";+ }++ if (this.args.post.yours) {+ return "d-liked";+ }+ }++ get truncatedUsers() {+ return this.likedUsers?.content.slice(0, DISPLAY_MAX_USERS);+ }++ get slicedUsers() {+ return this.likedUsers?.content.slice(+ DISPLAY_MAX_USERS,+ DISPLAY_MAX_USERS * 2+ );+ }++ get hiddenUserCount() {+ return (+ this.likedUsers?.length -+ (this.truncatedUsers.length + this.slicedUsers.length)+ );+ }++ get toggleSlicedUsersVisiblityIcon() {+ return this.slicedUsersVisible ? "angle-up" : "angle-down";+ }+<template>- <button- type="button"- aria-label={{i18n "post.sr_post_like_count_button" [email protected]}}- class={{concatClass- "btn btn-flat no-text"- "post-action-menu__like-count"- "like-count"- "button-count"- "highlight-action"- (if @post.liked "has-liked")- (if @post.yours "my-likes" "regular-likes")- }}- {{on "click" this.togglePopup}}- ...attributes- >- {{#if this.buttonIcon}}- {{icon this.buttonIcon}}- {{/if}}- {{@post.likeCount}}- </button>+ {{#if this.useNewMenu}}+ <button+ type="button"+ aria-label={{i18n+ "post.sr_post_like_count_button"+ }}+ class={{concatClass+ "btn btn-flat no-text"+ "post-action-menu__like-count"+ "like-count"+ "button-count"+ "highlight-action"+ (if @post.liked "has-liked")+ (if @post.yours "my-likes" "regular-likes")+ }}+ {{on "click" this.togglePopup}}+ ...attributes+ >+ {{#if this.buttonIcon}}+ {{icon this.buttonIcon}}+ {{/if}}+ {{@post.likeCount}}+ </button>+ {{else}}+ <DMenu+ @modalForMobile={{true}}+ @identifier="post-like-users_{{@post.id}}"+ @onShow={{this.fetchLikedUsers}}+ @triggerClass={{concatClass+ "post-action-menu__like-count"+ "like-count"+ "btn-flat"+ "button-count"+ "highlight-action"+ (if @post.yours "my-likes" "regular-likes")+ }}+ @icon={{if @post.yours "d-liked" ""}}+ @placement="top"+ label={{i18n "post.sr_post_like_count_button" [email protected]}}+ id="post-like-users_{{@post.id}}"+ >+ <:trigger>+ {{@post.likeCount}}+ </:trigger>+ <:content>+ <ConditionalLoadingSpinner+ @condition={{this.loadingLikedUsers}}+ class="liked-users-list__container"+ >+ <span class="liked-users-list__count">+ {{icon "d-liked" class="liked-users-list__count-icon"}}+ {{@post.likeCount}}+ </span>+ <div class="liked-users-list">+ <ul class="liked-users-list__list">+ {{#each this.truncatedUsers as |user|}}+ <li class="liked-users-list__item">+ <PluginOutlet+ @name="liked-users-list-avatar"+ @outletArgs={{lazyHash user=user post=@post}}+ >+ <UserAvatar+ class="trigger-user-card"+ @user={{user}}+ @size="small"+ />+ </PluginOutlet>+ </li>+ {{/each}}+ {{#if this.slicedUsers}}+ <li class="liked-users-list__item">+ <DButton+ class="liked-users-list__more-button btn-flat"+ @icon={{this.toggleSlicedUsersVisiblityIcon}}+ @action={{this.toggleSlicedUsersVisiblity}}+ />+ </li>+ {{/if}}+ </ul>+ {{#if this.slicedUsersVisible}}+ <ul class="liked-users-list__list">+ {{#each this.slicedUsers as |user|}}+ <li class="liked-users-list__item">+ <PluginOutlet+ @name="liked-users-list-avatar"+ @outletArgs={{lazyHash user=user post=@post}}+ >+ <UserAvatar+ class="trigger-user-card"+ @user={{user}}+ @size="small"+ />+ </PluginOutlet>+ </li>+ {{/each}}+ </ul>+ {{#if this.hiddenUserCount}}+ <span class="liked-users-list__more">+ {{i18n+ "discourse_reactions.state_panel.more_users"+ count=this.hiddenUserCount+ }}+ </span>+ {{/if}}+ {{/if}}+ </div>+ </ConditionalLoadingSpinner>+ </:content>+ </DMenu>+ {{/if}}</template>}diff --git a/frontend/discourse/tests/acceptance/post-controls-test.js b/frontend/discourse/tests/acceptance/post-controls-test.jsindex 94e4b3b236a..0492831369c 100644--- a/frontend/discourse/tests/acceptance/post-controls-test.js+++ b/frontend/discourse/tests/acceptance/post-controls-test.js@@ -3,7 +3,9 @@ import { test } from "qunit";import { acceptance } from "discourse/tests/helpers/qunit-helpers";import { i18n } from "discourse-i18n";-acceptance(`Post controls`, function () {+acceptance(`Post controls`, function (needs) {+ needs.settings({ enable_new_post_reactions_menu: true });+test("popup with likes is shown when clicking on like count", async function (assert) {await visit("/t/internationalization-localization/280");diff --git a/plugins/discourse-reactions/app/controllers/discourse_reactions/custom_reactions_controller.rb b/plugins/discourse-reactions/app/controllers/discourse_reactions/custom_reactions_controller.rbindex 387942fb093..ee2c9081653 100644--- a/plugins/discourse-reactions/app/controllers/discourse_reactions/custom_reactions_controller.rb+++ b/plugins/discourse-reactions/app/controllers/discourse_reactions/custom_reactions_controller.rb@@ -1,11 +1,12 @@# frozen_string_literal: trueclass DiscourseReactions::CustomReactionsController < ApplicationController+ MAX_USERS_COUNT = 26PAGE_SIZE = 20requires_plugin DiscourseReactions::PLUGIN_NAME- before_action :ensure_logged_in, except: %i[reactions_users_list]+ before_action :ensure_logged_in, except: %i[reactions_users_list post_reactions_users]def togglepost = fetch_post_from_params@@ -177,8 +178,129 @@ class DiscourseReactions::CustomReactionsController < ApplicationControllerrender_json_dump(users: users, total_rows: total)end+ def post_reactions_users+ params.require(:id).to_i+ reaction_value = params[:reaction_value]+ post = fetch_post_from_params++ raise Discourse::InvalidParameters if !post++ reaction_users = []++ if !reaction_value || reaction_value == DiscourseReactions::Reaction.main_reaction_id+ # We only want to get likes that don't have an associated ReactionUser+ # record, which count as a like or there will be double ups for main_reaction_id.+ likes =+ post.post_actions.where(+ DiscourseReactions::PostActionExtension.filter_reaction_likes_sql,+ like: PostActionType::LIKE_POST_ACTION_ID,+ valid_reactions: DiscourseReactions::Reaction.valid_reactions.to_a,+ )++ # Filter out likes for reactions that are not longer enabled,+ # which match up to a ReactionUser in historical data.+ historical_reaction_likes =+ likes+ .joins(+ "LEFT JOIN discourse_reactions_reaction_users ON discourse_reactions_reaction_users.user_id = post_actions.user_id AND discourse_reactions_reaction_users.post_id = post_actions.post_id",+ )+ .joins(+ "LEFT JOIN discourse_reactions_reactions ON discourse_reactions_reactions.id = discourse_reactions_reaction_users.reaction_id",+ )+ .where.not(+ discourse_reactions_reactions: {+ reaction_value: DiscourseReactions::Reaction.valid_reactions.to_a,+ },+ )++ likes = likes.where.not(id: historical_reaction_likes.select(:id))+ end++ if likes.present?+ main_reaction =+ DiscourseReactions::Reaction.find_by(+ reaction_value: DiscourseReactions::Reaction.main_reaction_id,+ post_id: post.id,+ )+ count = likes.length+ users = format_likes_users(likes)++ # Also include ReactionUser records for main_reaction_id+ # if they have been created in the past; new records created+ # using main_reaction_id will only make a PostAction.+ if main_reaction && main_reaction[:reaction_users_count]+ (users << get_users(main_reaction)).flatten!+ users.sort_by! { |user| user[:created_at] }+ count += main_reaction.reaction_users_count.to_i+ end++ reaction_users << {+ id: DiscourseReactions::Reaction.main_reaction_id,+ count: count,+ users: users.reverse.slice(0, MAX_USERS_COUNT + 1),+ }+ end++ if !reaction_value+ post+ .reactions+ .select do |reaction|+ reaction[:reaction_users_count] &&+ reaction[:reaction_value] != DiscourseReactions::Reaction.main_reaction_id+ end+ .each { |reaction| reaction_users << format_reaction_user(reaction) }+ elsif reaction_value != DiscourseReactions::Reaction.main_reaction_id+ post+ .reactions+ .where(reaction_value: reaction_value)+ .select { |reaction| reaction[:reaction_users_count] }+ .each { |reaction| reaction_users << format_reaction_user(reaction) }+ end++ render_json_dump(reaction_users: reaction_users)+ end+private+ def get_users(reaction)+ reaction+ .reaction_users+ .includes(:user)+ .order("discourse_reactions_reaction_users.created_at desc")+ .limit(MAX_USERS_COUNT + 1)+ .map do |reaction_user|+ {+ username: reaction_user.user.username,+ name: reaction_user.user.name,+ avatar_template: reaction_user.user.avatar_template,+ can_undo: reaction_user.can_undo?,+ created_at: reaction_user.created_at.to_s,+ }+ end+ end++ def format_reaction_user(reaction)+ {+ id: reaction.reaction_value,+ count: reaction.reaction_users_count.to_i,+ users: get_users(reaction),+ }+ end++ def format_like_user(like)+ {+ username: like.user.username,+ name: like.user.name,+ avatar_template: like.user.avatar_template,+ can_undo: guardian.can_delete_post_action?(like),+ created_at: like.created_at.to_s,+ }+ end++ def format_likes_users(likes)+ likes.includes([:user]).limit(MAX_USERS_COUNT + 1).map { |like| format_like_user(like) }+ end+def post_serializer(post)PostSerializer.new(post, scope: guardian, root: false)enddiff --git a/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-actions-summary.gjs b/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-actions-summary.gjsindex ea648fd3b96..624fa818b94 100644--- a/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-actions-summary.gjs+++ b/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-actions-summary.gjs@@ -4,12 +4,31 @@ import DiscourseReactionsActions from "./discourse-reactions-actions";export default class ReactionsActionSummary extends Component {static extraControls = true;- static shouldRender(args) {+ static shouldRender(args, _context, owner) {if (args.post.deleted) {return false;}- return args.post.reaction_users_count > 0;+ if (args.post.reaction_users_count <= 0) {+ return false;+ }++ const siteSettings = owner?.lookup("service:site-settings");+ if (siteSettings?.enable_new_post_reactions_menu) {+ return true;+ }++ const site = owner?.lookup("service:site");+ if (site?.mobileView) {+ return false;+ }++ const mainReaction = siteSettings?.discourse_reactions_reaction_for_like;+ return !(+ args.post.reactions &&+ args.post.reactions.length === 1 &&+ args.post.reactions[0].id === mainReaction+ );}<template>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.gjsindex 4486aa1ac3d..09dee3b5916 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@@ -21,10 +21,11 @@ import lazyHash from "discourse/helpers/lazy-hash";import { isRailsTesting, isTesting } from "discourse/lib/environment";import { emojiUrlFor } from "discourse/lib/text";import closeOnClickOutside from "discourse/modifiers/close-on-click-outside";-import { eq, not } from "discourse/truth-helpers";+import { and, eq, not } from "discourse/truth-helpers";import { i18n } from "discourse-i18n";import CustomReaction from "../models/discourse-reactions-custom-reaction";import DiscourseReactionsCounter from "./discourse-reactions-counter";+import DiscourseReactionsDoubleButton from "./discourse-reactions-double-button";import DiscourseReactionsPicker from "./discourse-reactions-picker";import DiscourseReactionsReactionButton from "./discourse-reactions-reaction-button";@@ -121,14 +122,20 @@ export default class DiscourseReactionsActions extends Component {@service dialog;@service capabilities;@service siteSettings;+ @service site;@service currentUser;@service appEvents;@tracked reactionsPickerExpanded = false;+ @tracked statePanelExpanded = false;@tracked clickOutsideDisabled = false;containerElement = null;+ get useNewMenu() {+ return this.siteSettings.enable_new_post_reactions_menu;+ }+get data() {return this.args.post;}@@ -183,7 +190,11 @@ export default class DiscourseReactionsActions extends Component {@actiontoggleReactions(event) {if (!this.reactionsPickerExpanded) {- this.expandReactionsPicker(event);+ if (this.statePanelExpanded) {+ this.scheduleExpand("expandReactionsPicker");+ } else {+ this.expandReactionsPicker(event);+ }}}@@ -522,7 +533,14 @@ export default class DiscourseReactionsActions extends Component {}let selector;- if (!attrs.reaction || attrs.reaction === mainReactionName) {+ if (+ !this.useNewMenu &&+ this.data.reactions &&+ this.data.reactions.length === 1 &&+ this.data.reactions[0].id === mainReactionName+ ) {+ selector = `.discourse-reactions-double-button .discourse-reactions-reaction-button .d-icon`;+ } else if (!attrs.reaction || attrs.reaction === mainReactionName) {selector = `.discourse-reactions-reaction-button .d-icon`;} else {selector = `.discourse-reactions-reaction-button .reaction-button .btn-toggle-reaction-emoji`;@@ -600,7 +618,7 @@ export default class DiscourseReactionsActions extends Component {if (this.clickOutsideDisabled) {return;}- if (this.reactionsPickerExpanded) {+ if (this.reactionsPickerExpanded || this.statePanelExpanded) {this.collapseAllPanels();}}@@ -608,10 +626,27 @@ export default class DiscourseReactionsActions extends Component {expandReactionsPicker() {cancel(this._collapseHandler);activeReactionsComponent?.collapseAllPanels();+ this.statePanelExpanded = false;this.reactionsPickerExpanded = true;this.updateReactionsPickerPopover();}+ @action+ expandStatePanel() {+ cancel(this._collapseHandler);+ activeReactionsComponent?.collapseAllPanels();+ this.statePanelExpanded = true;+ this.reactionsPickerExpanded = false;+ this.updateReactionsStatePanel();+ }++ @action+ collapseStatePanel() {+ cancel(this._collapseHandler);+ this._collapseHandler = null;+ this.statePanelExpanded = false;+ }+collapseReactionsPicker() {cancel(this._collapseHandler);this._collapseHandler = null;@@ -626,6 +661,7 @@ export default class DiscourseReactionsActions extends Component {false);this._collapseHandler = null;+ this.statePanelExpanded = false;this.reactionsPickerExpanded = false;}@@ -637,6 +673,14 @@ export default class DiscourseReactionsActions extends Component {);}+ @action+ updateReactionsStatePanel() {+ this.showPopover(+ ".discourse-reactions-counter",+ ".discourse-reactions-state-panel"+ );+ }+showPopover(referenceSelector, floatingSelector) {schedule("afterRender", () => {const referenceElement =@@ -701,6 +745,14 @@ export default class DiscourseReactionsActions extends Component {}}+ get onlyOneMainReaction() {+ return (+ this.data.reactions?.length === 1 &&+ this.data.reactions[0].id ===+ this.siteSettings.discourse_reactions_reaction_for_like+ );+ }+get showReactionsPicker() {return (this.currentUser &&@@ -728,7 +780,18 @@ export default class DiscourseReactionsActions extends Component {(hashcounter=(curryComponentDiscourseReactionsCounter- (lazyHash post=this.data position=@position)+ (lazyHash+ post=this.data+ position=@position+ reactionsPickerExpanded=this.reactionsPickerExpanded+ statePanelExpanded=this.statePanelExpanded+ expandStatePanel=this.expandStatePanel+ collapseStatePanel=this.collapseStatePanel+ cancelCollapse=this.cancelCollapse+ scheduleCollapse=this.scheduleCollapse+ updatePopover=this.updateReactionsStatePanel+ collapseAllPanels=this.collapseAllPanels+ ))button=(curryComponentDiscourseReactionsReactionButton@@ -759,6 +822,25 @@ export default class DiscourseReactionsActions extends Component {{{#if (eq @position "left")}}<components.counter />+ {{else if this.useNewMenu}}+ {{#unless this.data.yours}}+ <components.button />+ {{/unless}}+ {{else if this.onlyOneMainReaction}}+ <DiscourseReactionsDoubleButton+ @post={{this.data}}+ @counterComponent={{components.counter}}+ @buttonComponent={{components.button}}+ />+ {{else if this.site.mobileView}}+ {{#if (not this.data.yours)}}+ <components.counter />+ <components.button />+ {{else if+ (and this.data.yours this.data.reactions this.data.reactions.length)+ }}+ <components.counter />+ {{/if}}{{else if (not this.data.yours)}}<components.button />{{/if}}diff --git a/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-counter.gjs b/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-counter.gjsindex 7cdc342dd97..6d921db4269 100644--- a/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-counter.gjs+++ b/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-counter.gjs@@ -1,23 +1,58 @@import Component from "@glimmer/component";import { on } from "@ember/modifier";import { action } from "@ember/object";+import { trackedObject } from "@ember/reactive/collections";import { service } from "@ember/service";+import DButton from "discourse/components/d-button";+import { uniqueItemsFromArray } from "discourse/lib/array-tools";+import { bind } from "discourse/lib/decorators";+import closeOnClickOutside from "discourse/modifiers/close-on-click-outside";+import { and } from "discourse/truth-helpers";import { i18n } from "discourse-i18n";+import CustomReaction from "../models/discourse-reactions-custom-reaction";import DiscourseReactionsList from "./discourse-reactions-list";+import DiscourseReactionsStatePanel from "./discourse-reactions-state-panel";import DiscourseReactionsUsersMenu from "./discourse-reactions-users-menu";const MENU_IDENTIFIER = "discourse-reactions-users-menu";export default class DiscourseReactionsCounter extends Component {+ @service capabilities;@service menu;+ @service site;@service siteSettings;+ reactionsUsers = trackedObject();++ get useNewMenu() {+ return this.siteSettings.enable_new_post_reactions_menu;+ }+get elementId() {return `discourse-reactions-counter-${this.args.post.id}-${this.args.position || "right"}`;}+ reactionsChanged(data) {+ uniqueItemsFromArray(data.reactions).forEach((reaction) => {+ this.getUsers(reaction);+ });+ }++ @bind+ async getUsers(reactionValue) {+ const response = await CustomReaction.findReactionUsers(this.args.post.id, {+ reactionValue,+ });++ response.reaction_users.forEach((reactionUser) => {+ this.reactionsUsers[reactionUser.id] = reactionUser.users;+ });++ this.args.updatePopover?.();+ }+@actionmouseDown(event) {event.stopImmediatePropagation();@@ -30,9 +65,21 @@ export default class DiscourseReactionsCounter extends Component {@actionkeyDown(event) {+ if (this.useNewMenu) {+ if (event.key === "Enter" || event.key === " ") {+ event.preventDefault();+ this.#toggleMenu(event.currentTarget);+ }+ return;+ }+if (event.key === "Enter" || event.key === " ") {event.preventDefault();- this.#toggleMenu(event.currentTarget);+ this.click(event);+ } else if (event.key === "Escape" && this.args.statePanelExpanded) {+ event.stopPropagation();+ this.args.collapseStatePanel();+ document.getElementById(this.elementId)?.focus();}}@@ -42,13 +89,65 @@ export default class DiscourseReactionsCounter extends Component {return;}- if (event.target.closest(".post-users-popup")) {+ if (this.useNewMenu) {+ if (event.target.closest(".post-users-popup")) {+ return;+ }++ event.stopPropagation();+ event.preventDefault();+ this.#toggleMenu(event.currentTarget);+ return;+ }++ this.args.cancelCollapse();++ if (!this.capabilities.touch || this.site.desktopView) {+ event.stopPropagation();+ event.preventDefault();++ if (!this.args.statePanelExpanded) {+ this.getUsers();+ }++ this.toggleStatePanel(event);+ }+ }++ @action+ clickOutside() {+ if (this.args.statePanelExpanded) {+ this.args.collapseAllPanels();+ }+ }++ @action+ touchStart(event) {+ if (this.useNewMenu) {+ return;+ }++ this.args.cancelCollapse();++ if (+ event.target.classList.contains("show-users") ||+ event.target.classList.contains("avatar")+ ) {+ return true;+ }++ if (this.args.statePanelExpanded) {+ event.stopPropagation();+ event.preventDefault();return;}- event.stopPropagation();- event.preventDefault();- this.#toggleMenu(event.currentTarget);+ if (this.capabilities.touch) {+ event.stopPropagation();+ event.preventDefault();+ this.getUsers();+ this.toggleStatePanel(event);+ }}get classes() {@@ -73,14 +172,62 @@ export default class DiscourseReactionsCounter extends Component {return classes.join(" ");}+ toggleStatePanel() {+ if (!this.args.statePanelExpanded) {+ this.args.expandStatePanel();+ } else {+ this.args.collapseStatePanel();+ }+ }++ @action+ pointerOver(event) {+ if (this.useNewMenu) {+ return;+ }++ if (event.pointerType !== "mouse") {+ return;+ }++ this.args.cancelCollapse();+ }++ @action+ pointerOut(event) {+ if (this.useNewMenu) {+ return;+ }++ if (event.pointerType !== "mouse") {+ return;+ }++ if (!event.relatedTarget?.closest(`#${this.elementId}`)) {+ this.args.scheduleCollapse("collapseStatePanel");+ }+ }+get counterAriaLabel() {return i18n("discourse_reactions.counter.aria_label", {count: this.args.post.reaction_users_count,});}+ get onlyOneMainReaction() {+ return (+ this.args.post.reactions?.length === 1 &&+ this.args.post.reactions[0].id ===+ this.siteSettings.discourse_reactions_reaction_for_like+ );+ }+#toggleMenu(trigger) {- this.menu.show(trigger, {+ const virtualElement = {+ getBoundingClientRect: () => trigger.getBoundingClientRect(),+ };++ this.menu.show(virtualElement, {identifier: MENU_IDENTIFIER,component: DiscourseReactionsUsersMenu,modalForMobile: true,@@ -94,24 +241,75 @@ export default class DiscourseReactionsCounter extends Component {<template>{{! template-lint-disable no-invalid-interactive no-pointer-down-event-binding }}- <div- id={{this.elementId}}- class={{this.classes}}- role="button"- tabindex="0"- aria-label={{this.counterAriaLabel}}- {{on "mousedown" this.mouseDown}}- {{on "mouseup" this.mouseUp}}- {{on "click" this.click}}- {{on "keydown" this.keyDown}}- >- {{#if @post.reaction_users_count}}- <DiscourseReactionsList @post={{@post}} />-- <span class="reactions-counter" aria-hidden="true">- {{@post.reaction_users_count}}- </span>- {{/if}}- </div>+ {{#if this.useNewMenu}}+ <div+ id={{this.elementId}}+ class={{this.classes}}+ role="button"+ tabindex="0"+ aria-label={{this.counterAriaLabel}}+ {{on "mousedown" this.mouseDown}}+ {{on "mouseup" this.mouseUp}}+ {{on "click" this.click}}+ {{on "keydown" this.keyDown}}+ >+ {{#if @post.reaction_users_count}}+ <DiscourseReactionsList @post={{@post}} />++ <span class="reactions-counter" aria-hidden="true">+ {{@post.reaction_users_count}}+ </span>+ {{/if}}+ </div>+ {{else}}+ <div+ id={{this.elementId}}+ class={{this.classes}}+ role="button"+ tabindex="0"+ aria-label={{this.counterAriaLabel}}+ {{on "mousedown" this.mouseDown}}+ {{on "mouseup" this.mouseUp}}+ {{closeOnClickOutside this.clickOutside}}+ {{on "touchstart" this.touchStart}}+ {{on "pointerover" this.pointerOver}}+ {{on "pointerout" this.pointerOut}}+ {{on "click" this.click}}+ {{on "keydown" this.keyDown}}+ >+ {{#if @post.reaction_users_count}}+ <DiscourseReactionsStatePanel+ @post={{@post}}+ @reactionsUsers={{this.reactionsUsers}}+ @statePanelExpanded={{@statePanelExpanded}}+ @scheduleCollapse={{@scheduleCollapse}}+ @cancelCollapse={{@cancelCollapse}}+ />++ {{#unless this.onlyOneMainReaction}}+ <DiscourseReactionsList+ {{on "click" this.click}}+ @post={{@post}}+ @reactionsUsers={{this.reactionsUsers}}+ @getUsers={{this.getUsers}}+ />+ {{/unless}}++ <span class="reactions-counter" aria-hidden="true">+ {{@post.reaction_users_count}}+ </span>++ {{#if (and @post.yours this.onlyOneMainReaction)}}+ <div class="discourse-reactions-reaction-button my-likes">+ <DButton+ class="btn-toggle-reaction-like btn-flat btn-icon no-text reaction-button"+ @translatedTitle={{this.counterAriaLabel}}+ @icon={{this.siteSettings.discourse_reactions_like_icon}}+ />+ </div>+ {{/if}}+ {{/if}}+ </div>+ {{/if}}</template>}diff --git a/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-list-emoji.gjs b/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-list-emoji.gjsindex 6780d1ae775..db1404d9b54 100644--- a/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-list-emoji.gjs+++ b/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-list-emoji.gjs@@ -1,27 +1,157 @@import Component from "@glimmer/component";+import { tracked } from "@glimmer/tracking";+import { on } from "@ember/modifier";+import { action } from "@ember/object";+import { debounce } from "@ember/runloop";import { service } from "@ember/service";+import {+ computePosition,+ flip,+ limitShift,+ offset,+ shift,+} from "@floating-ui/dom";import emoji from "discourse/helpers/emoji";+import { bind } from "discourse/lib/decorators";+import { i18n } from "discourse-i18n";++const DISPLAY_MAX_USERS = 19;export default class DiscourseReactionsListEmoji extends Component {@service siteSettings;+ @tracked loadingReactions = false;++ get useNewMenu() {+ return this.siteSettings.enable_new_post_reactions_menu;+ }+get elementId() {return `discourse-reactions-list-emoji-${this.args.post.id}-${this.args.reaction.id}`;}+ @action+ pointerOver(event) {+ if (this.useNewMenu) {+ return;+ }++ if (event.pointerType !== "mouse" || !this.args.reaction.count) {+ return;+ }++ this.showTooltip();++ if (!this.args.users?.length && !this.loadingReactions) {+ debounce(this, this._loadReactionUsers, 3000, true);+ }+ }++ showTooltip() {+ const referenceElement = document.getElementById(this.elementId);+ const floatingElement = referenceElement.querySelector(".user-list");++ computePosition(referenceElement, floatingElement, {+ placement: "bottom",+ middleware: [+ offset(-5),+ shift({ limiter: limitShift() }),+ flip({ padding: 5 }),+ ],+ }).then(({ x, y }) => {+ Object.assign(floatingElement.style, {+ left: `${x}px`,+ top: `${y}px`,+ });+ });+ }++ _loadReactionUsers() {+ if (!this.args.getUsers) {+ return;+ }+ this.loadingReactions = true;+ this.args.getUsers(this.args.reaction.id).finally(() => {+ this.loadingReactions = false;+ });+ }++ get truncatedUsers() {+ return this.args.users?.slice(0, DISPLAY_MAX_USERS);+ }++ @bind+ displayNameForUser(user) {+ if (+ !this.siteSettings.prioritize_username_in_ux &&+ this.siteSettings.prioritize_full_name_in_ux+ ) {+ return user.name || user.username;+ } else if (this.siteSettings.prioritize_username_in_ux) {+ return user.username;+ } else if (!user.name) {+ return user.username;+ } else {+ return user.name;+ }+ }++ get hiddenUserCount() {+ return this.args.users?.length - this.truncatedUsers?.length;+ }+<template>- <div class="discourse-reactions-list-emoji" id={{this.elementId}}>- {{#if @reaction.count}}- {{emoji- @reaction.id- skipTitle=true- class=(if- this.siteSettings.discourse_reactions_desaturated_reaction_panel- "desaturated"- ""- )- }}- {{/if}}- </div>+ {{#if this.useNewMenu}}+ <div class="discourse-reactions-list-emoji" id={{this.elementId}}>+ {{#if @reaction.count}}+ {{emoji+ @reaction.id+ skipTitle=true+ class=(if+ this.siteSettings.discourse_reactions_desaturated_reaction_panel+ "desaturated"+ ""+ )+ }}+ {{/if}}+ </div>+ {{else}}+ <div+ class="discourse-reactions-list-emoji"+ id={{this.elementId}}+ {{on "pointerover" this.pointerOver}}+ >+ {{#if @reaction.count}}+ {{emoji+ @reaction.id+ skipTitle=true+ class=(if+ this.siteSettings.discourse_reactions_desaturated_reaction_panel+ "desaturated"+ ""+ )+ }}++ <div class="user-list">+ <div class="container">+ <span class="heading">{{@reaction.id}}</span>+ {{#each this.truncatedUsers as |user|}}+ <span class="username">{{this.displayNameForUser user}}</span>+ {{else}}+ <div class="center"><div class="spinner small"></div></div>+ {{/each}}+ {{#if this.hiddenUserCount}}+ <span class="other-users">+ {{i18n+ "discourse_reactions.state_panel.more_users"+ count=this.hiddenUserCount+ }}+ </span>+ {{/if}}+ </div>+ </div>+ {{/if}}+ </div>+ {{/if}}</template>}diff --git a/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-list.gjs b/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-list.gjsindex a0abed8c710..2acd0b7a823 100644--- a/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-list.gjs+++ b/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-list.gjs@@ -1,3 +1,4 @@+import { get } from "@ember/helper";import DiscourseReactionsListEmoji from "./discourse-reactions-list-emoji";const DiscourseReactionsList = <template>@@ -5,7 +6,12 @@ const DiscourseReactionsList = <template>{{#if @post.reaction_users_count}}<div class="reactions">{{#each @post.reactions as |reaction|}}- <DiscourseReactionsListEmoji @reaction={{reaction}} @post={{@post}} />+ <DiscourseReactionsListEmoji+ @reaction={{reaction}}+ @users={{if @reactionsUsers (get @reactionsUsers reaction.id)}}+ @post={{@post}}+ @getUsers={{@getUsers}}+ />{{/each}}</div>{{/if}}diff --git a/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-state-panel-reaction.gjs b/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-state-panel-reaction.gjsnew file mode 100644index 00000000000..c2dbf4b952c--- /dev/null+++ b/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-state-panel-reaction.gjs@@ -0,0 +1,120 @@+import Component from "@glimmer/component";+import { on } from "@ember/modifier";+import { action } from "@ember/object";+import UserAvatar from "discourse/components/user-avatar";+import concatClass from "discourse/helpers/concat-class";+import icon from "discourse/helpers/d-icon";+import emoji from "discourse/helpers/emoji";+import { gt } from "discourse/truth-helpers";+import { i18n } from "discourse-i18n";++const MAX_USERS_COUNT = 26;+const MIN_USERS_COUNT = 8;++export default class DiscourseReactionsStatePanelReaction extends Component {+ @action+ click(event) {+ if (event?.target?.classList?.contains("show-users")) {+ event.preventDefault();+ event.stopPropagation();++ this.args.showUsers(this.args.reaction.id);+ }+ }++ get firstLineUsers() {+ return this.args.users.slice(0, MIN_USERS_COUNT);+ }++ get otherUsers() {+ return this.args.users.slice(MIN_USERS_COUNT, MAX_USERS_COUNT);+ }++ get columnsCount() {+ return this.args.users.length > MIN_USERS_COUNT+ ? this.firstLineUsers.length + 1+ : this.firstLineUsers.length;+ }++ get groupAriaLabel() {+ return i18n("discourse_reactions.state_panel.reaction_group", {+ reaction: this.args.reaction.id,+ count: this.args.reaction.count,+ });+ }++ get moreLabel() {+ if (this.args.isDisplayed && this.args.reaction.count > MAX_USERS_COUNT) {+ return i18n("discourse_reactions.state_panel.more_users", {+ count: this.args.reaction.count - MAX_USERS_COUNT,+ });+ }+ }++ <template>+ {{! template-lint-disable no-invalid-interactive }}+ <div+ class={{concatClass+ "discourse-reactions-state-panel-reaction"+ (if @isDisplayed "is-displayed")+ }}+ role="listitem"+ aria-label={{this.groupAriaLabel}}+ {{on "click" this.click}}+ >+ {{#if @users}}+ <div class="reaction-wrapper" aria-hidden="true">+ <div class="emoji-wrapper">+ {{emoji @reaction.id}}+ </div>+ <div class="count">+ {{@reaction.count}}+ </div>+ </div>++ <div class="users">+ <div class="list list-columns-{{this.columnsCount}}">+ {{#each this.firstLineUsers key="username" as |user|}}+ <span>+ <UserAvatar+ class="trigger-user-card"+ @size="tiny"+ @user={{user}}+ />+ </span>+ {{/each}}++ {{#if (gt @users.length MIN_USERS_COUNT)}}+ <button+ type="button"+ class="show-users"+ aria-label={{if+ @isDisplayed+ (i18n "discourse_reactions.state_panel.hide_users")+ (i18n "discourse_reactions.state_panel.show_users")+ }}+ >+ {{icon (if @isDisplayed "chevron-up" "chevron-down")}}+ </button>+ {{/if}}++ {{#if @isDisplayed}}+ {{#each this.otherUsers key="username" as |user|}}+ <span>+ <UserAvatar+ class="trigger-user-card"+ @size="tiny"+ @user={{user}}+ />+ </span>+ {{/each}}+ {{/if}}+ </div>+ <span class="more">+ {{this.moreLabel}}+ </span>+ </div>+ {{/if}}+ </div>+ </template>+}diff --git a/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-state-panel.gjs b/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-state-panel.gjsnew file mode 100644index 00000000000..0a406af481e--- /dev/null+++ b/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-state-panel.gjs@@ -0,0 +1,115 @@+import Component from "@glimmer/component";+import { tracked } from "@glimmer/tracking";+import { on } from "@ember/modifier";+import { action, get } from "@ember/object";+import didInsert from "@ember/render-modifiers/modifiers/did-insert";+import { schedule } from "@ember/runloop";+import concatClass from "discourse/helpers/concat-class";+import { and, eq } from "discourse/truth-helpers";+import DiscourseReactionsStatePanelReaction from "./discourse-reactions-state-panel-reaction";++export default class DiscourseReactionsStatePanel extends Component {+ @tracked displayedReactionId;++ get classes() {+ const classes = [];++ const { post } = this.args;+ if (post?.reactions) {+ const maxCount = Math.max(+ ...post.reactions.map((reaction) => reaction.count)+ );+ const charsCount = maxCount.toString().length;+ classes.push(`max-length-${charsCount}`);+ }++ if (this.args.statePanelExpanded) {+ classes.push("is-expanded");+ }++ return classes;+ }++ @action+ pointerOut(event) {+ if (event.pointerType !== "mouse") {+ return;+ }++ this.args.scheduleCollapse("collapseStatePanel");+ }++ @action+ pointerOver(event) {+ if (event.pointerType !== "mouse") {+ return;+ }++ this.args.cancelCollapse();+ }++ @action+ showUsers(reactionId) {+ if (!this.displayedReactionId) {+ this.displayedReactionId = reactionId;+ } else if (this.displayedReactionId === reactionId) {+ this.hideUsers();+ } else if (this.displayedReactionId !== reactionId) {+ this.displayedReactionId = reactionId;+ }+ }++ @action+ hideUsers() {+ this.displayedReactionId = null;+ }++ get hasReactionData() {+ return !!Object.keys(this.args.reactionsUsers).length;+ }++ @action+ focusContainer(element) {+ schedule("afterRender", () => {+ const counter = element.closest(".discourse-reactions-counter");+ if (counter?.matches(":focus-visible")) {+ element.focus();+ }+ });+ }++ <template>+ <div+ class={{concatClass "discourse-reactions-state-panel" this.classes}}+ {{on "pointerout" this.pointerOut}}+ {{on "pointerover" this.pointerOver}}+ >+ {{#if (and @statePanelExpanded @post.reactions.length)}}+ <div class="container">+ {{#if this.hasReactionData}}+ <div+ class="counters"+ role="list"+ tabindex="-1"+ {{didInsert this.focusContainer}}+ >+ {{#each @post.reactions key="id" as |reaction|}}+ <DiscourseReactionsStatePanelReaction+ @reaction={{reaction}}+ @users={{get @reactionsUsers reaction.id}}+ @post={{@post}}+ @isDisplayed={{eq reaction.id this.displayedReactionId}}+ @showUsers={{this.showUsers}}+ />+ {{/each}}+ </div>+ {{else}}+ <div class="spinner-container">+ <div class="spinner small"></div>+ </div>+ {{/if}}+ </div>+ {{/if}}+ </div>+ </template>+}diff --git a/plugins/discourse-reactions/assets/javascripts/discourse/initializers/discourse-reactions.gjs b/plugins/discourse-reactions/assets/javascripts/discourse/initializers/discourse-reactions.gjsindex 42349022d9a..7595b81286f 100644--- a/plugins/discourse-reactions/assets/javascripts/discourse/initializers/discourse-reactions.gjs+++ b/plugins/discourse-reactions/assets/javascripts/discourse/initializers/discourse-reactions.gjs@@ -162,7 +162,6 @@ function customizePostMenu(api) {"post-menu-buttons",({ value: dag, context: { buttonKeys } }) => {dag.replace(buttonKeys.LIKE, ReactionsActionButton);- dag.delete(buttonKeys.LIKE_COUNT);dag.add("discourse-reactions-actions", ReactionsActionSummary, {after: buttonKeys.REPLIES,});diff --git a/plugins/discourse-reactions/assets/javascripts/discourse/models/discourse-reactions-custom-reaction.js b/plugins/discourse-reactions/assets/javascripts/discourse/models/discourse-reactions-custom-reaction.jsindex 764cfa35045..272c74d10b1 100644--- a/plugins/discourse-reactions/assets/javascripts/discourse/models/discourse-reactions-custom-reaction.js+++ b/plugins/discourse-reactions/assets/javascripts/discourse/models/discourse-reactions-custom-reaction.js@@ -103,6 +103,24 @@ export default class CustomReaction extends RestModel {);}+ static findReactionUsers(postId, options = {}) {+ let url = `/discourse-reactions/posts/${postId}/reactions-users.json`;+ if (options.reactionValue) {+ url += `?reaction_value=${options.reactionValue}`;+ }+ return ajax(url, {+ type: "GET",+ }).then((result) => {+ const reactionUsers = result.reaction_users.map((reactionUser) => {+ reactionUser.users = reactionUser.users.map((user) =>+ User.create(user)+ );+ return reactionUser;+ });+ return { reaction_users: reactionUsers };+ });+ }+init() {super.init(...arguments);this.__type = "discourse-reactions-custom-reaction";diff --git a/plugins/discourse-reactions/assets/stylesheets/common/discourse-reactions.scss b/plugins/discourse-reactions/assets/stylesheets/common/discourse-reactions.scssindex df12a530fbe..286ff660708 100644--- a/plugins/discourse-reactions/assets/stylesheets/common/discourse-reactions.scss+++ b/plugins/discourse-reactions/assets/stylesheets/common/discourse-reactions.scss@@ -36,6 +36,69 @@ html.discourse-reactions-no-select {}}}++ .discourse-no-touch & {+ &:hover {+ .user-list {+ visibility: visible;+ opacity: 0.9;++ .spinner {+ animation-play-state: running;+ }+ }+ }+ }+ }++ .user-list {+ position: absolute;+ visibility: hidden;+ z-index: z("usercard") - 2;+ transition: opacity 0.33s;+ opacity: 0;+ padding: 0.5em 0;+ min-width: 120px;+ min-height: 80px;+ width: max-content;+ top: 0;++ .spinner {+ animation-play-state: paused;+ }++ .container {+ margin-top: 0.5em;+ font-size: $font-down-2;+ background-color: var(--primary);+ color: var(--secondary-very-high);+ border-radius: 3px;+ padding: 1em;+ display: flex;+ flex-direction: column;++ .heading {+ font-weight: 700;+ font-size: $font-up-1;+ padding-bottom: 0.5em;+ text-align: left;+ }++ .username {+ @include ellipsis;+ }++ .username,+ .other-users {+ white-space: nowrap;+ text-align: left;+ }++ .other-users {+ padding-top: 0.25em;+ color: var(--secondary-high);+ }+ }}}@@ -46,6 +109,150 @@ html.discourse-reactions-no-select {}}+.discourse-reactions-counter .discourse-reactions-state-panel {+ cursor: default;+ z-index: z("usercard") - 2;+ position: absolute;+ visibility: hidden;+ padding: 15px 0;+ width: max-content;+ top: 0;++ &.is-expanded {+ min-width: 80px;+ visibility: visible;+ }++ .discourse-reactions-state-panel-reaction .count {+ padding-right: 0.25em;+ }++ @for $i from 1 through 5 {+ &.max-length-#{$i} {+ .discourse-reactions-state-panel-reaction .count {+ width: #{$i * 10}px;+ }+ }+ }++ .container {+ box-shadow: var(--shadow-card);+ background-color: var(--secondary);+ display: flex;+ flex-direction: column;+ z-index: 1;+ padding: 0.25em;+ border-radius: 8px;+ }++ .counters {+ display: flex;+ flex-direction: column;+ max-height: 200px;+ overflow-y: auto;+ }+}++.discourse-reactions-state-panel-reaction {+ border-bottom: 1px solid var(--content-border-color);+ display: flex;+ justify-content: flex-start;+ align-items: flex-start;++ &:first-child {+ padding-top: 0;+ }++ &:last-child {+ border: none;+ padding-bottom: 0;+ }++ .list {+ display: grid;+ column-gap: 0.25em;+ row-gap: 0.25em;+ padding-top: 0.25em;+ grid-template-rows: 22.5px;+ }++ @for $i from 1 through 9 {+ .list-columns-#{$i} {+ grid-template-columns: repeat($i, 22.5px);+ }+ }++ .users {+ display: flex;+ flex-direction: column;++ .trigger-user-card {+ width: 22px;+ height: 22px;+ display: flex;+ align-items: center;+ justify-content: center;++ .avatar {+ // constrain to container+ width: 100%;+ height: 100%;+ }+ }+ }++ .more {+ color: var(--primary-medium);+ font-size: $font-down-1;+ padding-top: 0.5em;+ text-align: left;+ }++ .reaction-wrapper {+ display: flex;+ align-items: center;+ justify-content: center;+ padding-top: 0.25em;+ margin-left: 0 !important; // core rule has too much specificity++ .count {+ font-size: $font-down-1;+ color: var(--primary-medium);+ text-align: left;++ @include ellipsis;+ }++ .emoji-wrapper {+ width: 25px;+ height: 25px;+ display: flex;+ align-items: center;+ justify-content: center;+ }+ }++ .show-users {+ padding: 0 !important;+ margin: 0 !important;+ background: none !important;+ border-color: transparent !important;+ color: var(--primary-medium) !important;++ .d-icon {+ color: var(--primary-medium) !important;+ margin: 0;+ pointer-events: none;+ }+ }++ .count {+ color: var(--primary);+ font-size: $font-up-1;+ margin-left: 0.5em;+ }+}+@keyframes fadeIn {0% {opacity: 0;diff --git a/plugins/discourse-reactions/config/routes.rb b/plugins/discourse-reactions/config/routes.rbindex e3f5f2cfe8d..b0b6c99c0b2 100644--- a/plugins/discourse-reactions/config/routes.rb+++ b/plugins/discourse-reactions/config/routes.rb@@ -17,4 +17,6 @@ DiscourseReactions::Engine.routes.draw doget "/discourse-reactions/posts/:id/reactions-users-list" =>"custom_reactions#reactions_users_list",:as => "reactions_users_list"+ get "/discourse-reactions/posts/:id/reactions-users" => "custom_reactions#post_reactions_users",+ :as => "post_reactions_users"enddiff --git a/plugins/discourse-reactions/spec/requests/custom_reactions_controller_spec.rb b/plugins/discourse-reactions/spec/requests/custom_reactions_controller_spec.rbindex d1727395a0b..c5d451f0265 100644--- a/plugins/discourse-reactions/spec/requests/custom_reactions_controller_spec.rb+++ b/plugins/discourse-reactions/spec/requests/custom_reactions_controller_spec.rb@@ -504,6 +504,111 @@ describe DiscourseReactions::CustomReactionsController doendend+ describe "#post_reactions_users" do+ it "return reaction_users of post when theres no parameters" do+ get "/discourse-reactions/posts/#{post_2.id}/reactions-users.json"+ parsed = response.parsed_body++ expect(response.status).to eq(200)+ expect(parsed["reaction_users"][0]["users"][0]["username"]).to eq(user_5.username)+ expect(parsed["reaction_users"][0]["users"][0]["name"]).to eq(user_5.name)+ expect(parsed["reaction_users"][0]["users"][0]["avatar_template"]).to eq(+ user_5.avatar_template,+ )+ end++ it "return reaction_users of reaction when there are parameters" do+ get "/discourse-reactions/posts/#{post_2.id}/reactions-users.json?reaction_value=#{laughing_reaction.reaction_value}"+ parsed = response.parsed_body++ expect(response.status).to eq(200)+ expect(parsed["reaction_users"][0]["users"][0]["username"]).to eq(user_1.username)+ expect(parsed["reaction_users"][0]["users"][0]["name"]).to eq(user_1.name)+ expect(parsed["reaction_users"][0]["users"][0]["avatar_template"]).to eq(+ user_1.avatar_template,+ )+ end++ it "gives 404 ERROR when the post_id OR reaction_value is invalid" do+ get "/discourse-reactions/posts/1000000/reactions-users.json"+ expect(response.status).to eq(404)++ get "/discourse-reactions/posts/1000000/reactions-users.json?reaction_value=test"+ expect(response.status).to eq(404)+ end++ it "merges matching custom reaction into likes" do+ get "/discourse-reactions/posts/#{post_2.id}/reactions-users.json?reaction_value=#{DiscourseReactions::Reaction.main_reaction_id}"+ parsed = response.parsed_body+ like_count = parsed["reaction_users"][0]["count"].to_i+ expect(like_count).to eq(1)++ get "/discourse-reactions/posts/#{post_2.id}/reactions-users.json?reaction_value=laughing"+ parsed = response.parsed_body+ reaction_count = parsed["reaction_users"][0]["count"].to_i+ expect(reaction_count).to eq(2)++ SiteSetting.discourse_reactions_reaction_for_like = "laughing"++ get "/discourse-reactions/posts/#{post_2.id}/reactions-users.json?reaction_value=#{DiscourseReactions::Reaction.main_reaction_id}"+ parsed = response.parsed_body+ expect(parsed["reaction_users"][0]["count"]).to eq(like_count + reaction_count)+ end++ it "does not show reaction_users on PMs without permission" do+ get "/discourse-reactions/posts/#{private_post.id}/reactions-users.json"+ expect(response.status).to eq(403)+ end++ it "shows reaction_users on PMs with permission" do+ sign_in(user_2)+ get "/discourse-reactions/posts/#{private_post.id}/reactions-users.json"+ expect(response.status).to eq(200)+ end++ it "does not double up reactions which also count as likes if the reaction is no longer enabled" do+ post_for_enabled_reactions = Fabricate(:post, user: user_2)+ new_reaction_1 =+ Fabricate(:reaction, post: post_for_enabled_reactions, reaction_value: "laughing")+ Fabricate(+ :reaction_user,+ user: user_5,+ reaction: new_reaction_1,+ post: post_for_enabled_reactions,+ )+ Fabricate(+ :post_action,+ post: post_for_enabled_reactions,+ user: user_4,+ post_action_type_id: PostActionType::LIKE_POST_ACTION_ID,+ )++ get "/discourse-reactions/posts/#{post_for_enabled_reactions.id}/reactions-users.json"+ parsed = response.parsed_body++ expect(response.status).to eq(200)+ expect(+ parsed["reaction_users"].find { |reaction| reaction["id"] == "laughing" }["count"],+ ).to eq(1)+ expect(parsed["reaction_users"].find { |reaction| reaction["id"] == "heart" }["count"]).to eq(+ 1,+ )++ SiteSetting.discourse_reactions_enabled_reactions = "+1"++ get "/discourse-reactions/posts/#{post_for_enabled_reactions.id}/reactions-users.json"+ parsed = response.parsed_body++ expect(response.status).to eq(200)+ expect(+ parsed["reaction_users"].find { |reaction| reaction["id"] == "laughing" }["count"],+ ).to eq(1)+ expect(parsed["reaction_users"].find { |reaction| reaction["id"] == "heart" }["count"]).to eq(+ 1,+ )+ end+ end+describe "positive notifications" dobefore { PostActionNotifier.enable }diff --git a/plugins/discourse-reactions/spec/system/page_objects/post_reactions_list.rb b/plugins/discourse-reactions/spec/system/page_objects/post_reactions_list.rbindex 58b2a5c8441..c39117d9e94 100644--- a/plugins/discourse-reactions/spec/system/page_objects/post_reactions_list.rb+++ b/plugins/discourse-reactions/spec/system/page_objects/post_reactions_list.rb@@ -29,11 +29,18 @@ module PageObjectsdef hover_over_reaction(reaction)component.find(reaction_list_emoji_selector(reaction)).hover+ page.has_css?(".discourse-reactions-list-emoji .user-list", visible: true)enddef click_reaction(reaction)component.find(reaction_list_emoji_selector(reaction)).clickend++ def has_users_for_reaction?(reaction, usernames)+ find("#{reaction_list_emoji_selector(reaction)} .user-list .container").has_text?(+ usernames.join("\n"),+ )+ endendendenddiff --git a/plugins/discourse-reactions/spec/system/reactions_post_list_spec.rb b/plugins/discourse-reactions/spec/system/reactions_post_list_spec.rbindex 44675d628fe..a2299c65005 100644--- a/plugins/discourse-reactions/spec/system/reactions_post_list_spec.rb+++ b/plugins/discourse-reactions/spec/system/reactions_post_list_spec.rb@@ -12,6 +12,7 @@ describe "Reactions | Post reaction user list" dobefore doSiteSetting.discourse_reactions_enabled = true+ SiteSetting.enable_new_post_reactions_menu = trueDiscourseReactions::ReactionManager.new(reaction_value: "heart",diff --git a/plugins/discourse-reactions/test/javascripts/acceptance/discourse-reactions-post-test.js b/plugins/discourse-reactions/test/javascripts/acceptance/discourse-reactions-post-test.jsindex 247c61981c0..53b58d24d41 100644--- a/plugins/discourse-reactions/test/javascripts/acceptance/discourse-reactions-post-test.js+++ b/plugins/discourse-reactions/test/javascripts/acceptance/discourse-reactions-post-test.js@@ -11,6 +11,7 @@ acceptance("Post", function (needs) {discourse_reactions_enabled_reactions: "otter|open_mouth",discourse_reactions_reaction_for_like: "heart",discourse_reactions_like_icon: "heart",+ enable_new_post_reactions_menu: true,});needs.pretender((server, helper) => {diff --git a/spec/system/post_menu_spec.rb b/spec/system/post_menu_spec.rbindex 3273b576c96..7dbed72dedd 100644--- a/spec/system/post_menu_spec.rb+++ b/spec/system/post_menu_spec.rb@@ -513,6 +513,7 @@ describe "Post menu" doendit "shows the users who liked when clicking on the like count" do+ SiteSetting.enable_new_post_reactions_menu = truePostActionCreator.like(user, post)PostActionCreator.like(admin, post)