From 4b561277a95adcbd99e89718fd5af29be05692af Mon Sep 17 00:00:00 2001 From: Alan Guo Xiang Tan Date: Wed, 28 Sep 2022 09:58:07 +0800 Subject: [PATCH] FEATURE: Add review link to community section for logged in user (#18374) When there are pending reviewables, the review section link is displayed in the main section. When there are no pending reviewables, the review section link is displayed under the more links drawer. Internal ref: /t/74210 --- .../app/components/reviewable-item.js | 4 +- .../sidebar/common/community-section.js | 40 ++++++---- .../components/sidebar/more-section-links.hbs | 2 +- .../sidebar/user/community-section.js | 35 +++++++- .../subscribe-user-notifications.js | 4 +- .../community-section/review-section-link.js | 33 ++++++++ .../javascripts/discourse/app/models/user.js | 5 ++ .../discourse/app/routes/review-index.js | 5 +- .../sidebar-user-community-section-test.js | 80 +++++++++++++++++++ .../base/sidebar-more-section-links.scss | 2 +- .../common/base/sidebar-section-link.scss | 6 ++ config/locales/client.en.yml | 4 + 12 files changed, 192 insertions(+), 28 deletions(-) create mode 100644 app/assets/javascripts/discourse/app/lib/sidebar/user/community-section/review-section-link.js diff --git a/app/assets/javascripts/discourse/app/components/reviewable-item.js b/app/assets/javascripts/discourse/app/components/reviewable-item.js index 9843038de4e..ff67e672a81 100644 --- a/app/assets/javascripts/discourse/app/components/reviewable-item.js +++ b/app/assets/javascripts/discourse/app/components/reviewable-item.js @@ -151,11 +151,11 @@ export default Component.extend({ // "fast track" to update the current user's reviewable count before the message bus finds out. if (performResult.reviewable_count !== undefined) { - this.currentUser.set( - "reviewable_count", + this.currentUser.updateReviewableCount( performResult.reviewable_count ); } + if (performResult.unseen_reviewable_count !== undefined) { this.currentUser.set( "unseen_reviewable_count", diff --git a/app/assets/javascripts/discourse/app/components/sidebar/common/community-section.js b/app/assets/javascripts/discourse/app/components/sidebar/common/community-section.js index 2ef6f167147..9a2e5174d85 100644 --- a/app/assets/javascripts/discourse/app/components/sidebar/common/community-section.js +++ b/app/assets/javascripts/discourse/app/components/sidebar/common/community-section.js @@ -1,5 +1,6 @@ import Component from "@glimmer/component"; import { inject as service } from "@ember/service"; +import { tracked } from "@glimmer/tracking"; import { customSectionLinks, @@ -13,29 +14,18 @@ export default class SidebarCommunitySection extends Component { @service appEvents; @service siteSettings; + @tracked sectionLinks; + @tracked moreSectionLinks; + @tracked moreSecondarySectionLinks; + + callbackId; headerActionsIcon; headerActions; - sectionLinks; - moreSectionLinks; - moreSecondarySectionLinks; - callbackId; constructor() { super(...arguments); - this.moreSectionLinks = this.#initializeSectionLinks([ - ...this.defaultMoreSectionLinks, - ...customSectionLinks, - ]); - - this.moreSecondarySectionLinks = this.#initializeSectionLinks([ - ...this.defaultMoreSecondarySectionLinks, - ...secondaryCustomSectionLinks, - ]); - - this.sectionLinks = this.#initializeSectionLinks( - this.defaultMainSectionLinks - ); + this.refreshSectionLinks(); this.callbackId = this.topicTrackingState.onStateChange(() => { this.sectionLinks.forEach((sectionLink) => { @@ -64,6 +54,22 @@ export default class SidebarCommunitySection extends Component { return []; } + refreshSectionLinks() { + this.moreSectionLinks = this.#initializeSectionLinks([ + ...this.defaultMoreSectionLinks, + ...customSectionLinks, + ]); + + this.moreSecondarySectionLinks = this.#initializeSectionLinks([ + ...this.defaultMoreSecondarySectionLinks, + ...secondaryCustomSectionLinks, + ]); + + this.sectionLinks = this.#initializeSectionLinks( + this.defaultMainSectionLinks + ); + } + #initializeSectionLinks(sectionLinkClasses) { return sectionLinkClasses.reduce((links, sectionLinkClass) => { const sectionLink = this.#initializeSectionLink(sectionLinkClass); diff --git a/app/assets/javascripts/discourse/app/components/sidebar/more-section-links.hbs b/app/assets/javascripts/discourse/app/components/sidebar/more-section-links.hbs index 0eb84ca6323..432b7701ee5 100644 --- a/app/assets/javascripts/discourse/app/components/sidebar/more-section-links.hbs +++ b/app/assets/javascripts/discourse/app/components/sidebar/more-section-links.hbs @@ -12,7 +12,7 @@ {{did-insert this.registerClickListener}} {{will-destroy this.unregisterClickListener}} > -