diff --git a/app/assets/javascripts/discourse/app/components/suggested-topics.js b/app/assets/javascripts/discourse/app/components/suggested-topics.js index a054bb0a766..fbcb952c357 100644 --- a/app/assets/javascripts/discourse/app/components/suggested-topics.js +++ b/app/assets/javascripts/discourse/app/components/suggested-topics.js @@ -1,7 +1,6 @@ import { computed, get } from "@ember/object"; import Component from "@ember/component"; import I18n from "I18n"; -import Site from "discourse/models/site"; import { categoryBadgeHTML } from "discourse/helpers/category-link"; import discourseComputed from "discourse-common/utils/decorators"; import getURL from "discourse-common/lib/get-url"; @@ -90,7 +89,7 @@ export default Component.extend({ if ( category && - get(category, "id") === Site.currentProp("uncategorized_category_id") + get(category, "id") === this.site.uncategorized_category_id ) { category = null; } diff --git a/app/assets/javascripts/discourse/app/helpers/category-link.js b/app/assets/javascripts/discourse/app/helpers/category-link.js index 289b0407d90..52b0ce4ebea 100644 --- a/app/assets/javascripts/discourse/app/helpers/category-link.js +++ b/app/assets/javascripts/discourse/app/helpers/category-link.js @@ -1,7 +1,6 @@ import { helperContext, registerUnbound } from "discourse-common/lib/helpers"; import Category from "discourse/models/category"; import I18n from "I18n"; -import Site from "discourse/models/site"; import { escapeExpression } from "discourse/lib/utilities"; import { get } from "@ember/object"; import getURL from "discourse-common/lib/get-url"; @@ -39,13 +38,13 @@ export function addExtraIconRenderer(renderer) { @param {Number} [opts.depth] Current category depth, used for limiting recursive calls **/ export function categoryBadgeHTML(category, opts) { - let siteSettings = helperContext().siteSettings; + const { site, siteSettings } = helperContext(); opts = opts || {}; if ( !category || (!opts.allowUncategorized && - get(category, "id") === Site.currentProp("uncategorized_category_id") && + get(category, "id") === site.uncategorized_category_id && siteSettings.suppress_uncategorized_badge) ) { return ""; diff --git a/app/assets/javascripts/discourse/app/routes/discovery-categories.js b/app/assets/javascripts/discourse/app/routes/discovery-categories.js index dc179e39b87..1bbb16c2cba 100644 --- a/app/assets/javascripts/discourse/app/routes/discovery-categories.js +++ b/app/assets/javascripts/discourse/app/routes/discovery-categories.js @@ -4,7 +4,6 @@ import EmberObject, { action } from "@ember/object"; import I18n from "I18n"; import OpenComposer from "discourse/mixins/open-composer"; import PreloadStore from "discourse/lib/preload-store"; -import Site from "discourse/models/site"; import TopicList from "discourse/models/topic-list"; import { ajax } from "discourse/lib/ajax"; import { defaultHomepage } from "discourse/lib/utilities"; @@ -50,6 +49,7 @@ const DiscoveryCategoriesRoute = DiscourseRoute.extend(OpenComposer, { return model; }); }, + _loadBefore(store) { return function (topic_ids, storeInSession) { // refresh dupes @@ -78,6 +78,7 @@ const DiscoveryCategoriesRoute = DiscourseRoute.extend(OpenComposer, { }); }; }, + _findCategoriesAndTopics(filter) { return hash({ wrappedCategoriesList: PreloadStore.getAndRemove("categories_list"), @@ -89,8 +90,8 @@ const DiscoveryCategoriesRoute = DiscourseRoute.extend(OpenComposer, { let store = this.store; if (categoriesList && topicsList) { - if (topicsList.topic_list && topicsList.topic_list.top_tags) { - Site.currentProp("top_tags", topicsList.topic_list.top_tags); + if (topicsList.topic_list?.top_tags) { + this.site.set("top_tags", topicsList.topic_list.top_tags); } return EmberObject.create({ @@ -106,8 +107,8 @@ const DiscoveryCategoriesRoute = DiscourseRoute.extend(OpenComposer, { } // Otherwise, return the ajax result return ajax(`/categories_and_${filter}`).then((result) => { - if (result.topic_list && result.topic_list.top_tags) { - Site.currentProp("top_tags", result.topic_list.top_tags); + if (result.topic_list?.top_tags) { + this.site.set("top_tags", result.topic_list.top_tags); } return EmberObject.create({ diff --git a/app/assets/javascripts/discourse/app/routes/discovery.js b/app/assets/javascripts/discourse/app/routes/discovery.js index d718a4da400..1951755782f 100644 --- a/app/assets/javascripts/discourse/app/routes/discovery.js +++ b/app/assets/javascripts/discourse/app/routes/discovery.js @@ -7,7 +7,6 @@ import OpenComposer from "discourse/mixins/open-composer"; import User from "discourse/models/user"; import { scrollTop } from "discourse/mixins/scroll-top"; import { setTopicList } from "discourse/lib/topic-list-tracker"; -import Site from "discourse/models/site"; import { action } from "@ember/object"; export default DiscourseRoute.extend(OpenComposer, { @@ -36,7 +35,7 @@ export default DiscourseRoute.extend(OpenComposer, { }, }); } else if (url && (matches = url.match(/top\/(.*)$/))) { - if (Site.currentProp("periods").includes(matches[1])) { + if (this.site.periods.includes(matches[1])) { this.replaceWith("discovery.top", { queryParams: { period: matches[1], diff --git a/app/assets/javascripts/discourse/tests/unit/lib/category-badge-test.js b/app/assets/javascripts/discourse/tests/unit/lib/category-badge-test.js index dfde32f150e..f21fcad5de2 100644 --- a/app/assets/javascripts/discourse/tests/unit/lib/category-badge-test.js +++ b/app/assets/javascripts/discourse/tests/unit/lib/category-badge-test.js @@ -1,9 +1,8 @@ import { module, test } from "qunit"; -import Site from "discourse/models/site"; import { categoryBadgeHTML } from "discourse/helpers/category-link"; -import sinon from "sinon"; import { getOwner } from "discourse-common/lib/get-owner"; import { setupTest } from "ember-qunit"; +import { helperContext } from "discourse-common/lib/helpers"; module("Unit | Utility | category-badge", function (hooks) { setupTest(hooks); @@ -76,10 +75,8 @@ module("Unit | Utility | category-badge", function (hooks) { id: 345, }); - sinon - .stub(Site, "currentProp") - .withArgs("uncategorized_category_id") - .returns(345); + const { site } = helperContext(); + site.set("uncategorized_category_id", 345); assert.blank( categoryBadgeHTML(uncategorized),