A platform for community discussion. Free, open, simple.
FIX: Stop sending unnecessary request when show more is clicked (#39396)
Pyx7f5b789b2ba5
diff --git a/frontend/discourse/app/components/post/menu.gjs b/frontend/discourse/app/components/post/menu.gjsindex a3cafcb56bb..f9aca6b9ec4 100644--- a/frontend/discourse/app/components/post/menu.gjs+++ b/frontend/discourse/app/components/post/menu.gjs@@ -40,7 +40,6 @@ import PostMenuReplyButton from "./menu/buttons/reply";import PostMenuShareButton from "./menu/buttons/share";import PostMenuShowMoreButton from "./menu/buttons/show-more";-const LIKE_ACTION = 2;const VIBRATE_DURATION = 5;const buttonKeys = Object.freeze({@@ -93,9 +92,7 @@ export default class PostMenu extends Component {true,this.#prepareStaticMethodsState({ collapsed: true }));- @tracked isWhoLikedVisible = false;- @tracked likedUsers = [];- @tracked totalLikedUsers;+@tracked isWhoReadVisible = false;@tracked readers = [];@tracked totalReaders;@@ -117,7 +114,6 @@ export default class PostMenu extends Component {showMoreActions: this.showMoreActions,showLogin: this.args.showLogin,toggleReplies: this.args.toggleReplies,- toggleWhoLiked: this.toggleWhoLiked,toggleWhoRead: this.toggleWhoRead,};}@@ -428,10 +424,6 @@ export default class PostMenu extends Component {return this.registeredButtons.get(buttonKeys.SHOW_MORE);}- get remainingLikedUsers() {- return this.totalLikedUsers - this.likedUsers.length;- }-get remainingReaders() {return this.totalReaders - this.readers.length;}@@ -473,10 +465,6 @@ export default class PostMenu extends Component {}await this.args.toggleLike();-- if (!this.collapsed) {- await this.#fetchWhoLiked();- }},this.staticMethodsArgs);@@ -523,7 +511,6 @@ export default class PostMenu extends Component {this.collapsed = false;const fetchData = [- !this.isWhoLikedVisible && this.#fetchWhoLiked(),!this.isWhoReadVisible &&this.args.showReadIndicator &&this.#fetchWhoRead(),@@ -532,16 +519,6 @@ export default class PostMenu extends Component {await Promise.all(fetchData);}- @action- toggleWhoLiked() {- if (this.isWhoLikedVisible) {- this.isWhoLikedVisible = false;- return;- }-- this.#fetchWhoLiked();- }-@actiontoggleWhoRead() {if (this.isWhoReadVisible) {@@ -568,17 +545,6 @@ export default class PostMenu extends Component {);}- async #fetchWhoLiked() {- const users = await this.store.find("post-action-user", {- id: this.args.post.id,- post_action_type_id: LIKE_ACTION,- });-- this.likedUsers = users.content.map(smallUserAttrs);- this.totalLikedUsers = users.totalRows;- this.isWhoLikedVisible = true;- }-async #fetchWhoRead() {const users = await this.store.find("post-reader", {id: this.args.post.id,@@ -595,7 +561,6 @@ export default class PostMenu extends Component {collapsed: collapsed ?? this.collapsed,currentUser: this.currentUser,filteredRepliesView: this.args.filteredRepliesView,- isWhoLikedVisible: this.isWhoLikedVisible,isWhoReadVisible: this.isWhoReadVisible,isWikiMode: this.isWikiMode,nestedReplyView: this.args.nestedReplyView,diff --git a/frontend/discourse/tests/unit/components/post-menu-test.gjs b/frontend/discourse/tests/unit/components/post-menu-test.gjsindex 2cdade5a375..a1aff104901 100644--- a/frontend/discourse/tests/unit/components/post-menu-test.gjs+++ b/frontend/discourse/tests/unit/components/post-menu-test.gjs@@ -4,6 +4,7 @@ import { module, test } from "qunit";import PostMenu from "discourse/components/post/menu";import { withPluginApi } from "discourse/lib/plugin-api";import { setupRenderingTest } from "discourse/tests/helpers/component-test";+import pretender, { response } from "discourse/tests/helpers/create-pretender";const noop = () => {};@@ -105,6 +106,22 @@ module("Unit | Component | PostMenu", function (hooks) {);});+ test("show more does not request who liked the post", async function (assert) {+ this.siteSettings.post_menu_hidden_items = "bookmark|copyLink";++ let requested = false;+ pretender.get("/post_action_users", () => {+ requested = true;+ return response({ post_action_users: [] });+ });++ const post = this.post;+ await render(<template><PostMenu @post={{post}} /></template>);+ await click(".post-action-menu__show-more");++ assert.false(requested, "no request is sent to /post_action_users");+ });+module("post-menu value transformer", function () {test("context/collapsedButtons: allows handling which buttons are collapsed", async function (assert) {this.siteSettings.post_menu_hidden_items = "bookmark|copyLink";