DEV: Convert discovery controllers to native class syntax (#22938)
This commit is contained in:
parent
5dc3a276c8
commit
089dead654
|
@ -1,37 +1,37 @@
|
|||
import Controller, { inject as controller } from "@ember/controller";
|
||||
import { inject as service } from "@ember/service";
|
||||
import { alias, equal, not } from "@ember/object/computed";
|
||||
import Controller, { inject as controller } from "@ember/controller";
|
||||
import { action } from "@ember/object";
|
||||
import Category from "discourse/models/category";
|
||||
import DiscourseURL from "discourse/lib/url";
|
||||
import { inject as service } from "@ember/service";
|
||||
|
||||
export default Controller.extend({
|
||||
discoveryTopics: controller("discovery/topics"),
|
||||
navigationCategory: controller("navigation/category"),
|
||||
application: controller(),
|
||||
router: service(),
|
||||
viewingCategoriesList: equal(
|
||||
"router.currentRouteName",
|
||||
"discovery.categories"
|
||||
),
|
||||
loading: false,
|
||||
export default class DiscoveryController extends Controller {
|
||||
@service router;
|
||||
|
||||
category: alias("navigationCategory.category"),
|
||||
noSubcategories: alias("navigationCategory.noSubcategories"),
|
||||
@controller("discovery/topics") discoveryTopics;
|
||||
@controller("navigation/category") navigationCategory;
|
||||
@controller application;
|
||||
|
||||
loadedAllItems: not("discoveryTopics.model.canLoadMore"),
|
||||
@equal("router.currentRouteName", "discovery.categories")
|
||||
viewingCategoriesList;
|
||||
|
||||
@alias("navigationCategory.category") category;
|
||||
@alias("navigationCategory.noSubcategories") noSubcategories;
|
||||
@not("discoveryTopics.model.canLoadMore") loadedAllItems;
|
||||
|
||||
loading = false;
|
||||
|
||||
@action
|
||||
loadingBegan() {
|
||||
this.set("loading", true);
|
||||
this.set("application.showFooter", false);
|
||||
},
|
||||
}
|
||||
|
||||
@action
|
||||
loadingComplete() {
|
||||
this.set("loading", false);
|
||||
this.set("application.showFooter", this.loadedAllItems);
|
||||
},
|
||||
}
|
||||
|
||||
showMoreUrl(period) {
|
||||
let url = "",
|
||||
|
@ -58,18 +58,17 @@ export default Controller.extend({
|
|||
urlSearchParams.set("period", period);
|
||||
|
||||
return `${url}?${urlSearchParams.toString()}`;
|
||||
},
|
||||
}
|
||||
|
||||
get showLoadingSpinner() {
|
||||
return (
|
||||
this.get("loading") &&
|
||||
this.siteSettings.page_loading_indicator === "spinner"
|
||||
);
|
||||
},
|
||||
}
|
||||
|
||||
actions: {
|
||||
changePeriod(p) {
|
||||
DiscourseURL.routeTo(this.showMoreUrl(p));
|
||||
},
|
||||
},
|
||||
});
|
||||
@action
|
||||
changePeriod(p) {
|
||||
DiscourseURL.routeTo(this.showMoreUrl(p));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import DiscoveryController from "discourse/controllers/discovery";
|
||||
import { inject as controller } from "@ember/controller";
|
||||
import { reads } from "@ember/object/computed";
|
||||
import DiscoveryController from "discourse/controllers/discovery";
|
||||
import { action } from "@ember/object";
|
||||
import { dasherize } from "@ember/string";
|
||||
import discourseComputed from "discourse-common/utils/decorators";
|
||||
import { reads } from "@ember/object/computed";
|
||||
|
||||
const subcategoryStyleComponentNames = {
|
||||
rows: "categories_only",
|
||||
|
@ -17,17 +17,19 @@ const mobileCompatibleViews = [
|
|||
"subcategories_with_featured_topics",
|
||||
];
|
||||
|
||||
export default DiscoveryController.extend({
|
||||
discovery: controller(),
|
||||
export default class CategoriesController extends DiscoveryController {
|
||||
@controller discovery;
|
||||
|
||||
// this makes sure the composer isn't scoping to a specific category
|
||||
category: null,
|
||||
category = null;
|
||||
|
||||
@reads("currentUser.staff") canEdit;
|
||||
|
||||
canEdit: reads("currentUser.staff"),
|
||||
@discourseComputed
|
||||
isCategoriesRoute() {
|
||||
return this.router.currentRouteName === "discovery.categories";
|
||||
},
|
||||
}
|
||||
|
||||
@discourseComputed("model.parentCategory")
|
||||
categoryPageStyle(parentCategory) {
|
||||
let style = this.siteSettings.desktop_category_page_style;
|
||||
|
@ -50,7 +52,7 @@ export default DiscoveryController.extend({
|
|||
? "categories_only"
|
||||
: style;
|
||||
return dasherize(componentName);
|
||||
},
|
||||
}
|
||||
|
||||
@action
|
||||
showInserted(event) {
|
||||
|
@ -59,11 +61,10 @@ export default DiscoveryController.extend({
|
|||
// Move inserted into topics
|
||||
this.model.loadBefore(tracker.get("newIncoming"), true);
|
||||
tracker.resetTracking();
|
||||
},
|
||||
}
|
||||
|
||||
actions: {
|
||||
refresh() {
|
||||
this.send("triggerRefresh");
|
||||
},
|
||||
},
|
||||
});
|
||||
@action
|
||||
refresh() {
|
||||
this.send("triggerRefresh");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,60 +1,68 @@
|
|||
import { inject as controller } from "@ember/controller";
|
||||
import { inject as service } from "@ember/service";
|
||||
import { alias, empty, equal, gt, not, readOnly } from "@ember/object/computed";
|
||||
import BulkTopicSelection from "discourse/mixins/bulk-topic-selection";
|
||||
import DismissTopics from "discourse/mixins/dismiss-topics";
|
||||
import DiscoveryController from "discourse/controllers/discovery";
|
||||
import I18n from "I18n";
|
||||
import Topic from "discourse/models/topic";
|
||||
import { inject as controller } from "@ember/controller";
|
||||
import deprecated from "discourse-common/lib/deprecated";
|
||||
import discourseComputed from "discourse-common/utils/decorators";
|
||||
import { endWith } from "discourse/lib/computed";
|
||||
import { routeAction } from "discourse/helpers/route-action";
|
||||
import { inject as service } from "@ember/service";
|
||||
import { userPath } from "discourse/lib/url";
|
||||
import { action } from "@ember/object";
|
||||
|
||||
const controllerOpts = {
|
||||
discovery: controller(),
|
||||
router: service(),
|
||||
export default class TopicsController extends DiscoveryController.extend(
|
||||
BulkTopicSelection,
|
||||
DismissTopics
|
||||
) {
|
||||
@service router;
|
||||
@controller discovery;
|
||||
|
||||
period: null,
|
||||
canCreateTopicOnCategory: null,
|
||||
period = null;
|
||||
canCreateTopicOnCategory = null;
|
||||
selected = null;
|
||||
expandGloballyPinned = false;
|
||||
expandAllPinned = false;
|
||||
|
||||
canStar: alias("currentUser.id"),
|
||||
showTopicPostBadges: not("new"),
|
||||
redirectedReason: alias("currentUser.user_option.redirected_to_top.reason"),
|
||||
@alias("currentUser.id") canStar;
|
||||
@not("new") showTopicPostBadges;
|
||||
@alias("currentUser.user_option.redirected_to_top.reason") redirectedReason;
|
||||
@readOnly("model.params.order") order;
|
||||
@readOnly("model.params.ascending") ascending;
|
||||
@gt("model.topics.length", 0) hasTopics;
|
||||
@empty("model.more_topics_url") allLoaded;
|
||||
@endWith("model.filter", "latest") latest;
|
||||
@endWith("model.filter", "top") top;
|
||||
@equal("period", "yearly") yearly;
|
||||
@equal("period", "quarterly") quarterly;
|
||||
@equal("period", "monthly") monthly;
|
||||
@equal("period", "weekly") weekly;
|
||||
@equal("period", "daily") daily;
|
||||
|
||||
expandGloballyPinned: false,
|
||||
expandAllPinned: false,
|
||||
|
||||
order: readOnly("model.params.order"),
|
||||
ascending: readOnly("model.params.ascending"),
|
||||
|
||||
selected: null,
|
||||
|
||||
// Remove these actions which are defined in `DiscoveryController`
|
||||
// Remove these loading actions which are defined in `DiscoveryController`
|
||||
// We want them to bubble in DiscoveryTopicsController
|
||||
@action
|
||||
loadingBegan() {
|
||||
this.set("application.showFooter", false);
|
||||
return true;
|
||||
},
|
||||
|
||||
}
|
||||
@action
|
||||
loadingComplete() {
|
||||
this.set("application.showFooter", this.loadedAllItems);
|
||||
return true;
|
||||
},
|
||||
}
|
||||
|
||||
@discourseComputed("model.filter", "model.topics.length")
|
||||
showDismissRead(filter, topicsLength) {
|
||||
return this._isFilterPage(filter, "unread") && topicsLength > 0;
|
||||
},
|
||||
}
|
||||
|
||||
@discourseComputed("model.filter", "model.topics.length")
|
||||
showResetNew(filter, topicsLength) {
|
||||
return this._isFilterPage(filter, "new") && topicsLength > 0;
|
||||
},
|
||||
}
|
||||
|
||||
callResetNew(dismissPosts = false, dismissTopics = false, untrack = false) {
|
||||
const tracked =
|
||||
|
@ -80,7 +88,7 @@ const controllerOpts = {
|
|||
tracked ? { skipResettingParams: ["filter", "f"] } : {}
|
||||
);
|
||||
});
|
||||
},
|
||||
}
|
||||
|
||||
// Show newly inserted topics
|
||||
@action
|
||||
|
@ -91,26 +99,25 @@ const controllerOpts = {
|
|||
// Move inserted into topics
|
||||
this.model.loadBefore(tracker.get("newIncoming"), true);
|
||||
tracker.resetTracking();
|
||||
},
|
||||
}
|
||||
|
||||
actions: {
|
||||
changeSort() {
|
||||
deprecated(
|
||||
"changeSort has been changed from an (action) to a (route-action)",
|
||||
{
|
||||
since: "2.6.0",
|
||||
dropFrom: "2.7.0",
|
||||
id: "discourse.topics.change-sort",
|
||||
}
|
||||
);
|
||||
return routeAction("changeSort", this.router._router, ...arguments)();
|
||||
},
|
||||
},
|
||||
@action
|
||||
changeSort() {
|
||||
deprecated(
|
||||
"changeSort has been changed from an (action) to a (route-action)",
|
||||
{
|
||||
since: "2.6.0",
|
||||
dropFrom: "2.7.0",
|
||||
id: "discourse.topics.change-sort",
|
||||
}
|
||||
);
|
||||
return routeAction("changeSort", this.router._router, ...arguments)();
|
||||
}
|
||||
|
||||
@action
|
||||
refresh() {
|
||||
this.send("triggerRefresh");
|
||||
},
|
||||
}
|
||||
|
||||
afterRefresh(filter, list, listModel = list) {
|
||||
this.setProperties({ model: listModel });
|
||||
|
@ -121,22 +128,12 @@ const controllerOpts = {
|
|||
}
|
||||
|
||||
this.send("loadingComplete");
|
||||
},
|
||||
|
||||
hasTopics: gt("model.topics.length", 0),
|
||||
allLoaded: empty("model.more_topics_url"),
|
||||
latest: endWith("model.filter", "latest"),
|
||||
top: endWith("model.filter", "top"),
|
||||
yearly: equal("period", "yearly"),
|
||||
quarterly: equal("period", "quarterly"),
|
||||
monthly: equal("period", "monthly"),
|
||||
weekly: equal("period", "weekly"),
|
||||
daily: equal("period", "daily"),
|
||||
}
|
||||
|
||||
@discourseComputed("model.filter")
|
||||
new(filter) {
|
||||
return filter?.endsWith("new") && !this.currentUser?.new_new_view_enabled;
|
||||
},
|
||||
}
|
||||
|
||||
@discourseComputed("allLoaded", "model.topics.length")
|
||||
footerMessage(allLoaded, topicsLength) {
|
||||
|
@ -161,7 +158,7 @@ const controllerOpts = {
|
|||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
@discourseComputed("allLoaded", "model.topics.length")
|
||||
footerEducation(allLoaded, topicsLength) {
|
||||
|
@ -186,11 +183,5 @@ const controllerOpts = {
|
|||
`${this.currentUser.get("username_lower")}/preferences/tracking`
|
||||
),
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
export default DiscoveryController.extend(
|
||||
controllerOpts,
|
||||
BulkTopicSelection,
|
||||
DismissTopics
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue