From 685e1de3ea97aa90d5244e8addd16bb05fb4bce3 Mon Sep 17 00:00:00 2001 From: Mark VanLandingham Date: Mon, 1 May 2023 11:31:57 -0500 Subject: [PATCH] DEV: Fire appEvents for user menu events (opening/clicking) (#21322) --- .../javascripts/discourse/app/components/user-menu/menu.js | 2 ++ .../discourse/app/components/user-menu/notifications-list.js | 3 +++ .../discourse/app/lib/user-menu/notification-item.js | 5 ++++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/discourse/app/components/user-menu/menu.js b/app/assets/javascripts/discourse/app/components/user-menu/menu.js index c2d1b367644..31a67ae5c3c 100644 --- a/app/assets/javascripts/discourse/app/components/user-menu/menu.js +++ b/app/assets/javascripts/discourse/app/components/user-menu/menu.js @@ -277,6 +277,8 @@ export default class UserMenu extends Component { getOwner(this), tab.panelComponent ); + + this.appEvents.trigger("user-menu:tab-click", tab.id); this.currentNotificationTypes = tab.notificationTypes; } diff --git a/app/assets/javascripts/discourse/app/components/user-menu/notifications-list.js b/app/assets/javascripts/discourse/app/components/user-menu/notifications-list.js index efe1cadf523..c478c0bed5c 100644 --- a/app/assets/javascripts/discourse/app/components/user-menu/notifications-list.js +++ b/app/assets/javascripts/discourse/app/components/user-menu/notifications-list.js @@ -14,6 +14,7 @@ import UserMenuReviewable from "discourse/models/user-menu-reviewable"; import UserMenuReviewableItem from "discourse/lib/user-menu/reviewable-item"; export default class UserMenuNotificationsList extends UserMenuItemsList { + @service appEvents; @service currentUser; @service siteSettings; @service site; @@ -108,6 +109,7 @@ export default class UserMenuNotificationsList extends UserMenuItemsList { } ).forEach((item) => { const props = { + appEvents: this.appEvents, currentUser: this.currentUser, siteSettings: this.siteSettings, site: this.site, @@ -126,6 +128,7 @@ export default class UserMenuNotificationsList extends UserMenuItemsList { content.push( new UserMenuNotificationItem({ notification, + appEvents: this.appEvents, currentUser: this.currentUser, siteSettings: this.siteSettings, site: this.site, diff --git a/app/assets/javascripts/discourse/app/lib/user-menu/notification-item.js b/app/assets/javascripts/discourse/app/lib/user-menu/notification-item.js index d140078e1bb..31369e65ce0 100644 --- a/app/assets/javascripts/discourse/app/lib/user-menu/notification-item.js +++ b/app/assets/javascripts/discourse/app/lib/user-menu/notification-item.js @@ -5,8 +5,9 @@ import { setTransientHeader } from "discourse/lib/ajax"; import { getRenderDirector } from "discourse/lib/notification-types-manager"; export default class UserMenuNotificationItem extends UserMenuBaseItem { - constructor({ notification, currentUser, siteSettings, site }) { + constructor({ notification, appEvents, currentUser, siteSettings, site }) { super(...arguments); + this.appEvents = appEvents; this.notification = notification; this.currentUser = currentUser; this.siteSettings = siteSettings; @@ -62,6 +63,8 @@ export default class UserMenuNotificationItem extends UserMenuBaseItem { } onClick() { + this.appEvents.trigger("user-menu:notification-click", this.notification); + if (!this.notification.read) { this.notification.set("read", true);