From ca7f1dabbf3dd77c05f18c8048734703a640f2b8 Mon Sep 17 00:00:00 2001 From: Kyle Zhao Date: Mon, 12 Aug 2019 14:01:59 -0400 Subject: [PATCH] REFACTOR: user-menu-links widget for extensibility (#7996) --- .../discourse/widgets/user-menu.js.es6 | 41 +++++++++++-------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/app/assets/javascripts/discourse/widgets/user-menu.js.es6 b/app/assets/javascripts/discourse/widgets/user-menu.js.es6 index 33e92f03849..7d00766b10b 100644 --- a/app/assets/javascripts/discourse/widgets/user-menu.js.es6 +++ b/app/assets/javascripts/discourse/widgets/user-menu.js.es6 @@ -13,6 +13,28 @@ export function addUserMenuGlyph(glyph) { createWidget("user-menu-links", { tagName: "div.menu-links-header", + bookmarksGlyph() { + return { + label: "user.bookmarks", + className: "user-bookmarks-link", + icon: "bookmark", + href: `${this.attrs.path}/activity/bookmarks` + }; + }, + + messagesGlyph() { + return { + label: "user.private_messages", + className: "user-pms-link", + icon: "envelope", + href: `${this.attrs.path}/messages` + }; + }, + + glyphHtml(glyph) { + return this.attach("link", $.extend(glyph, { hideLabel: true })); + }, + html(attrs) { const { currentUser, siteSettings } = this; @@ -37,20 +59,10 @@ createWidget("user-menu-links", { }); } - glyphs.push({ - label: "user.bookmarks", - className: "user-bookmarks-link", - icon: "bookmark", - href: `${path}/activity/bookmarks` - }); + glyphs.push(this.bookmarksGlyph()); if (siteSettings.enable_personal_messages) { - glyphs.push({ - label: "user.private_messages", - className: "user-pms-link", - icon: "envelope", - href: `${path}/messages` - }); + glyphs.push(this.messagesGlyph()); } const profileLink = { @@ -95,10 +107,7 @@ createWidget("user-menu-links", { return h("ul.menu-links-row", [ links.map(l => h("li.user", this.attach("link", l))), - h( - "li.glyphs", - glyphs.map(l => this.attach("link", $.extend(l, { hideLabel: true }))) - ) + h("li.glyphs", glyphs.map(l => this.glyphHtml(l))) ]); } });