From 71a8d48d21e29f70fc26f3133a1cb0f500ea1312 Mon Sep 17 00:00:00 2001 From: Amanda Alves Branquinho Date: Wed, 20 Nov 2024 19:22:02 -0300 Subject: [PATCH] DEV: add outlet wrapper for small user list (#29763) * DEV: add outlet wrapper for small user list * DEV: use value transformer to extend small user attrs function * Update app/assets/javascripts/discourse/app/components/small-user-list.gjs Co-authored-by: Jarek Radosz --------- Co-authored-by: Jarek Radosz --- .../admin/addon/templates/user-badges.hbs | 1 + .../app/components/small-user-list.gjs | 94 +++++++++---------- .../discourse/app/lib/transformer/registry.js | 1 + .../discourse/app/lib/user-list-attrs.js | 16 ++++ .../discourse/app/widgets/post-menu.js | 17 +--- 5 files changed, 66 insertions(+), 63 deletions(-) create mode 100644 app/assets/javascripts/discourse/app/lib/user-list-attrs.js diff --git a/app/assets/javascripts/admin/addon/templates/user-badges.hbs b/app/assets/javascripts/admin/addon/templates/user-badges.hbs index 64d419ca2a8..1c6bb0071dc 100644 --- a/app/assets/javascripts/admin/addon/templates/user-badges.hbs +++ b/app/assets/javascripts/admin/addon/templates/user-badges.hbs @@ -21,6 +21,7 @@ @outletArgs={{hash availableBadges=this.availableBadges userBadges=this.userBadges + user=this.user }} >
diff --git a/app/assets/javascripts/discourse/app/components/small-user-list.gjs b/app/assets/javascripts/discourse/app/components/small-user-list.gjs index 92528bf3056..8fc904534f9 100644 --- a/app/assets/javascripts/discourse/app/components/small-user-list.gjs +++ b/app/assets/javascripts/discourse/app/components/small-user-list.gjs @@ -1,31 +1,22 @@ import Component from "@glimmer/component"; +import { hash } from "@ember/helper"; import { service } from "@ember/service"; +import PluginOutlet from "discourse/components/plugin-outlet"; import avatar from "discourse/helpers/bound-avatar-template"; -import { userPath } from "discourse/lib/url"; +import { smallUserAttrs } from "discourse/lib/user-list-attrs"; import getURL from "discourse-common/lib/get-url"; import { i18n } from "discourse-i18n"; export default class SmallUserList extends Component { @service currentUser; - smallUserAtts(user) { - return { - template: user.avatar_template, - username: user.username, - post_url: user.post_url, - url: userPath(user.username_lower), - unknown: user.unknown, - }; - } - get users() { let users = this.args.users; - if ( this.args.addSelf && !users.some((u) => u.username === this.currentUser.username) ) { - users = users.concat(this.smallUserAtts(this.currentUser)); + users = users.concat(smallUserAttrs(this.currentUser)); } return users; } @@ -39,47 +30,52 @@ export default class SmallUserList extends Component { } diff --git a/app/assets/javascripts/discourse/app/lib/transformer/registry.js b/app/assets/javascripts/discourse/app/lib/transformer/registry.js index d3adc0f4059..fc5d448c862 100644 --- a/app/assets/javascripts/discourse/app/lib/transformer/registry.js +++ b/app/assets/javascripts/discourse/app/lib/transformer/registry.js @@ -14,4 +14,5 @@ export const VALUE_TRANSFORMERS = Object.freeze([ "mentions-class", "more-topics-tabs", "post-menu-buttons", + "small-user-attrs", ]); diff --git a/app/assets/javascripts/discourse/app/lib/user-list-attrs.js b/app/assets/javascripts/discourse/app/lib/user-list-attrs.js new file mode 100644 index 00000000000..dd03989ec00 --- /dev/null +++ b/app/assets/javascripts/discourse/app/lib/user-list-attrs.js @@ -0,0 +1,16 @@ +import { applyValueTransformer } from "discourse/lib/transformer"; +import { userPath } from "discourse/lib/url"; + +export function smallUserAttrs(user) { + const defaultAttrs = { + template: user.avatar_template, + username: user.username, + post_url: user.post_url, + url: userPath(user.username_lower), + unknown: user.unknown, + }; + + return applyValueTransformer("small-user-attrs", defaultAttrs, { + user, + }); +} diff --git a/app/assets/javascripts/discourse/app/widgets/post-menu.js b/app/assets/javascripts/discourse/app/widgets/post-menu.js index dc662c020e6..4b331fab9ed 100644 --- a/app/assets/javascripts/discourse/app/widgets/post-menu.js +++ b/app/assets/javascripts/discourse/app/widgets/post-menu.js @@ -6,7 +6,7 @@ import AdminPostMenu from "discourse/components/admin-post-menu"; import DeleteTopicDisallowedModal from "discourse/components/modal/delete-topic-disallowed"; import { formattedReminderTime } from "discourse/lib/bookmark"; import { recentlyCopied, showAlert } from "discourse/lib/post-action-feedback"; -import { userPath } from "discourse/lib/url"; +import { smallUserAttrs } from "discourse/lib/user-list-attrs"; import { NO_REMINDER_ICON, WITH_REMINDER_ICON, @@ -55,16 +55,6 @@ function registerButton(name, builder) { _builders[name] = builder; } -function smallUserAtts(user) { - return { - template: user.avatar_template, - username: user.username, - post_url: user.post_url, - url: userPath(user.username_lower), - unknown: user.unknown, - }; -} - export function buildButton(name, widget) { let { attrs, state, siteSettings, settings, currentUser } = widget; @@ -907,14 +897,13 @@ export default createWidget("post-menu", { getWhoLiked() { const { attrs, state } = this; - return this.store .find("post-action-user", { id: attrs.id, post_action_type_id: LIKE_ACTION, }) .then((users) => { - state.likedUsers = users.map(smallUserAtts); + state.likedUsers = users.map(smallUserAttrs); state.total = users.totalRows; }); }, @@ -923,7 +912,7 @@ export default createWidget("post-menu", { const { attrs, state } = this; return this.store.find("post-reader", { id: attrs.id }).then((users) => { - state.readers = users.map(smallUserAtts); + state.readers = users.map(smallUserAttrs); state.totalReaders = users.totalRows; }); },