Skip to content

A platform for community discussion. Free, open, simple.

UX: experimental user sidebar nav feature (#44050)

Krisac93ba0c34bf
diff --git a/app/assets/stylesheets/common/base/_index.scss b/app/assets/stylesheets/common/base/_index.scss
index 7cedc861905..bc669291fc2 100644
--- a/app/assets/stylesheets/common/base/_index.scss
+++ b/app/assets/stylesheets/common/base/_index.scss
@@ -56,6 +56,7 @@
@import "sidebar-more-section-links";
@import "sidebar-section";
@import "sidebar-section-link";
+@import "sidebar-user-nav";
@import "static-login";
@import "tagging";
@import "tag-settings";
diff --git a/app/assets/stylesheets/common/base/sidebar-user-nav.scss b/app/assets/stylesheets/common/base/sidebar-user-nav.scss
new file mode 100644
index 00000000000..f296afa86b8
--- /dev/null
+++ b/app/assets/stylesheets/common/base/sidebar-user-nav.scss
@@ -0,0 +1,67 @@
+@use "lib/viewport";
+
+body.user-nav-panel-active {
+ .user-navigation-primary {
+ display: none;
+ }
+
+ // The panel replaces every one of these navs
+ .user-navigation-secondary {
+ display: none;
+ }
+
+ &.user-messages-page
+ .user-navigation-secondary:has(.navigation-controls > *) {
+ display: flex;
+ justify-content: flex-end;
+
+ .messages-nav,
+ .category-breadcrumb {
+ display: none;
+ }
+ }
+
+ .user-main .about.collapsed-info {
+ .details .primary {
+ .avatar {
+ width: 38px;
+ height: 38px;
+ margin-top: var(--space-half);
+ }
+
+ .user-profile-names__primary {
+ font-size: var(--font-up-1);
+ line-height: var(--line-height-medium);
+ }
+
+ .user-profile-names__secondary {
+ font-size: var(--font-0);
+ }
+ }
+ }
+
+ @include viewport.until(sm) {
+ .user-content tbody {
+ border-top: none;
+ }
+ }
+}
+
+body.user-nav-from-profile {
+ .admin-users.admin-config-page {
+ display: none;
+ }
+
+ .admin-container {
+ margin-top: 0;
+ }
+}
+
+.sidebar-sections.user-nav-panel {
+ .sidebar-section-link-wrapper:has(.--inbox)
+ + .sidebar-section-link-wrapper:not(:has(.--inbox)) {
+ margin-top: 0.25em;
+ padding-top: 0.25em;
+ border-top: 1px solid var(--d-sidebar-section-border-color);
+ }
+}
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index 8b2d220d8ca..dad8d927dfc 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -6633,6 +6633,7 @@ en:
forum:
label: Forum
back_to_forum: "Back to Forum"
+ back_to_admin: "Back to Admin"
filter_links: "Filter links..."
clear_filter: "Clear filter"
no_results:
diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index e4520fa76c6..261d18cc8ad 100644
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -2364,8 +2364,8 @@ en:
enable_local_logins_via_email: "Allow users to request a one-click login link to be sent to them via email."
enable_local_logins_via_code: "Allow members to sign up, accept invitations, and log in with one-time email codes (OTPs), without requiring a password."
enable_random_usernames: 'Generates random usernames for accounts created with a one-time email code using the format "adjective + noun + two random numbers" (example: QuietFalcon34). New members can change their username during the signup process.'
- random_username_adjectives: 'Words used as the first half of a randomly generated username. The leading letter is capitalized when the words are combined.'
- random_username_nouns: 'Words used as the second half of a randomly generated username. The leading letter is capitalized when the words are combined.'
+ random_username_adjectives: "Words used as the first half of a randomly generated username. The leading letter is capitalized when the words are combined."
+ random_username_nouns: "Words used as the second half of a randomly generated username. The leading letter is capitalized when the words are combined."
allow_passkeys_for_2fa: "Allow users to use a passkey to satisfy two-factor authentication when confirming a sensitive action."
allow_new_registrations: "Allow new user registrations. Uncheck this to prevent anyone from creating a new account."
enable_signup_cta: "Show a notice to returning anonymous users prompting them to sign up for an account."
@@ -3181,6 +3181,7 @@ en:
improved_crawler_detection: "Enables improved crawler tracking which can better detect likely crawlers and ensure traffic reporting is more accurate."
enable_invite_modal_with_roles: "Enables a redesigned invite flow that lets admins invite someone directly as an admin. The invitee becomes a moderator on signup and an admin once the inviter confirms via email."
update_pending_users_reminder_default: "We are updating the default for the {{setting:pending_users_reminder_delay_minutes}} setting to 30 minutes so that staff are promptly notified when a new member is waiting for approval. If you have previously changed this setting, this change will have no effect."
+ sidebar_user_navigation: "Moves the navigation for user pages — profile, activity, notifications, messages, invites and preferences — out of the horizontal tab bars and into a dedicated sidebar panel, the way the admin area works. On mobile the panel is served from the hamburger menu."
enable_generated_llms_txt: "Generates a concise /llms.txt when no custom file is uploaded. The document describes public discovery routes, the preferred Discourse MCP interface, and responsible agent access. To tune automated access, configure {{setting:slow_down_crawler_user_agents}} and {{setting:slow_down_crawler_rate}}."
enable_markdown_endpoints: "Serve supported topics and topic lists as Markdown through .md URLs and requests with an Accept: text/markdown header. Normal visibility and profile privacy rules always apply."
diff --git a/config/site_settings.yml b/config/site_settings.yml
index 9e85fc47477..46a2b2769ca 100644
--- a/config/site_settings.yml
+++ b/config/site_settings.yml
@@ -5012,3 +5012,11 @@ experimental:
permanent_warning: false
allow_enabled_for:
- everyone
+ sidebar_user_navigation:
+ default: false
+ hidden: true
+ client: true
+ upcoming_change:
+ status: "experimental"
+ impact: "feature,all_members"
+ learn_more_url: "https://meta.discourse.org/t/-/413150"
diff --git a/frontend/discourse/admin/controllers/admin-user.js b/frontend/discourse/admin/controllers/admin-user.js
index f680f5e4f6c..8edb15ef8fa 100644
--- a/frontend/discourse/admin/controllers/admin-user.js
+++ b/frontend/discourse/admin/controllers/admin-user.js
@@ -1,3 +1,15 @@
import Controller from "@ember/controller";
+import { service } from "@ember/service";
-export default class AdminUserController extends Controller {}
+export default class AdminUserController extends Controller {
+ @service userNavSidebarStateManager;
+
+ // Arriving from someone's profile, the Users config page's own header and
+ // tabs are not the trail the viewer followed, and the sidebar already offers
+ // the way back.
+ get arrivedFromProfile() {
+ const { entryURL, enteredFromAdmin } = this.userNavSidebarStateManager;
+
+ return !!entryURL && !enteredFromAdmin;
+ }
+}
diff --git a/frontend/discourse/admin/routes/admin-user.js b/frontend/discourse/admin/routes/admin-user.js
index b2e9b38cec0..fdcdfe542b2 100644
--- a/frontend/discourse/admin/routes/admin-user.js
+++ b/frontend/discourse/admin/routes/admin-user.js
@@ -1,8 +1,12 @@
import { get } from "@ember/object";
+import { service } from "@ember/service";
import AdminUser from "discourse/admin/models/admin-user";
import DiscourseRoute from "discourse/routes/discourse";
export default class AdminUserRoute extends DiscourseRoute {
+ @service adminSidebarStateManager;
+ @service userNavSidebarStateManager;
+
serialize(model) {
return {
user_id: model.get("id"),
@@ -20,4 +24,44 @@ export default class AdminUserRoute extends DiscourseRoute {
return adminUser;
});
}
+
+ setupController(controller, model) {
+ super.setupController(...arguments);
+
+ // The user nav panel reads both the user being viewed and the tab
+ // visibility rules off the `user` controller, and no route populates it
+ // here. AdminUser is a User, so those rules resolve the same way they do
+ // on a profile. Nothing else on this page wants that controller, so it is
+ // only written while the panel is there to read it.
+ if (this.userNavSidebarStateManager.enabled) {
+ this.controllerFor("user").set("model", model);
+ }
+ }
+
+ activate() {
+ super.activate(...arguments);
+
+ // The parent admin route has already claimed the sidebar by now; this is a
+ // user's page, so the user nav takes it back.
+ this.userNavSidebarStateManager.captureEntryPoint();
+ this.userNavSidebarStateManager.forceUserNavSidebar();
+ }
+
+ deactivate(transition) {
+ super.deactivate(...arguments);
+
+ this.userNavSidebarStateManager.clearEntryPoint();
+
+ // `routes/admin` only hands the sidebar back when the transition leaves
+ // admin altogether, so moving to another admin page has to restore the
+ // admin sidebar here — but only when this route took it in the first place.
+ if (
+ this.userNavSidebarStateManager.enabled &&
+ transition?.to?.name?.startsWith("admin")
+ ) {
+ this.adminSidebarStateManager.maybeForceAdminSidebar({
+ onlyIfAlreadyActive: false,
+ });
+ }
+ }
}
diff --git a/frontend/discourse/admin/templates/admin-user.gjs b/frontend/discourse/admin/templates/admin-user.gjs
index 3a29bf131c4..644e6a12810 100644
--- a/frontend/discourse/admin/templates/admin-user.gjs
+++ b/frontend/discourse/admin/templates/admin-user.gjs
@@ -1,3 +1,9 @@
+import bodyClass from "discourse/helpers/body-class";
+
export default <template>
+ {{#if @controller.arrivedFromProfile}}
+ {{bodyClass "user-nav-from-profile"}}
+ {{/if}}
+
<section>{{outlet}}</section>
</template>
diff --git a/frontend/discourse/app/components/header/hamburger-dropdown-wrapper.gjs b/frontend/discourse/app/components/header/hamburger-dropdown-wrapper.gjs
index b94f3827546..b37cffca1d7 100644
--- a/frontend/discourse/app/components/header/hamburger-dropdown-wrapper.gjs
+++ b/frontend/discourse/app/components/header/hamburger-dropdown-wrapper.gjs
@@ -45,7 +45,10 @@ export default class HamburgerDropdownWrapper extends Component {
@action
clickOutside(e) {
- let exceptionSelectors = [".sidebar-more-section-content"];
+ let exceptionSelectors = [
+ ".sidebar-more-section-content",
+ ".fk-d-menu-modal",
+ ];
exceptionSelectors = applyValueTransformer(
"hamburger-dropdown-click-outside-exceptions",
diff --git a/frontend/discourse/app/components/sidebar/api-panels.gjs b/frontend/discourse/app/components/sidebar/api-panels.gjs
index 8f1059002e7..19c7344d0fb 100644
--- a/frontend/discourse/app/components/sidebar/api-panels.gjs
+++ b/frontend/discourse/app/components/sidebar/api-panels.gjs
@@ -15,6 +15,7 @@ export default class SidebarApiPanels extends Component {
@collapsable={{@collapsableSections}}
@expandActiveSection={{this.sidebarState.currentPanel.expandActiveSection}}
@scrollActiveLinkIntoView={{this.sidebarState.currentPanel.scrollActiveLinkIntoView}}
+ @toggleNavigationMenu={{@toggleNavigationMenu}}
/>
</div>
</template>
diff --git a/frontend/discourse/app/components/sidebar/api-section.gjs b/frontend/discourse/app/components/sidebar/api-section.gjs
index 4adc710d4f0..91e3688dfc6 100644
--- a/frontend/discourse/app/components/sidebar/api-section.gjs
+++ b/frontend/discourse/app/components/sidebar/api-section.gjs
@@ -59,6 +59,7 @@ export default class SidebarApiSection extends Component {
@identifier={{concat "sidebar-more-" @section.name}}
@scrollActiveLinkIntoView={{@scrollActiveLinkIntoView}}
@sectionLinks={{this.moreLinks}}
+ @toggleNavigationMenu={{@toggleNavigationMenu}}
@triggerPrefixType={{@section.moreLinksTriggerPrefixType}}
@triggerPrefixValue={{@section.moreLinksTriggerPrefixValue}}
@triggerSuffixType={{@section.moreLinksTriggerSuffixType}}
@@ -130,6 +131,7 @@ export default class SidebarApiSection extends Component {
@identifier={{concat "sidebar-more-" @section.name}}
@scrollActiveLinkIntoView={{@scrollActiveLinkIntoView}}
@sectionLinks={{this.moreLinks}}
+ @toggleNavigationMenu={{@toggleNavigationMenu}}
@triggerPrefixType={{@section.moreLinksTriggerPrefixType}}
@triggerPrefixValue={{@section.moreLinksTriggerPrefixValue}}
@triggerSuffixType={{@section.moreLinksTriggerSuffixType}}
diff --git a/frontend/discourse/app/components/sidebar/api-sections.gjs b/frontend/discourse/app/components/sidebar/api-sections.gjs
index 99f9fe22655..0c7085ce7b2 100644
--- a/frontend/discourse/app/components/sidebar/api-sections.gjs
+++ b/frontend/discourse/app/components/sidebar/api-sections.gjs
@@ -50,6 +50,7 @@ export default class SidebarApiSections extends Component {
@expandWhenActive={{@expandActiveSection}}
@scrollActiveLinkIntoView={{@scrollActiveLinkIntoView}}
@section={{section}}
+ @toggleNavigationMenu={{@toggleNavigationMenu}}
/>
{{/each}}
</template>
diff --git a/frontend/discourse/app/components/sidebar/back-to-forum.gjs b/frontend/discourse/app/components/sidebar/back-to-forum.gjs
index 4a82f66fbab..5ce6e0d9fea 100644
--- a/frontend/discourse/app/components/sidebar/back-to-forum.gjs
+++ b/frontend/discourse/app/components/sidebar/back-to-forum.gjs
@@ -25,11 +25,15 @@ export default class BackToForum extends Component {
return getURL("/");
}
+ get label() {
+ return this.args.label ?? "sidebar.back_to_forum";
+ }
+
<template>
<a class="sidebar-sections__back-to-forum" href={{this.href}}>
{{dIcon "arrow-left"}}
- <span>{{i18n "sidebar.back_to_forum"}}</span>
+ <span>{{i18n this.label}}</span>
</a>
</template>
}
diff --git a/frontend/discourse/app/components/sidebar/hamburger-dropdown.gjs b/frontend/discourse/app/components/sidebar/hamburger-dropdown.gjs
index 80b57b7d929..ca831086cca 100644
--- a/frontend/discourse/app/components/sidebar/hamburger-dropdown.gjs
+++ b/frontend/discourse/app/components/sidebar/hamburger-dropdown.gjs
@@ -74,6 +74,7 @@ export default class SidebarHamburgerDropdown extends Component {
<ApiPanels
@collapsableSections={{this.collapsableSections}}
@currentUser={{this.currentUser}}
+ @toggleNavigationMenu={{@toggleNavigationMenu}}
/>
{{/if}}
<PluginOutlet @name="after-sidebar-sections" />
diff --git a/frontend/discourse/app/components/sidebar/panel-header.gjs b/frontend/discourse/app/components/sidebar/panel-header.gjs
index c6155708750..056cafb3337 100644
--- a/frontend/discourse/app/components/sidebar/panel-header.gjs
+++ b/frontend/discourse/app/components/sidebar/panel-header.gjs
@@ -13,16 +13,41 @@ export default class PanelHeader extends Component {
return this.sidebarState.currentPanel.displayHeader;
}
+ get showFilter() {
+ const minimum = this.sidebarState.currentPanel.filterableMinLinks;
+
+ if (!minimum || this.sidebarState.filter) {
+ return true;
+ }
+
+ const links = (this.args.sections ?? [])
+ .filter((section) => section.displaySection)
+ .reduce(
+ (total, section) =>
+ total +
+ (section.links?.length ?? 0) +
+ (section.moreLinks?.length ?? 0),
+ 0
+ );
+
+ return links >= minimum;
+ }
+
<template>
{{#if this.shouldDisplay}}
<div class="sidebar-panel-header">
<div class="sidebar-panel-header__row">
- <BackToForum />
+ <BackToForum
+ @href={{this.sidebarState.currentPanel.backLink.href}}
+ @label={{this.sidebarState.currentPanel.backLink.label}}
+ />
<ToggleAllSections @sections={{@sections}} />
</div>
<div class="sidebar-panel-header__row">
<Search />
- <Filter />
+ {{#if this.showFilter}}
+ <Filter />
+ {{/if}}
</div>
<FilterNoResults @sections={{@sections}} />
</div>
diff --git a/frontend/discourse/app/controllers/user.js b/frontend/discourse/app/controllers/user.js
index d9543338657..11c5f35dd31 100644
--- a/frontend/discourse/app/controllers/user.js
+++ b/frontend/discourse/app/controllers/user.js
@@ -11,6 +11,7 @@ import { prioritizeNameInUx } from "discourse/lib/settings";
export default class UserController extends Controller {
@service currentUser;
@service router;
+ @service userNavSidebarStateManager;
@optionalService adminTools;
@computed("currentUser.ignored_ids", "model.ignored", "model.muted")
@@ -293,9 +294,20 @@ export default class UserController extends Controller {
return false;
}
+ if (this.siteSettings.sidebar_user_navigation) {
+ return false;
+ }
+
return this.site.desktopView;
}
+ // Drives the body class the panel's stylesheet keys on. The panel is not
+ // always in the DOM to be matched — collapsed, narrow and mobile all serve it
+ // from the menu button instead — so the navs it replaces cannot key on it.
+ get userNavPanelActive() {
+ return this.userNavSidebarStateManager.enabled;
+ }
+
get silencingsRouteQuery() {
return {
filters: {
diff --git a/frontend/discourse/app/lib/plugin-api.gjs b/frontend/discourse/app/lib/plugin-api.gjs
index 2caff693b0b..d36b5c237e3 100644
--- a/frontend/discourse/app/lib/plugin-api.gjs
+++ b/frontend/discourse/app/lib/plugin-api.gjs
@@ -124,6 +124,7 @@ import {
registerCustomCountable as registerUserCategorySectionLinkCountable,
} from "discourse/lib/sidebar/user/categories-section/category-section-link";
import { registerCustomTagSectionLinkPrefixIcon } from "discourse/lib/sidebar/user/tags-section/base-tag-section-link";
+import { addUserNavPreferencesLink } from "discourse/lib/sidebar/user-nav-sidebar";
import { consolePrefix } from "discourse/lib/source-identifier";
import {
_addTransformerName,
@@ -2992,6 +2993,35 @@ class _PluginApi {
addAdminSidebarSectionLink(sectionName, link);
}
+ /**
+ * EXPERIMENTAL. Do not use.
+ * Adds a link to the preferences section of the user nav sidebar panel.
+ *
+ * The `user-preferences-nav` plugin outlet renders markup the panel cannot
+ * read, so a plugin with a preferences tab registers it here as well to stay
+ * reachable once the horizontal nav is hidden.
+ *
+ * ```javascript
+ * api.addUserNavPreferencesLink({
+ * name: "preferences-chat",
+ * route: "preferences.chat",
+ * label: "chat.title_capitalized",
+ * icon: "d-chat",
+ * displayed: ({ siteSettings }) => siteSettings.chat_enabled,
+ * });
+ * ```
+ *
+ * @param {Object} link - A link object representing a preferences link.
+ * @param {string} link.name - The name of the link. Needs to be dasherized and lowercase.
+ * @param {string} link.route - The Ember route name the link points at.
+ * @param {string} link.label - The i18n key for the link's text.
+ * @param {string} [link.icon] - The FontAwesome icon to display for the link.
+ * @param {Function} [link.displayed] - Predicate deciding whether to show the link.
+ */
+ addUserNavPreferencesLink(link) {
+ addUserNavPreferencesLink(link);
+ }
+
/**
* EXPERIMENTAL. Do not use.
* Support for setting a Sidebar panel.
diff --git a/frontend/discourse/app/lib/sidebar/base-custom-sidebar-panel.js b/frontend/discourse/app/lib/sidebar/base-custom-sidebar-panel.js
index 1232ff74ef8..560aaeb33d4 100644
--- a/frontend/discourse/app/lib/sidebar/base-custom-sidebar-panel.js
+++ b/frontend/discourse/app/lib/sidebar/base-custom-sidebar-panel.js
@@ -50,6 +50,15 @@ export default class BaseCustomSidebarPanel {
return false;
}
+ /**
+ * Overrides the header's back link, for a panel that can be reached from
+ * somewhere other than the forum.
+ *
+ * @returns {{href: string, label: string}|undefined} An href and an i18n key,
+ * or undefined to leave the default "back to forum" link alone.
+ */
+ get backLink() {}
+
get expandActiveSection() {
return false;
}
@@ -62,6 +71,16 @@ export default class BaseCustomSidebarPanel {
return false;
}
+ /**
+ * How many links the panel must hold before its filter earns its place. A
+ * short panel is quicker to read than to filter.
+ *
+ * @returns {number} Defaults to 0, showing the filter whenever `filterable`.
+ */
+ get filterableMinLinks() {
+ return 0;
+ }
+
/**
* @returns {boolean} Controls whether the search is shown.
* Displays modal on click allowing searching for admin pages, site settings, themes, components and reports.
diff --git a/frontend/discourse/app/lib/sidebar/custom-sections.js b/frontend/discourse/app/lib/sidebar/custom-sections.js
index c1122d22747..3c48c8ece2d 100644
--- a/frontend/discourse/app/lib/sidebar/custom-sections.js
+++ b/frontend/discourse/app/lib/sidebar/custom-sections.js
@@ -4,6 +4,7 @@ import BaseCustomSidebarSectionLink from "discourse/lib/sidebar/base-custom-side
import { MAIN_PANEL } from "discourse/lib/sidebar/panels";
import { i18n } from "discourse-i18n";
import AdminSidebarPanel from "./admin-sidebar";
+import UserNavSidebarPanel from "./user-nav-sidebar";
class MainSidebarPanel extends BaseCustomSidebarPanel {
scrollActiveLinkIntoView = true;
@@ -63,6 +64,10 @@ export function resetPanelSections(
}
export function resetSidebarPanels() {
- customPanels = [new MainSidebarPanel(), new AdminSidebarPanel()];
+ customPanels = [
+ new MainSidebarPanel(),
+ new AdminSidebarPanel(),
+ new UserNavSidebarPanel(),
+ ];
currentPanelKey = MAIN_PANEL;
}
diff --git a/frontend/discourse/app/lib/sidebar/panels.js b/frontend/discourse/app/lib/sidebar/panels.js
index 9728f56801c..65a4b639d9d 100644
--- a/frontend/discourse/app/lib/sidebar/panels.js
+++ b/frontend/discourse/app/lib/sidebar/panels.js
@@ -2,3 +2,4 @@ export const COMBINED_MODE = "combined";
export const SEPARATED_MODE = "separated";
export const MAIN_PANEL = "main";
export const ADMIN_PANEL = "admin";
+export const USER_NAV_PANEL = "user-nav";
diff --git a/frontend/discourse/app/lib/sidebar/user-nav-sidebar.js b/frontend/discourse/app/lib/sidebar/user-nav-sidebar.js
new file mode 100644
index 00000000000..a8f3bf61140
--- /dev/null
+++ b/frontend/discourse/app/lib/sidebar/user-nav-sidebar.js
@@ -0,0 +1,765 @@
+import { cached } from "@glimmer/tracking";
+import { getOwner, setOwner } from "@ember/owner";
+import { getOwnerWithFallback } from "discourse/lib/get-owner";
+import getURL, { withoutPrefix } from "discourse/lib/get-url";
+import { showCreateInviteModal } from "discourse/lib/invite-modal";
+import BaseCustomSidebarPanel from "discourse/lib/sidebar/base-custom-sidebar-panel";
+import BaseCustomSidebarSection from "discourse/lib/sidebar/base-custom-sidebar-section";
+import BaseCustomSidebarSectionLink from "discourse/lib/sidebar/base-custom-sidebar-section-link";
+import { USER_NAV_PANEL } from "discourse/lib/sidebar/panels";
+import { i18n } from "discourse-i18n";
+
+/**
+ * Preferences tabs registered by plugins. They reach the horizontal nav through
+ * the `user-preferences-nav` outlet, which renders markup this panel cannot
+ * read, so a plugin that wants its tab in the panel registers it here too.
+ */
+let additionalPreferencesLinks = [];
+
+export function addUserNavPreferencesLink(link) {
+ additionalPreferencesLinks.push(link);
+}
+
+// For testing
+export function clearAdditionalUserNavPreferencesLinks() {
+ additionalPreferencesLinks = [];
+}
+
+// Mirrors `components/user-nav.gjs`. The tabs that own a secondary nav become
+// sections of their own below, so they are not repeated here — their section
+// header stands in for the tab.
+const PROFILE_LINKS = [
+ {
+ // Leads the list: staff open a profile to act on it, and this is the only
+ // entry that leaves the profile for somewhere else.
+ name: "admin",
+ href: ({ user }) => user?.adminPath,
+ label: "admin.user.manage_user",
+ icon: "wrench",
+ displayed: ({ currentUser }) => currentUser?.staff,
+ },
+ {
+ name: "summary",
+ route: "user.summary",
+ label: "user.summary.title",
+ icon: "user",
+ displayed: ({ user }) => !user?.profile_hidden,
+ },
+ {
+ name: "badges",
+ route: "user.badges",
+ label: "badges.title",
+ icon: "certificate",
+ displayed: ({ controller }) => controller?.showBadges,
+ },
+];
+
+// Mirrors `templates/user-activity.gjs`.
+const ACTIVITY_LINKS = [
+ {
+ name: "activity-all",
+ route: "userActivity.index",
+ label: "user.filters.all",
+ icon: "bars-staggered",
+ },
+ {
+ name: "activity-topics",
+ route: "userActivity.topics",
+ label: "user_action_groups.4",
+ icon: "list-ul",
+ },
+ {
+ name: "activity-replies",
+ route: "userActivity.replies",
+ label: "user_action_groups.5",
+ icon: "reply",
+ },
+ {
+ name: "activity-read",
+ route: "userActivity.read",
+ label: "user.read",
+ icon: "clock-rotate-left",
+ displayed: ({ controller }) => controller?.showRead,
+ },
+ {
+ name: "activity-drafts",
+ route: "userActivity.drafts",
+ label: "drafts.label",
+ icon: "pencil",
+ displayed: ({ controller }) => controller?.showDrafts,
+ count: ({ currentUser }) => currentUser?.draft_count,
+ },
+ {
+ name: "activity-pending",
+ route: "userActivity.pending",
+ icon: "clock",
+ displayed: ({ user }) => user?.pending_posts_count > 0,
+ text: ({ user }) =>
+ i18n("pending_posts.label_with_count", {
+ count: user.pending_posts_count,
+ }),
+ },
+ {
+ name: "activity-likes",
+ route: "userActivity.likesGiven",
+ label: "user_action_groups.1",
+ icon: "heart",
+ },
+ {
+ name: "activity-bookmarks",
+ route: "userActivity.bookmarks",
+ label: "user_action_groups.3",
+ icon: "bookmark",
+ displayed: ({ controller }) => controller?.showBookmarks,
+ },
+];
+
+// Mirrors `templates/user-notifications.gjs`.
+const NOTIFICATION_LINKS = [
+ {
+ name: "notifications-all",
+ route: "userNotifications.index",
+ label: "user.filters.all",
+ icon: "bell",
+ count: ({ currentUser }) => currentUser?.all_unread_notifications_count,
+ },
+ {
+ name: "notifications-responses",
+ route: "userNotifications.responses",
+ label: "user_action_groups.5",
+ icon: "reply",
+ },
+ {
+ name: "notifications-likes",
+ route: "userNotifications.likesReceived",
+ label: "user_action_groups.2",
+ icon: "heart",
+ },
+ {
+ name: "notifications-mentions",
+ route: "userNotifications.mentions",
+ label: "user_action_groups.7",
+ icon: "at",
+ displayed: ({ siteSettings }) => siteSettings?.enable_mentions,
+ },
+ {
+ name: "notifications-edits",
+ route: "userNotifications.edits",
+ label: "user_action_groups.11",
+ icon: "pencil",
+ },
+ {
+ name: "notifications-links",
+ route: "userNotifications.links",
+ label: "user_action_groups.17",
+ icon: "link",
+ },
+];
+
+// Mirrors `templates/user-invited.gjs`. The counts that template shows come
+// from controller state that only exists once the tab has been opened, so the
+// plain tab labels are used instead.
+const INVITE_LINKS = [
+ {
+ name: "invites-pending",
+ route: "userInvited.show",
+ routeParams: ["pending"],
+ label: "user.invited.pending_tab",
+ icon: "hourglass-start",
+ },
+ {
+ name: "invites-expired",
+ route: "userInvited.show",
+ routeParams: ["expired"],
+ label: "user.invited.expired_tab",
+ icon: "circle-xmark",
+ },
+ {
+ name: "invites-redeemed",
+ route: "userInvited.show",
+ routeParams: ["redeemed"],
+ label: "user.invited.redeemed_tab",
+ icon: "check",
+ },
+];
+
+// Mirrors the horizontal nav in `templates/preferences.gjs`.
+const PREFERENCES_LINKS = [
+ {
+ name: "preferences-account",
+ route: "preferences.account",
+ label: "user.preferences_nav.account",
+ icon: "circle-user",
+ },
+ {
+ name: "preferences-security",
+ route: "preferences.security",
+ label: "user.preferences_nav.security",
+ icon: "lock",
+ },
+ {
+ name: "preferences-profile",
+ route: "preferences.profile",
+ label: "user.preferences_nav.profile",
+ icon: "address-card",
+ },
+ {
+ name: "preferences-emails",
+ route: "preferences.emails",
+ label: "user.preferences_nav.emails",
+ icon: "envelope",
+ },
+ {
+ name: "preferences-notifications",
+ route: "preferences.notifications",
+ label: "user.preferences_nav.notifications",
+ icon: "bell",
+ },
+ {
+ name: "preferences-tracking",
+ route: "preferences.tracking",
+ label: "user.preferences_nav.tracking",
+ icon: "plus",
+ displayed: ({ user }) => user?.can_change_tracking_preferences !== false,
+ },
+ {
+ name: "preferences-users",
+ route: "preferences.users",
+ label: "user.preferences_nav.users",
+ icon: "users",
+ },
+ {
+ name: "preferences-interface",
+ route: "preferences.interface",
+ label: "user.preferences_nav.interface",
+ icon: "desktop",
+ },
+ {
+ name: "preferences-navigation-menu",
+ route: "preferences.navigation-menu",
+ label: "user.preferences_nav.navigation_menu",
+ icon: "bars",
+ },
+ {
+ name: "preferences-calendar-subscriptions",
+ route: "preferences.calendar-subscriptions",
+ label: "user.preferences_nav.calendar_subscriptions",
+ icon: "calendar-days",
+ },
+];
+
+// Mirrors `templates/user-private-messages/user.gjs` and `group.gjs`. The links
+// are scoped to whichever inbox is selected, so they are built from the live
+// `user-private-messages` controller rather than a static list.
+function messageLinks({ owner, currentUser, user }) {
+ const messages = owner.lookup("controller:user-private-messages");
+ const viewingSelf = messages?.viewingSelf ?? currentUser?.id === user?.id;
+ const group = messages?.isGroup && messages?.group?.name;
+
+ if (group) {
+ return [
+ {
+ name: "messages-group-latest",
+ route: "userPrivateMessages.group.index",
+ routeParams: [group],
+ label: "categories.latest",
+ icon: "envelope",
+ },
+ ...(viewingSelf
+ ? [
+ {
+ name: "messages-group-new",
+ route: "userPrivateMessages.group.new",
+ routeParams: [group],
+ label: "user.messages.new",
+ icon: "circle-exclamation",
+ count: (context) =>
+ pmCount(context, "new", {
+ inboxFilter: "group",
+ groupName: group,
+ }),
+ },
+ {
+ name: "messages-group-unread",
+ route: "userPrivateMessages.group.unread",
+ routeParams: [group],
+ label: "user.messages.unread",
+ icon: "circle-plus",
+ count: (context) =>
+ pmCount(context, "unread", {
+ inboxFilter: "group",
+ groupName: group,
+ }),
+ },
+ {
+ name: "messages-group-archive",
+ route: "userPrivateMessages.group.archive",
+ routeParams: [group],
+ label: "user.messages.archive",
+ icon: "box-archive",
+ },
+ ]
+ : []),
+ ];
+ }
+
+ return [
+ {
+ name: "messages-latest",
+ route: "userPrivateMessages.user.index",
+ label: "categories.latest",
+ icon: "envelope",
+ },
+ {
+ name: "messages-sent",
+ route: "userPrivateMessages.user.sent",
+ label: "user.messages.sent",
+ icon: "reply",
+ },
+ ...(viewingSelf
+ ? [
+ {
+ name: "messages-new",
+ route: "userPrivateMessages.user.new",
+ label: "user.messages.new",
+ icon: "circle-exclamation",
+ count: (context) =>
+ pmCount(context, "new", { inboxFilter: "user" }),
+ },
+ {
+ name: "messages-unread",
+ route: "userPrivateMessages.user.unread",
+ label: "user.messages.unread",
+ icon: "circle-plus",
+ count: (context) =>
+ pmCount(context, "unread", { inboxFilter: "user" }),
+ },
+ ]
+ : []),
+ {
+ name: "messages-archive",
+ route: "userPrivateMessages.user.archive",
+ label: "user.messages.archive",
+ icon: "box-archive",
+ },
+ ];
+}
+
+function pmCount({ pmTopicTrackingState }, type, opts) {
+ return pmTopicTrackingState?.lookupCount(type, opts) ?? 0;
+}
+
+// The inboxes `MessagesDropdown` offers, rebuilt for the section's drawer.
+function messageInboxes({ user, router, site }) {
+ const username = user?.username_lower || user?.username?.toLowerCase();
+
+ if (!username) {
+ return [];
+ }
+
+ const inboxes = [
+ {
+ id: "inbox",
+ title: i18n("user.messages.inbox"),
+ icon: "inbox",
+ route: "userPrivateMessages.user",
+ models: [username],
+ countOpts: { inboxFilter: "user" },
+ },
+ ...(user.groupsWithMessages || []).map(({ name }) => ({
+ id: `group-${name}`,
+ title: name,
+ icon: "inbox",
+ route: "userPrivateMessages.group",
+ models: [username, name],
+ countOpts: { inboxFilter: "group", groupName: name },
+ })),
+ ];
+
+ if (site?.can_tag_pms) {
+ inboxes.push({
+ id: "tags",
+ title: i18n("user.messages.tags"),
+ icon: "tags",
+ route: "userPrivateMessages.tags",
+ models: [username],
+ });
+ }
+
+ return inboxes.filter((inbox) =>
+ routeExists(router, inbox.route, inbox.models)
+ );
+}
+
+// The inbox picker rides in the drawer that leads the messages section. Below
+// one inbox there is nothing to pick between.
+function messageDrawerLinks(context) {
+ const inboxes = messageInboxes(context);
+
+ return inboxes.length > 1
+ ? inboxes.map((inbox) => ({
+ name: inbox.id,
+ route: inbox.route,
+ routeParams: inbox.models.slice(1),
+ text: inbox.title,
+ icon: inbox.icon,
+ classNames: "user-nav-sidebar-link --inbox",
+ count: inbox.countOpts
+ ? (ctx) =>
+ pmCount(ctx, "new", inbox.countOpts) +
+ pmCount(ctx, "unread", inbox.countOpts)
+ : undefined,
+ }))
+ : [];
+}
+
+// The `displayed` predicates delegate to the `user` controller wherever the
+// horizontal navs do, since it already owns these rules and is live on every
+// route the panel covers.
+const NAV_SECTIONS = [
+ {
+ name: "profile",
+ hideSectionHeader: true,
+ links: () => PROFILE_LINKS,
+ },
+ {
+ name: "activity",
+ title: "user.activity_stream",
+ displayed: ({ user, controller }) =>
+ !user?.profile_hidden && controller?.showActivityTab,
+ links: () => ACTIVITY_LINKS,
+ },
+ {
+ name: "notifications",
+ title: "user.notifications",
+ displayed: ({ controller }) => controller?.showNotificationsTab,
+ links: () => NOTIFICATION_LINKS,
+ },
+ {
+ name: "messages",
+ title: "user.private_messages",
+ displayed: ({ controller }) => controller?.showPrivateMessages,
+ links: messageLinks,
+ moreLinks: messageDrawerLinks,
+ moreLinksPosition: "start",
+ moreLinksTriggerPrefixType: "icon",
+ moreLinksTriggerPrefixValue: "inbox",
+ moreLinksTriggerSuffixType: "icon",
+ moreLinksTriggerSuffixValue: "chevron-down",
+ // The trigger names the current inbox, so it must not also be listed above.
+ moreLinksHoistActiveLink: false,
+ moreLinksTriggerText: ({ owner }) => {
+ const messages = owner.lookup("controller:user-private-messages");
+
+ return messages?.isGroup && messages?.group?.name
+ ? messages.group.name
+ : i18n("user.messages.inbox");
+ },
+ headerActionsIcon: "plus",
+ headerActions: ({ owner, controller }) =>
+ controller?.showPrivateMessages && controller?.viewingSelf
+ ? [
+ {
+ id: "new-message",
+ title: i18n("user.new_private_message"),
+ action: () => owner.lookup("service:composer").openNewMessage({}),
+ },
+ ]
+ : [],
+ },
+ {
+ name: "invites",
+ title: "user.invited.title",
+ // Mirrors `can_see_invite_details` in `routes/user-invited.js`.
+ displayed: ({ controller, currentUser, user }) =>
+ controller?.canInviteToForum &&
+ (currentUser?.staff || currentUser?.id === user?.id),
+ links: () => INVITE_LINKS,
+ headerActionsIcon: "plus",
+ headerActions: ({ owner, controller, currentUser, user }) =>
+ controller?.canInviteToForum && currentUser?.id === user?.id
+ ? [
+ {
+ id: "create-invite",
+ title: i18n("user.invited.create"),
+ action: () => {
+ // `showCreateInviteModal` picks the right modal variant for
+ // the site; it just needs something owned to look up from, and
+ // reads `model.editing` even when opened fresh.
+ const context = {};
+ setOwner(context, owner);
+ showCreateInviteModal(context, { model: { invites: [] } });
+ },
+ },
+ ]
+ : [],
+ },
+ {
+ name: "preferences",
+ title: "user.preferences.title",
+ // Staff can open someone else's preferences, so this follows `can_edit`
+ // rather than "is this me".
+ displayed: ({ user }) => !!user?.can_edit,
+ links: () => [...PREFERENCES_LINKS, ...additionalPreferencesLinks],
+ },
+];
+
+/**
+ * Routes differ between deploys, and a plugin route may not be installed, so
+ * anything the router cannot build a URL for is dropped rather than left to
+ * throw from `<LinkTo>` while the sidebar renders.
+ */
+export function routeExists(router, route, models = []) {
+ try {
+ router.urlFor(route, ...models);
+ return true;
+ } catch {
+ return false;
+ }
+}
+
+/**
+ * `resetNamespace` routes such as `userActivity` and `preferences` keep `user`
+ * as their parent even though their names don't show it, so walking the
+ * RouteInfo chain catches every tab — including ones added by plugins.
+ */
+export function isUserRoute(routeInfo) {
+ for (let info = routeInfo; info; info = info.parent) {
+ if (info.name === "user") {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+// The `user` controller owns the nav visibility rules and holds the user being
+// viewed, which is not necessarily the current user.
+function navContext(owner) {
+ const controller = owner.lookup("controller:user");
+
+ return {
+ owner,
+ controller,
+ user: controller?.model,
+ currentUser: owner.lookup("service:current-user"),
+ pmTopicTrackingState: owner.lookup("service:pm-topic-tracking-state"),
+ router: owner.lookup("service:router"),
+ site: owner.lookup("service:site"),
+ siteSettings: owner.lookup("service:site-settings"),
+ };
+}
+
+function resolveLink(link, context) {
+ // Unread state is tracked for the current user only, so it says nothing
+ // about the person whose profile this is.
+ const viewingSelf = context.currentUser?.id === context.user?.id;
+ const href = typeof link.href === "function" ? link.href(context) : link.href;
+
+ return {
+ ...link,
+ count: viewingSelf && link.count ? link.count(context) : 0,
+ showCount: context.currentUser?.sidebarShowCountOfNewItems,
+ // `<LinkTo>` marks a route-backed link active by itself; an href link has
+ // to report it. Left undefined otherwise, since a boolean here would also
+ // override the router's answer for the route-backed ones.
+ currentWhen: href
+ ? !!context.router.currentURL?.startsWith(withoutPrefix(href))
+ : undefined,
+ href,
+ models: [context.user.username, ...(link.routeParams || [])],
+ text:
+ typeof link.text === "function"
+ ? link.text(context)
+ : link.text || i18n(link.label),
+ };
+}
+
+class UserNavSectionLink extends BaseCustomSidebarSectionLink {
+ constructor(linkConfig) {
+ super(...arguments);
+ this.linkConfig = linkConfig;
+ }
+
+ get name() {
+ return `user-nav-${this.linkConfig.name}`;
+ }
+
+ get classNames() {
+ return this.linkConfig.classNames || "user-nav-sidebar-link";
+ }
+
+ // Count when the viewer asked for counts, a plain dot otherwise — the same
+ // trade the community section's links make.
+ get badgeText() {
+ return this.linkConfig.showCount && this.linkConfig.count;
+ }
+
+ get suffixCSSClass() {
+ return "unread";
+ }
+
+ get suffixType() {
+ return "icon";
+ }
+
+ get suffixValue() {
+ if (!this.linkConfig.showCount && this.linkConfig.count > 0) {
+ return "circle";
+ }
+ }
+
+ get currentWhen() {
+ return this.linkConfig.currentWhen;
+ }
+
+ get route() {
+ return this.linkConfig.route;
+ }
+
+ get href() {
+ return this.linkConfig.href;
+ }
+
+ get models() {
+ return this.linkConfig.models;
+ }
+
+ get text() {
+ return this.linkConfig.text;
+ }
+
+ get title() {
+ return this.text;
+ }
+
+ get prefixType() {
+ return "icon";
+ }
+
+ get prefixValue() {
+ return this.linkConfig.icon;
+ }
+}
+
+function buildSection(config) {
+ return class UserNavSection extends BaseCustomSidebarSection {
+ name = `user-nav-${config.name}`;
+ hideSectionHeader = !!config.hideSectionHeader;
+ // Everything below the header-less list starts folded; the panel's
+ // `expandActiveSection` opens whichever one you are inside.
+ collapsedByDefault = !config.hideSectionHeader;
+
+ get text() {
+ return config.title ? i18n(config.title) : "";
+ }
+
+ get links() {
+ return buildLinks(config.links, getOwner(this));
+ }
+
+ get moreLinks() {
+ return config.moreLinks
+ ? buildLinks(config.moreLinks, getOwner(this))
+ : [];
+ }
+
+ get actions() {
+ return config.headerActions
+ ? config.headerActions(navContext(getOwner(this)))
+ : undefined;
+ }
+
+ get actionsIcon() {
+ return config.headerActionsIcon;
+ }
+
+ get moreLinksHoistActiveLink() {
+ return config.moreLinksHoistActiveLink ?? true;
+ }
+
+ get moreLinksPosition() {
+ return config.moreLinksPosition || "end";
+ }
+
+ get moreLinksTriggerPrefixType() {
+ return config.moreLinksTriggerPrefixType;
+ }
+
+ get moreLinksTriggerPrefixValue() {
+ return config.moreLinksTriggerPrefixValue;
+ }
+
+ get moreLinksTriggerSuffixType() {
+ return config.moreLinksTriggerSuffixType;
+ }
+
+ get moreLinksTriggerSuffixValue() {
+ return config.moreLinksTriggerSuffixValue;
+ }
+
+ get moreLinksTriggerText() {
+ const { moreLinksTriggerText } = config;
+
+ return typeof moreLinksTriggerText === "function"
+ ? moreLinksTriggerText(navContext(getOwner(this)))
+ : moreLinksTriggerText;
+ }
+
+ get displaySection() {
+ if (config.displayed && !config.displayed(navContext(getOwner(this)))) {
+ return false;
+ }
+
+ return this.links.length > 0 || this.moreLinks.length > 0;
+ }
+ };
+}
+
+function buildLinks(builder, owner) {
+ const context = navContext(owner);
+
+ if (!context.user?.username) {
+ return [];
+ }
+
+ return builder(context)
+ .filter((link) => !link.displayed || link.displayed(context))
+ .map((link) => resolveLink(link, context))
+ .filter(
+ (link) =>
+ link.href || routeExists(context.router, link.route, link.models)
+ )
+ .map((link) => new UserNavSectionLink(link));
+}
+
+export default class UserNavSidebarPanel extends BaseCustomSidebarPanel {
+ key = USER_NAV_PANEL;
+ // A hidden panel never renders a switch button and is skipped in combined
+ // mode, so it is only ever reachable by being forced — the same way the admin
+ // panel behaves.
+ hidden = true;
+ displayHeader = true;
+ filterable = true;
+ filterableMinLinks = 10;
+ expandActiveSection = true;
+ scrollActiveLinkIntoView = true;
+
+ // The panel also serves a user's admin page, which is reachable from the
+ // admin area as well as from a profile. Sending someone who arrived from
+ // admin back to the forum would drop them somewhere they never were.
+ get backLink() {
+ const state = getOwnerWithFallback(this).lookup(
+ "service:user-nav-sidebar-state-manager"
+ );
+
+ return state.enteredFromAdmin
+ ? { href: getURL(state.entryURL), label: "sidebar.back_to_admin" }
+ : undefined;
+ }
+
+ @cached
+ get sections() {
+ return NAV_SECTIONS.map(buildSection);
+ }
+}
diff --git a/frontend/discourse/app/routes/user.js b/frontend/discourse/app/routes/user.js
index fae11f0abb9..48583f06a2d 100644
--- a/frontend/discourse/app/routes/user.js
+++ b/frontend/discourse/app/routes/user.js
@@ -11,6 +11,7 @@ export default class UserRoute extends DiscourseRoute {
@service("search") searchService;
@service appEvents;
@service messageBus;
+ @service userNavSidebarStateManager;
beforeModel() {
if (this.siteSettings.hide_user_profiles_from_public && !this.currentUser) {
@@ -67,6 +68,8 @@ export default class UserRoute extends DiscourseRoute {
`/u/${user.username_lower}/counters`,
this.onUserCountersMessage
);
+
+ this.userNavSidebarStateManager.forceUserNavSidebar();
}
deactivate() {
@@ -85,6 +88,8 @@ export default class UserRoute extends DiscourseRoute {
// Remove the search context
this.searchService.searchContext = null;
+
+ this.userNavSidebarStateManager.stopForcingUserNavSidebar();
}
@bind
diff --git a/frontend/discourse/app/services/user-nav-sidebar-state-manager.js b/frontend/discourse/app/services/user-nav-sidebar-state-manager.js
new file mode 100644
index 00000000000..583a9282588
--- /dev/null
+++ b/frontend/discourse/app/services/user-nav-sidebar-state-manager.js
@@ -0,0 +1,68 @@
+import { tracked } from "@glimmer/tracking";
+import Service, { service } from "@ember/service";
+import scrollLock from "discourse/lib/scroll-lock";
+import { MAIN_PANEL, USER_NAV_PANEL } from "discourse/lib/sidebar/panels";
+
+/**
+ * Hands the sidebar over to the user nav panel while the user routes are
+ * active, and gives it back on the way out — the same trade
+ * `AdminSidebarStateManager` makes for the admin area.
+ */
+export default class UserNavSidebarStateManager extends Service {
+ @service header;
+ @service routeHistory;
+ @service sidebarState;
+ @service siteSettings;
+
+ /**
+ * Where the viewer was before they opened a user's admin page. Captured on
+ * arrival rather than read from history as they go, so that moving between
+ * that page's own tabs doesn't rewrite where they came from.
+ */
+ @tracked entryURL = null;
+
+ get enteredFromAdmin() {
+ return !!this.entryURL?.startsWith("/admin");
+ }
+
+ get enabled() {
+ return this.siteSettings.sidebar_user_navigation;
+ }
+
+ captureEntryPoint() {
+ this.entryURL = this.enabled ? (this.routeHistory.lastURL ?? null) : null;
+ }
+
+ clearEntryPoint() {
+ this.entryURL = null;
+ }
+
+ forceUserNavSidebar() {
+ if (!this.enabled) {
+ return false;
+ }
+
+ this.sidebarState.setPanel(USER_NAV_PANEL);
+ this.sidebarState.setSeparatedMode();
+ this.sidebarState.hideSwitchPanelButtons();
+ this.sidebarState.isForcingSidebar = true;
+ this.sidebarState.forcingSidebarPanel = USER_NAV_PANEL;
+
+ if (this.sidebarState.sidebarHidden) {
+ this.header.hamburgerVisible = false;
+ scrollLock(false);
+ }
+
+ return true;
+ }
+
+ stopForcingUserNavSidebar() {
+ if (this.sidebarState.forcingSidebarPanel !== USER_NAV_PANEL) {
+ return;
+ }
+
+ this.sidebarState.setPanel(MAIN_PANEL);
+ this.sidebarState.isForcingSidebar = false;
+ this.sidebarState.forcingSidebarPanel = null;
+ }
+}
diff --git a/frontend/discourse/app/templates/user.gjs b/frontend/discourse/app/templates/user.gjs
index fa725dd542d..fcc7d7da93a 100644
--- a/frontend/discourse/app/templates/user.gjs
+++ b/frontend/discourse/app/templates/user.gjs
@@ -4,6 +4,7 @@ import { trustHTML } from "@ember/template";
import PluginOutlet from "discourse/components/plugin-outlet";
import UserNav from "discourse/components/user-nav";
import UserProfileAvatar from "discourse/components/user-profile-avatar";
+import bodyClass from "discourse/helpers/body-class";
import formatUsername from "discourse/helpers/format-username";
import lazyHash from "discourse/helpers/lazy-hash";
import routeAction from "discourse/helpers/route-action";
@@ -19,6 +20,10 @@ import { i18n } from "discourse-i18n";
import CollapsedInfo from "./user/collapsed-info";
export default <template>
+ {{#if @controller.userNavPanelActive}}
+ {{bodyClass "user-nav-panel-active"}}
+ {{/if}}
+
<PluginOutlet
@connectorTagName="div"
@name="above-user-profile"
diff --git a/frontend/discourse/tests/helpers/qunit-helpers.js b/frontend/discourse/tests/helpers/qunit-helpers.js
index f80ee04a8d2..bbccfea33cb 100644
--- a/frontend/discourse/tests/helpers/qunit-helpers.js
+++ b/frontend/discourse/tests/helpers/qunit-helpers.js
@@ -77,6 +77,7 @@ import { resetLogSearchLinkClickedCallbacks } from "discourse/lib/search";
import { clearAdditionalAdminSidebarSectionLinks } from "discourse/lib/sidebar/admin-sidebar";
import { resetDefaultSectionLinks as resetTopicsSectionLinks } from "discourse/lib/sidebar/custom-community-section-links";
import { resetSidebarPanels } from "discourse/lib/sidebar/custom-sections";
+import { clearAdditionalUserNavPreferencesLinks } from "discourse/lib/sidebar/user-nav-sidebar";
import {
resetHighestReadCache,
setTopicList,
@@ -282,6 +283,7 @@ export function testCleanup(container, app) {
resetBeforeAuthCompleteCallbacks();
clearPopupMenuOptions();
clearAdditionalAdminSidebarSectionLinks();
+ clearAdditionalUserNavPreferencesLinks();
resetAdminPluginConfigNav();
resetTransformers();
rollbackAllPrepends();
diff --git a/plugins/chat/assets/javascripts/discourse/initializers/chat-setup.js b/plugins/chat/assets/javascripts/discourse/initializers/chat-setup.js
index 459cec209d7..840d0554962 100644
--- a/plugins/chat/assets/javascripts/discourse/initializers/chat-setup.js
+++ b/plugins/chat/assets/javascripts/discourse/initializers/chat-setup.js
@@ -32,6 +32,15 @@ class ChatSetupInit {
this.appEvents.on("discourse:focus-changed", this, "_handleFocusChanged");
withPluginApi((api) => {
+ api.addUserNavPreferencesLink({
+ name: "preferences-chat",
+ route: "preferences.chat",
+ label: "chat.title_capitalized",
+ icon: "d-chat",
+ displayed: ({ siteSettings, currentUser, user }) =>
+ siteSettings.chat_enabled && (user?.can_chat || currentUser?.admin),
+ });
+
api.registerReviewableComponent(
"ReviewableChatMessage",
async () =>
diff --git a/plugins/discourse-rewind/assets/javascripts/discourse/initializers/rewind-setup.js b/plugins/discourse-rewind/assets/javascripts/discourse/initializers/rewind-setup.js
index 0b64a615177..d11f2aa34db 100644
--- a/plugins/discourse-rewind/assets/javascripts/discourse/initializers/rewind-setup.js
+++ b/plugins/discourse-rewind/assets/javascripts/discourse/initializers/rewind-setup.js
@@ -18,6 +18,19 @@ export default {
}
withPluginApi((api) => {
+ api.addUserNavPreferencesLink({
+ name: "preferences-rewind",
+ route: "preferences.rewind",
+ label: "discourse_rewind.title",
+ icon: "repeat",
+ // Same conditions as `RewindPreferencesNav` in the horizontal nav: the
+ // site setting gates the tab so it does not vanish when a user turns
+ // rewind off for themselves, and `active` reflects the viewer's state.
+ displayed: ({ siteSettings, owner }) =>
+ siteSettings.discourse_rewind_enabled &&
+ !!owner.lookup("service:rewind")?.active,
+ });
+
if (this.rewind.enabled) {
api.addQuickAccessProfileItem({
icon: "repeat",
diff --git a/spec/integrity/user_nav_sidebar_icons_spec.rb b/spec/integrity/user_nav_sidebar_icons_spec.rb
new file mode 100644
index 00000000000..2ff9e139ce0
--- /dev/null
+++ b/spec/integrity/user_nav_sidebar_icons_spec.rb
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+RSpec.describe "user nav sidebar icons" do
+ it "only names icons the sprite ships" do
+ source = File.read(Rails.root.join("frontend/discourse/app/lib/sidebar/user-nav-sidebar.js"))
+ icons = source.scan(/\bicon: "([^"]+)"/).flatten.uniq
+
+ expect(icons).not_to be_empty
+ expect(icons - SvgSprite.all_icons).to be_empty
+ end
+end
diff --git a/spec/system/user_nav_sidebar_spec.rb b/spec/system/user_nav_sidebar_spec.rb
new file mode 100644
index 00000000000..6858ec59d13
--- /dev/null
+++ b/spec/system/user_nav_sidebar_spec.rb
@@ -0,0 +1,293 @@
+# frozen_string_literal: true
+
+RSpec.describe "User nav sidebar" do
+ fab!(:current_user) { Fabricate(:admin, username: "alice", refresh_auto_groups: true) }
+ fab!(:other_user) { Fabricate(:user, username: "bob", refresh_auto_groups: true) }
+ fab!(:group) { Fabricate(:group, name: "cats", has_messages: true) }
+ fab!(:group_message) do
+ Fabricate(:group_private_message_topic, user: current_user, recipient_group: group)
+ end
+
+ let(:panel) { "#d-sidebar .sidebar-sections.user-nav-panel" }
+ let(:sidebar_dropdown) { PageObjects::Components::SidebarHeaderDropdown.new }
+
+ before do
+ SiteSetting.navigation_menu = "sidebar"
+ SiteSetting.sidebar_user_navigation = true
+ group.add(current_user)
+ sign_in(current_user) unless RSpec.current_example.metadata[:anonymous]
+ end
+
+ def section(name)
+ "#{panel} .sidebar-section-wrapper[data-section-name='user-nav-#{name}']"
+ end
+
+ it "takes over the sidebar on user routes and hides the navs it replaces" do
+ visit("/u/alice/summary")
+
+ expect(page).to have_css(panel)
+ expect(page).to have_no_css(".user-navigation-primary")
+ expect(page).to have_no_css("#d-sidebar .sidebar__panel-switch-button")
+ expect(page).to have_css(".sidebar-filter__input")
+
+ within(panel) do
+ expect(page).to have_link("Summary")
+ expect(page).to have_css("[data-section-name='user-nav-messages']")
+ end
+ end
+
+ it "keeps the panel across every user tab and hands the sidebar back on the way out" do
+ visit("/u/alice/activity")
+ expect(page).to have_css(panel)
+
+ visit("/u/alice/preferences/account")
+ expect(page).to have_css(panel)
+
+ visit("/latest")
+
+ expect(page).to have_no_css(panel)
+ expect(page).to have_css("#d-sidebar .sidebar-section-wrapper")
+ end
+
+ it "navigates between tabs from the panel" do
+ visit("/u/alice/activity")
+
+ find(panel).click_link("Summary")
+
+ expect(page).to have_current_path("/u/alice/summary")
+ expect(page).to have_css(
+ "#d-sidebar .sidebar-section-link.active[data-link-name='user-nav-summary']",
+ )
+ end
+
+ it "expands the section you are inside and nests its horizontal nav" do
+ visit("/u/alice/activity")
+
+ expect(page).to have_no_css(".user-navigation-secondary")
+ expect(page).to have_css("#{section("activity")}.sidebar-section--expanded")
+
+ # Read, Drafts and Bookmarks are gated on the user controller rather than
+ # the user model, so they are easy to drop by accident.
+ within(section("activity")) do
+ %w[All Topics Replies Likes Read Drafts Bookmarks].each do |label|
+ expect(page).to have_link(label)
+ end
+ end
+ end
+
+ it "links staff to the admin page for the user being viewed" do
+ visit("/u/bob/summary")
+
+ expect(find(panel)).to have_link("Manage user", href: "/admin/users/#{other_user.id}/bob")
+ expect(find("#{section("profile")} .sidebar-section-link", match: :first).text).to eq(
+ "Manage user",
+ )
+ # The panel carries it now, so the profile button would be a duplicate.
+ expect(page).to have_no_css(".controls .user-admin")
+
+ find(panel).click_link("Manage user")
+
+ # An href link gets no active state from <LinkTo>, so the panel has to
+ # report it, and must keep reporting it on the page's sub-routes.
+ expect(page).to have_css(
+ "#{panel} .sidebar-section-link.active[data-link-name='user-nav-admin']",
+ )
+ end
+
+ it "keeps the panel on a user's admin page and leaves the back link alone" do
+ visit("/u/bob/summary")
+ find(panel).click_link("Manage user")
+
+ expect(page).to have_current_path("/admin/users/#{other_user.id}/bob")
+ expect(page).to have_css(panel)
+ within(panel) { expect(page).to have_link("Summary") }
+ expect(page).to have_css(".sidebar-sections__back-to-forum", text: "Back to Forum")
+ end
+
+ it "points the back link at admin when the admin area was the entry point" do
+ visit("/admin/users/list/active")
+ click_link("bob")
+
+ expect(page).to have_current_path("/admin/users/#{other_user.id}/bob")
+ expect(page).to have_css(panel)
+ expect(page).to have_css(".sidebar-sections__back-to-forum", text: "Back to Admin")
+ # Came from the users list, so its header and tabs are the trail back.
+ expect(page).to have_css(".admin-users.admin-config-page")
+ end
+
+ it "drops the users config header when the profile was the entry point" do
+ visit("/u/bob/summary")
+ find(panel).click_link("Manage user")
+
+ expect(page).to have_current_path("/admin/users/#{other_user.id}/bob")
+ expect(page).to have_no_css(".admin-users.admin-config-page")
+ end
+
+ it "keeps the panel when the admin page hands back to a profile" do
+ visit("/admin/users/#{other_user.id}/bob")
+ expect(page).to have_css(panel)
+
+ find(panel).click_link("Summary")
+
+ expect(page).to have_current_path("/u/bob/summary")
+ expect(page).to have_css(panel)
+ end
+
+ it "scopes the messages section to the selected inbox" do
+ visit("/u/alice/messages")
+
+ within(section("messages")) do
+ %w[Latest Sent New Unread Archive].each { |label| expect(page).to have_link(label) }
+ end
+
+ # The bar keeps the controls that live in it; only the parts the panel
+ # replaces go.
+ expect(page).to have_css(".user-navigation-secondary .navigation-controls")
+ expect(page).to have_no_css(".user-navigation-secondary .messages-nav a")
+
+ visit("/u/alice/messages/group/cats")
+
+ within(section("messages")) do
+ expect(page).to have_link("Latest")
+ expect(page).to have_no_link("Sent")
+ end
+ end
+
+ def link_suffix(name)
+ "#{panel} .sidebar-section-link[data-link-name='user-nav-#{name}'] " \
+ ".sidebar-section-link-suffix.icon.unread"
+ end
+
+ def link_badge(name)
+ "#{panel} .sidebar-section-link[data-link-name='user-nav-#{name}'] " \
+ ".sidebar-section-link-content-badge"
+ end
+
+ it "marks drafts, unread messages and notifications, as a dot or a count" do
+ # Never read, so it counts as new rather than unread.
+ Fabricate(:private_message_post, user: other_user, recipient: current_user)
+ Fabricate(:notification, user: current_user, read: false)
+ Draft.set(current_user, "#{Draft::NEW_TOPIC}_1", 0, { reply: "a draft" }.to_json)
+
+ visit("/u/alice/messages")
+ expect(page).to have_css(link_suffix("messages-new"))
+
+ visit("/u/alice/notifications")
+ expect(page).to have_css(link_suffix("notifications-all"))
+
+ # The count belongs in the suffix, not folded into the label.
+ visit("/u/alice/activity")
+ expect(page).to have_link("Drafts")
+ expect(page).to have_css(link_suffix("activity-drafts"))
+
+ current_user.user_option.update!(sidebar_show_count_of_new_items: true)
+
+ visit("/u/alice/messages")
+ expect(page).to have_css(link_badge("messages-new"), text: "1")
+ expect(page).to have_no_css(link_suffix("messages-new"))
+
+ visit("/u/alice/activity")
+ expect(page).to have_link("Drafts")
+ expect(page).to have_css(link_badge("activity-drafts"), text: "1")
+ end
+
+ it "leaves the counts off someone else's profile, since they track the viewer" do
+ Fabricate(:private_message_post, user: other_user, recipient: current_user)
+
+ visit("/u/bob/messages")
+
+ expect(page).to have_css(panel)
+ expect(page).to have_no_css(link_suffix("messages-new"))
+ expect(page).to have_no_css(link_badge("messages-new"))
+ end
+
+ it "hides the horizontal navs on narrow screens, where the menu button serves the panel",
+ mobile: true do
+ visit("/u/alice/activity")
+
+ expect(page).to have_no_css(".user-navigation-primary")
+ expect(page).to have_no_css(".user-navigation-secondary")
+
+ sidebar_dropdown.click
+
+ expect(page).to have_css(
+ ".sidebar-sections.user-nav-panel .sidebar-section-link[data-link-name='user-nav-summary']",
+ )
+ end
+
+ it "switches inbox from the drawer on narrow screens", mobile: true do
+ visit("/u/alice/messages")
+ sidebar_dropdown.click
+
+ find(".sidebar-sections.user-nav-panel .sidebar-more-section-links-details-summary").click
+ find(".fk-d-menu-modal .sidebar-section-link", text: "cats").click
+
+ expect(page).to have_current_path("/u/alice/messages/group/cats")
+ # Picking an inbox is a navigation, so the menu gets out of the way.
+ expect(page).to have_no_css(".sidebar-hamburger-dropdown")
+ end
+
+ it "serves the panel to anonymous visitors", anonymous: true do
+ # A brand new user's profile is hidden from anonymous visitors, which would
+ # leave the panel with nothing to show.
+ SiteSetting.hide_new_user_profiles = false
+
+ visit("/u/bob")
+
+ expect(page).to have_css(panel)
+ expect(page).to have_no_css(".user-navigation-primary")
+ within(panel) { expect(page).to have_link("Summary") }
+
+ # Everything that depends on who is viewing stays out.
+ expect(page).to have_no_css(section("preferences"))
+ expect(page).to have_no_css(section("messages"))
+ expect(page).to have_no_link("Manage user")
+
+ # Too few links left to be worth filtering.
+ expect(page).to have_no_css(".sidebar-filter__input")
+ end
+
+ it "drops the messages bar when nothing is left in it" do
+ # Someone else's inbox offers no new-message button, and the rest of the bar
+ # is what the panel replaced, so the whole thing would be an empty shell.
+ visit("/u/bob/messages")
+
+ expect(page).to have_css(section("messages"))
+ expect(page).to have_no_css(".user-navigation-secondary")
+ end
+
+ it "defers to the user controller for conditional tabs" do
+ visit("/u/alice/summary")
+ expect(page).to have_css(panel)
+ expect(page).to have_no_link("Badges")
+
+ BadgeGranter.grant(Badge.find(Badge::Autobiographer), current_user)
+
+ visit("/u/alice/summary")
+ within(panel) { expect(page).to have_link("Badges") }
+ end
+
+ it "leaves preferences to the panel rather than a button on your own profile" do
+ visit("/u/alice/summary")
+
+ expect(page).to have_no_css(".controls .user-preferences-btn")
+ expect(page).to have_css(section("preferences"))
+ end
+
+ it "leaves the horizontal navs alone while the change is off" do
+ SiteSetting.sidebar_user_navigation = false
+
+ visit("/u/alice/summary")
+
+ expect(page).to have_css(".user-navigation-primary")
+ expect(page).to have_no_css(panel)
+
+ # The admin user route records the entry point on every visit, so the
+ # header it drives must stay put while the change is off.
+ visit("/u/bob/summary")
+ find(".controls .user-admin").click
+
+ expect(page).to have_current_path("/admin/users/#{other_user.id}/bob")
+ expect(page).to have_css(".admin-users.admin-config-page")
+ end
+end