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.)
סיכום מבוסס בינה מלאכותית
The discussion revolves around modifying the link destination of a button in the user menu panel on Discourse. MrDavis97 wants to change the profile button from u/miles/summary to u/miles/activity. merefield suggests using api.reopenWidget to override the profileGlyph method and update the data.url attribute. Initially, MrDavis97 encounters a syntax error due to a missing closing parenthesis, which merefield corrects. However, the dropdown menu fails to open, prompting further debugging. merefield identifies missing constants (UserMenuAction, QuickAccess, Titles) and provides the necessary definitions. fzngagan offers a more concise solution by directly modifying the glyph object returned by this._super(), which merefield further optimizes by removing unnecessary arguments. The solution is confirmed to work by MrDavis97, who appreciates the learning experience.
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),
};
},
})
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>
Above was missing a closing ), updated
No error now, but… Now it causes the user-menu-links dropdown to not even open. Any idea why this is the case?
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 ![]()
(But see Faizaan’s optimisation below that negates the need for these, which is even better
)
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 ![]()
Yep, much better and avoids need for constants - nice optimisation! ![]()
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
Thanks guys! Working perfectly. Learning a lot about editing Discourse too!
