diff --git a/app/assets/javascripts/discourse/app/components/sidebar/categories-section.js b/app/assets/javascripts/discourse/app/components/sidebar/categories-section.js index f4cc5ea769d..f1f42406507 100644 --- a/app/assets/javascripts/discourse/app/components/sidebar/categories-section.js +++ b/app/assets/javascripts/discourse/app/components/sidebar/categories-section.js @@ -4,6 +4,20 @@ import GlimmerComponent from "discourse/components/glimmer"; import CategorySectionLink from "discourse/lib/sidebar/categories-section/category-section-link"; export default class SidebarCategoriesSection extends GlimmerComponent { + constructor() { + super(...arguments); + + this.callbackId = this.topicTrackingState.onStateChange(() => { + this.sectionLinks.forEach((sectionLink) => { + sectionLink.refreshCounts(); + }); + }); + } + + willDestroy() { + this.topicTrackingState.offStateChange(this.callbackId); + } + @cached get sectionLinks() { return this.site.trackedCategoriesList.map((trackedCategory) => { @@ -13,8 +27,4 @@ export default class SidebarCategoriesSection extends GlimmerComponent { }); }); } - - willDestroy() { - this.sectionLinks.forEach((sectionLink) => sectionLink.teardown()); - } } diff --git a/app/assets/javascripts/discourse/app/lib/sidebar/categories-section/category-section-link.js b/app/assets/javascripts/discourse/app/lib/sidebar/categories-section/category-section-link.js index 122edb437d3..ea39390be65 100644 --- a/app/assets/javascripts/discourse/app/lib/sidebar/categories-section/category-section-link.js +++ b/app/assets/javascripts/discourse/app/lib/sidebar/categories-section/category-section-link.js @@ -14,20 +14,11 @@ export default class CategorySectionLink { constructor({ category, topicTrackingState }) { this.category = category; this.topicTrackingState = topicTrackingState; - - this.callbackId = this.topicTrackingState.onStateChange( - this._refreshCounts - ); - - this._refreshCounts(); - } - - teardown() { - this.topicTrackingState.offStateChange(this.callbackId); + this.refreshCounts(); } @bind - _refreshCounts() { + refreshCounts() { this.totalUnread = this.topicTrackingState.countUnread({ categoryId: this.category.id, });