From 37030ed348fcca5c2b39af53e9c1a17dc0e2393c Mon Sep 17 00:00:00 2001 From: Jarek Radosz Date: Fri, 16 Jun 2023 16:36:50 +0200 Subject: [PATCH] DEV: Convert d-navigation-item to glimmer (#22155) --- .../app/components/d-navigation-item.hbs | 13 +++- .../app/components/d-navigation-item.js | 62 ++++++++----------- .../discourse/app/components/user-nav.hbs | 14 ++--- .../discourse/app/templates/preferences.hbs | 18 +++--- .../templates/user-private-messages-group.hbs | 12 ++-- .../templates/user-private-messages-user.hbs | 15 ++--- .../discourse/app/templates/user/activity.hbs | 18 +++--- .../app/templates/user/notifications.hbs | 10 +-- 8 files changed, 74 insertions(+), 88 deletions(-) diff --git a/app/assets/javascripts/discourse/app/components/d-navigation-item.hbs b/app/assets/javascripts/discourse/app/components/d-navigation-item.hbs index d3fc03d783d..66b1018c4fb 100644 --- a/app/assets/javascripts/discourse/app/components/d-navigation-item.hbs +++ b/app/assets/javascripts/discourse/app/components/d-navigation-item.hbs @@ -1,3 +1,10 @@ - - {{yield}} - \ No newline at end of file +
  • + + {{yield}} + +
  • \ No newline at end of file diff --git a/app/assets/javascripts/discourse/app/components/d-navigation-item.js b/app/assets/javascripts/discourse/app/components/d-navigation-item.js index ec9e17dd22b..3aee34f7a31 100644 --- a/app/assets/javascripts/discourse/app/components/d-navigation-item.js +++ b/app/assets/javascripts/discourse/app/components/d-navigation-item.js @@ -1,41 +1,29 @@ -import Component from "@ember/component"; -import { computed } from "@ember/object"; +import Component from "@glimmer/component"; import { inject as service } from "@ember/service"; -export default Component.extend({ - tagName: "li", +export default class DNavigationItem extends Component { + @service router; - route: null, - - router: service(), - - attributeBindings: ["ariaCurrent:aria-current", "title"], - - ariaCurrent: computed( - "router.currentRouteName", - "router.currentRoute.parent.name", - "route", - "ariaCurrentContext", - function () { - let ariaCurrentValue = "page"; - - // when there are multiple levels of navigation - // we want the active parent to get `aria-current="page"` - // and the active child to get `aria-current="location"` - if (this.ariaCurrentContext === "subNav") { - ariaCurrentValue = "location"; - } else if (this.ariaCurrentContext === "parentNav") { - if ( - this.router.currentRouteName !== this.route && // not the current route - this.router.currentRoute.parent.name.includes(this.route) // but is the current parent route - ) { - return "page"; - } - } - - return this.router.currentRouteName === this.route - ? ariaCurrentValue - : null; + get ariaCurrent() { + // when there are multiple levels of navigation + // we want the active parent to get `aria-current="page"` + // and the active child to get `aria-current="location"` + if ( + this.args.ariaCurrentContext === "parentNav" && + this.router.currentRouteName !== this.args.route && // not the current route + this.router.currentRoute.parent.name.includes(this.args.route) // but is the current parent route + ) { + return "page"; } - ), -}); + + if (this.router.currentRouteName !== this.args.route) { + return null; + } + + if (this.args.ariaCurrentContext === "subNav") { + return "location"; + } else { + return "page"; + } + } +} diff --git a/app/assets/javascripts/discourse/app/components/user-nav.hbs b/app/assets/javascripts/discourse/app/components/user-nav.hbs index c894eef5847..9fad9589576 100644 --- a/app/assets/javascripts/discourse/app/components/user-nav.hbs +++ b/app/assets/javascripts/discourse/app/components/user-nav.hbs @@ -4,15 +4,15 @@ @ariaLabel="User primary" > {{#unless @user.profile_hidden}} - + {{d-icon "user"}} {{i18n "user.summary.title"}} {{d-icon "stream"}} {{i18n "user.activity_stream"}} @@ -23,8 +23,8 @@ {{#if @showNotificationsTab}} {{d-icon "bell" class="glyph"}} {{i18n "user.notifications"}} @@ -34,8 +34,8 @@ {{#if @showPrivateMessages}} {{d-icon "envelope"}} {{i18n "user.private_messages"}} @@ -45,8 +45,8 @@ {{#if @canInviteToForum}} {{d-icon "user-plus"}} {{i18n "user.invited.title"}} @@ -54,7 +54,7 @@ {{/if}} {{#if @showBadges}} - + {{d-icon "certificate"}} {{i18n "badges.title"}} @@ -69,8 +69,8 @@ {{#if @user.can_edit}} {{d-icon "cog"}} {{i18n "user.preferences"}} diff --git a/app/assets/javascripts/discourse/app/templates/preferences.hbs b/app/assets/javascripts/discourse/app/templates/preferences.hbs index bde5fc4dd19..cc8cfd4da26 100644 --- a/app/assets/javascripts/discourse/app/templates/preferences.hbs +++ b/app/assets/javascripts/discourse/app/templates/preferences.hbs @@ -4,8 +4,8 @@