mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 09:17:08 +08:00
DEV: Prefer site
injection over import (#14982)
And in helpers use `helperContext().site`
This commit is contained in:
parent
80e422cea3
commit
0464f9d2be
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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 "";
|
||||
|
|
|
@ -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({
|
||||
|
|
|
@ -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],
|
||||
|
|
|
@ -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),
|
||||
|
|
Loading…
Reference in New Issue
Block a user