كيفية تغيير الرابط المرتبط بزر في لوحة قائمة المستخدم

Instead of the highlighted button pointing to u/miles/summary, I’d rather have it point to u/miles/activity. How can I do this? I tried to look it up online (it seems that you have to change the dara-url attribute with Javascript, but the only way I saw to do this was to first get the id of the element, which this element does not have.)

إعجاب واحد (1)

You’d need to reopen the relevant widget in a Theme Component, something like:

api.reopenWidget("user-menu-links", {
  profileGlyph() {
    return {
      title: Titles["profile"],
      className: "user-preferences-link menu-link",
      id: QuickAccess.PROFILE,
      icon: "user",
      action: UserMenuAction.QUICK_ACCESS,
      actionParam: QuickAccess.PROFILE,
      data: { url: `${this.attrs.path}/activity` },
      role: "tab",
      tabAttrs: this._tabAttrs(QuickAccess.PROFILE),
    };
  },
})
3 إعجابات

Thanks! Make sense, I think.
One thing though, I’m putting this through </head> but getting the error: SyntaxError: unknown: Unexpected token, expected "," (28:6)

<script type="text/discourse-plugin" version="0.8">    
    api.reopenWidget("user-menu-links", {
      profileGlyph() {
        return {
          title: Titles["profile"],
          className: "user-preferences-link menu-link",
          id: QuickAccess.PROFILE,
          icon: "user",
          action: UserMenuAction.QUICK_ACCESS,
          actionParam: QuickAccess.PROFILE,
          data: { url: `${this.attrs.path}/activity` },
          role: "tab",
          tabAttrs: this._tabAttrs(QuickAccess.PROFILE),
        };
      },
    }
</script>
إعجاب واحد (1)

Above was missing a closing ), updated

إعجابَين (2)

No error now, but… Now it causes the user-menu-links dropdown to not even open. Any idea why this is the case?

إعجاب واحد (1)

What did you do to debug it?

Looking at the javascript console in the browser is always a good start.

If you take a look, there are three obvious issues (ultimately).

The solution is pretty straightforward in this case, you just need to supply the missing constants:

      const UserMenuAction = {
        QUICK_ACCESS: "quickAccess",
      };

      const QuickAccess = {
        BOOKMARKS: "bookmarks",
        MESSAGES: "messages",
        NOTIFICATIONS: "notifications",
        PROFILE: "profile",
      };
      
      const Titles = {
        bookmarks: "user.bookmarks",
        messages: "user.private_messages",
        notifications: "user.notifications",
        profile: "user.preferences",
      };

Once you add these (from the original source code), it works :tada:

(But see Faizaan’s optimisation below that negates the need for these, which is even better :slight_smile: )

إعجابَين (2)

More simply

<script type="text/discourse-plugin" version="0.8">    
api.reopenWidget("user-menu-links", {
  profileGlyph() {
   const glyph = this._super(...arguments);
   glyph['data'] = { url: `${this.attrs.path}/activity` };
   return glyph;
  },
}

Not tested though :wink:

3 إعجابات

Yep, much better and avoids need for constants - nice optimisation! :slight_smile:

3 إعجابات

Actually, you can go even further and omit that:

      api.reopenWidget("user-menu-links", {
        profileGlyph() {
         const glyph = this._super();
         glyph['data'] = { url: `${this.attrs.path}/activity` };
         return glyph;
        }
      });

As there are no arguments

3 إعجابات

Thanks guys! Working perfectly. Learning a lot about editing Discourse too!

إعجابَين (2)