DEV: Convert discovery routes to native class syntax (#23010)

This commit is contained in:
David Taylor 2023-08-08 13:52:34 +01:00 committed by GitHub
parent 904ab8deaa
commit 655e99491a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 40 additions and 38 deletions

View File

@ -13,13 +13,15 @@ import showModal from "discourse/lib/show-modal";
import Session from "discourse/models/session"; import Session from "discourse/models/session";
import { inject as service } from "@ember/service"; import { inject as service } from "@ember/service";
const DiscoveryCategoriesRoute = DiscourseRoute.extend(OpenComposer, { export default class DiscoveryCategoriesRoute extends DiscourseRoute.extend(
router: service(), OpenComposer
) {
@service router;
renderTemplate() { renderTemplate() {
this.render("navigation/categories", { outlet: "navigation-bar" }); this.render("navigation/categories", { outlet: "navigation-bar" });
this.render("discovery/categories", { outlet: "list-container" }); this.render("discovery/categories", { outlet: "list-container" });
}, }
findCategories() { findCategories() {
let style = let style =
@ -39,7 +41,7 @@ const DiscoveryCategoriesRoute = DiscourseRoute.extend(OpenComposer, {
} }
return CategoryList.list(this.store); return CategoryList.list(this.store);
}, }
model() { model() {
return this.findCategories().then((model) => { return this.findCategories().then((model) => {
@ -50,7 +52,7 @@ const DiscoveryCategoriesRoute = DiscourseRoute.extend(OpenComposer, {
} }
return model; return model;
}); });
}, }
_loadBefore(store) { _loadBefore(store) {
return function (topic_ids, storeInSession) { return function (topic_ids, storeInSession) {
@ -79,7 +81,7 @@ const DiscoveryCategoriesRoute = DiscourseRoute.extend(OpenComposer, {
} }
}); });
}; };
}, }
_findCategoriesAndTopics(filter) { _findCategoriesAndTopics(filter) {
return hash({ return hash({
@ -122,14 +124,14 @@ const DiscoveryCategoriesRoute = DiscourseRoute.extend(OpenComposer, {
}); });
}); });
}); });
}, }
titleToken() { titleToken() {
if (defaultHomepage() === "categories") { if (defaultHomepage() === "categories") {
return; return;
} }
return I18n.t("filters.categories.title"); return I18n.t("filters.categories.title");
}, }
setupController(controller, model) { setupController(controller, model) {
controller.set("model", model); controller.set("model", model);
@ -138,22 +140,22 @@ const DiscoveryCategoriesRoute = DiscourseRoute.extend(OpenComposer, {
showCategoryAdmin: model.get("can_create_category"), showCategoryAdmin: model.get("can_create_category"),
canCreateTopic: model.get("can_create_topic"), canCreateTopic: model.get("can_create_topic"),
}); });
}, }
@action @action
triggerRefresh() { triggerRefresh() {
this.refresh(); this.refresh();
}, }
@action @action
createCategory() { createCategory() {
this.router.transitionTo("newCategory"); this.router.transitionTo("newCategory");
}, }
@action @action
reorderCategories() { reorderCategories() {
showModal("reorder-categories"); showModal("reorder-categories");
}, }
@action @action
createTopic() { createTopic() {
@ -162,13 +164,11 @@ const DiscoveryCategoriesRoute = DiscourseRoute.extend(OpenComposer, {
} else { } else {
this.openComposer(this.controllerFor("discovery/categories")); this.openComposer(this.controllerFor("discovery/categories"));
} }
}, }
@action @action
didTransition() { didTransition() {
next(() => this.controllerFor("application").set("showFooter", true)); next(() => this.controllerFor("application").set("showFooter", true));
return true; return true;
}, }
}); }
export default DiscoveryCategoriesRoute;

View File

@ -3,7 +3,7 @@ import I18n from "I18n";
import DiscourseRoute from "discourse/routes/discourse"; import DiscourseRoute from "discourse/routes/discourse";
import { action } from "@ember/object"; import { action } from "@ember/object";
export default class extends DiscourseRoute { export default class DiscoveryFilterRoute extends DiscourseRoute {
queryParams = { queryParams = {
q: { replace: true, refreshModel: true }, q: { replace: true, refreshModel: true },
}; };

View File

@ -1,7 +1,3 @@
/**
The parent route for all discovery routes.
Handles the logic for showing the loading spinners.
**/
import DiscourseRoute from "discourse/routes/discourse"; import DiscourseRoute from "discourse/routes/discourse";
import OpenComposer from "discourse/mixins/open-composer"; import OpenComposer from "discourse/mixins/open-composer";
import User from "discourse/models/user"; import User from "discourse/models/user";
@ -9,14 +5,20 @@ import { setTopicList } from "discourse/lib/topic-list-tracker";
import { action } from "@ember/object"; import { action } from "@ember/object";
import { resetCachedTopicList } from "discourse/lib/cached-topic-list"; import { resetCachedTopicList } from "discourse/lib/cached-topic-list";
export default DiscourseRoute.extend(OpenComposer, { /**
queryParams: { The parent route for all discovery routes.
Handles the logic for showing the loading spinners.
**/
export default class DiscoveryRoute extends DiscourseRoute.extend(
OpenComposer
) {
queryParams = {
filter: { refreshModel: true }, filter: { refreshModel: true },
}, };
redirect() { redirect() {
return this.redirectIfLoginRequired(); return this.redirectIfLoginRequired();
}, }
beforeModel(transition) { beforeModel(transition) {
const url = transition.intent.url; const url = transition.intent.url;
@ -43,7 +45,7 @@ export default DiscourseRoute.extend(OpenComposer, {
}); });
} }
} }
}, }
@action @action
loading() { loading() {
@ -51,12 +53,12 @@ export default DiscourseRoute.extend(OpenComposer, {
// We don't want loading to bubble // We don't want loading to bubble
return true; return true;
}, }
@action @action
loadingComplete() { loadingComplete() {
this.controllerFor("discovery").loadingComplete(); this.controllerFor("discovery").loadingComplete();
}, }
@action @action
didTransition() { didTransition() {
@ -64,13 +66,13 @@ export default DiscourseRoute.extend(OpenComposer, {
const model = this.controllerFor("discovery/topics").get("model"); const model = this.controllerFor("discovery/topics").get("model");
setTopicList(model); setTopicList(model);
}, }
// clear a pinned topic // clear a pinned topic
@action @action
clearPin(topic) { clearPin(topic) {
topic.clearPin(); topic.clearPin();
}, }
@action @action
createTopic() { createTopic() {
@ -79,13 +81,13 @@ export default DiscourseRoute.extend(OpenComposer, {
} else { } else {
this.openComposer(this.controllerFor("discovery/topics")); this.openComposer(this.controllerFor("discovery/topics"));
} }
}, }
@action @action
dismissReadTopics(dismissTopics) { dismissReadTopics(dismissTopics) {
const operationType = dismissTopics ? "topics" : "posts"; const operationType = dismissTopics ? "topics" : "posts";
this.send("dismissRead", operationType); this.send("dismissRead", operationType);
}, }
@action @action
dismissRead(operationType) { dismissRead(operationType) {
@ -94,15 +96,15 @@ export default DiscourseRoute.extend(OpenComposer, {
categoryId: controller.get("category.id"), categoryId: controller.get("category.id"),
includeSubcategories: !controller.noSubcategories, includeSubcategories: !controller.noSubcategories,
}); });
}, }
refresh() { refresh() {
resetCachedTopicList(this.session); resetCachedTopicList(this.session);
this._super(); super.refresh();
}, }
@action @action
triggerRefresh() { triggerRefresh() {
this.refresh(); this.refresh();
}, }
}); }