DEV: Convert discovery routes to native class syntax (#23010)
This commit is contained in:
parent
904ab8deaa
commit
655e99491a
|
@ -13,13 +13,15 @@ import showModal from "discourse/lib/show-modal";
|
|||
import Session from "discourse/models/session";
|
||||
import { inject as service } from "@ember/service";
|
||||
|
||||
const DiscoveryCategoriesRoute = DiscourseRoute.extend(OpenComposer, {
|
||||
router: service(),
|
||||
export default class DiscoveryCategoriesRoute extends DiscourseRoute.extend(
|
||||
OpenComposer
|
||||
) {
|
||||
@service router;
|
||||
|
||||
renderTemplate() {
|
||||
this.render("navigation/categories", { outlet: "navigation-bar" });
|
||||
this.render("discovery/categories", { outlet: "list-container" });
|
||||
},
|
||||
}
|
||||
|
||||
findCategories() {
|
||||
let style =
|
||||
|
@ -39,7 +41,7 @@ const DiscoveryCategoriesRoute = DiscourseRoute.extend(OpenComposer, {
|
|||
}
|
||||
|
||||
return CategoryList.list(this.store);
|
||||
},
|
||||
}
|
||||
|
||||
model() {
|
||||
return this.findCategories().then((model) => {
|
||||
|
@ -50,7 +52,7 @@ const DiscoveryCategoriesRoute = DiscourseRoute.extend(OpenComposer, {
|
|||
}
|
||||
return model;
|
||||
});
|
||||
},
|
||||
}
|
||||
|
||||
_loadBefore(store) {
|
||||
return function (topic_ids, storeInSession) {
|
||||
|
@ -79,7 +81,7 @@ const DiscoveryCategoriesRoute = DiscourseRoute.extend(OpenComposer, {
|
|||
}
|
||||
});
|
||||
};
|
||||
},
|
||||
}
|
||||
|
||||
_findCategoriesAndTopics(filter) {
|
||||
return hash({
|
||||
|
@ -122,14 +124,14 @@ const DiscoveryCategoriesRoute = DiscourseRoute.extend(OpenComposer, {
|
|||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
}
|
||||
|
||||
titleToken() {
|
||||
if (defaultHomepage() === "categories") {
|
||||
return;
|
||||
}
|
||||
return I18n.t("filters.categories.title");
|
||||
},
|
||||
}
|
||||
|
||||
setupController(controller, model) {
|
||||
controller.set("model", model);
|
||||
|
@ -138,22 +140,22 @@ const DiscoveryCategoriesRoute = DiscourseRoute.extend(OpenComposer, {
|
|||
showCategoryAdmin: model.get("can_create_category"),
|
||||
canCreateTopic: model.get("can_create_topic"),
|
||||
});
|
||||
},
|
||||
}
|
||||
|
||||
@action
|
||||
triggerRefresh() {
|
||||
this.refresh();
|
||||
},
|
||||
}
|
||||
|
||||
@action
|
||||
createCategory() {
|
||||
this.router.transitionTo("newCategory");
|
||||
},
|
||||
}
|
||||
|
||||
@action
|
||||
reorderCategories() {
|
||||
showModal("reorder-categories");
|
||||
},
|
||||
}
|
||||
|
||||
@action
|
||||
createTopic() {
|
||||
|
@ -162,13 +164,11 @@ const DiscoveryCategoriesRoute = DiscourseRoute.extend(OpenComposer, {
|
|||
} else {
|
||||
this.openComposer(this.controllerFor("discovery/categories"));
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
@action
|
||||
didTransition() {
|
||||
next(() => this.controllerFor("application").set("showFooter", true));
|
||||
return true;
|
||||
},
|
||||
});
|
||||
|
||||
export default DiscoveryCategoriesRoute;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ import I18n from "I18n";
|
|||
import DiscourseRoute from "discourse/routes/discourse";
|
||||
import { action } from "@ember/object";
|
||||
|
||||
export default class extends DiscourseRoute {
|
||||
export default class DiscoveryFilterRoute extends DiscourseRoute {
|
||||
queryParams = {
|
||||
q: { replace: true, refreshModel: true },
|
||||
};
|
||||
|
|
|
@ -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 OpenComposer from "discourse/mixins/open-composer";
|
||||
import User from "discourse/models/user";
|
||||
|
@ -9,14 +5,20 @@ import { setTopicList } from "discourse/lib/topic-list-tracker";
|
|||
import { action } from "@ember/object";
|
||||
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 },
|
||||
},
|
||||
};
|
||||
|
||||
redirect() {
|
||||
return this.redirectIfLoginRequired();
|
||||
},
|
||||
}
|
||||
|
||||
beforeModel(transition) {
|
||||
const url = transition.intent.url;
|
||||
|
@ -43,7 +45,7 @@ export default DiscourseRoute.extend(OpenComposer, {
|
|||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
@action
|
||||
loading() {
|
||||
|
@ -51,12 +53,12 @@ export default DiscourseRoute.extend(OpenComposer, {
|
|||
|
||||
// We don't want loading to bubble
|
||||
return true;
|
||||
},
|
||||
}
|
||||
|
||||
@action
|
||||
loadingComplete() {
|
||||
this.controllerFor("discovery").loadingComplete();
|
||||
},
|
||||
}
|
||||
|
||||
@action
|
||||
didTransition() {
|
||||
|
@ -64,13 +66,13 @@ export default DiscourseRoute.extend(OpenComposer, {
|
|||
|
||||
const model = this.controllerFor("discovery/topics").get("model");
|
||||
setTopicList(model);
|
||||
},
|
||||
}
|
||||
|
||||
// clear a pinned topic
|
||||
@action
|
||||
clearPin(topic) {
|
||||
topic.clearPin();
|
||||
},
|
||||
}
|
||||
|
||||
@action
|
||||
createTopic() {
|
||||
|
@ -79,13 +81,13 @@ export default DiscourseRoute.extend(OpenComposer, {
|
|||
} else {
|
||||
this.openComposer(this.controllerFor("discovery/topics"));
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
@action
|
||||
dismissReadTopics(dismissTopics) {
|
||||
const operationType = dismissTopics ? "topics" : "posts";
|
||||
this.send("dismissRead", operationType);
|
||||
},
|
||||
}
|
||||
|
||||
@action
|
||||
dismissRead(operationType) {
|
||||
|
@ -94,15 +96,15 @@ export default DiscourseRoute.extend(OpenComposer, {
|
|||
categoryId: controller.get("category.id"),
|
||||
includeSubcategories: !controller.noSubcategories,
|
||||
});
|
||||
},
|
||||
}
|
||||
|
||||
refresh() {
|
||||
resetCachedTopicList(this.session);
|
||||
this._super();
|
||||
},
|
||||
super.refresh();
|
||||
}
|
||||
|
||||
@action
|
||||
triggerRefresh() {
|
||||
this.refresh();
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue