DEV: migrate (almost all) routes from actions: to @action syntax (#14722)

This should be safe, all these places are pretty straightforward. I've run into one problem when changing this, though. That problem was fixed in https://github.com/discourse/discourse/pull/14624
This commit is contained in:
Andrei Prigorshnev
2021-11-30 17:01:06 +04:00
committed by GitHub
parent 88f9bb3dc9
commit 284ab8cdf7
19 changed files with 338 additions and 320 deletions

View File

@ -1,6 +1,7 @@
import DiscourseRoute from "discourse/routes/discourse";
import I18n from "I18n";
import { ajax } from "discourse/lib/ajax";
import { action } from "@ember/object";
export default DiscourseRoute.extend({
model() {
@ -36,10 +37,9 @@ export default DiscourseRoute.extend({
return I18n.t("about.simple_title");
},
actions: {
@action
didTransition() {
this.controllerFor("application").set("showFooter", true);
return true;
},
},
});

View File

@ -1,15 +1,15 @@
import DiscourseRoute from "discourse/routes/discourse";
import { emojiUnescape } from "discourse/lib/text";
import { escapeExpression } from "discourse/lib/utilities";
import { action } from "@ember/object";
export default function (filter) {
return DiscourseRoute.extend({
actions: {
@action
didTransition() {
this.controllerFor("user-posts")._showFooter();
return true;
},
},
model() {
return this.modelFor("user").get("postsStream");

View File

@ -1,6 +1,6 @@
import CategoryList from "discourse/models/category-list";
import DiscourseRoute from "discourse/routes/discourse";
import EmberObject from "@ember/object";
import EmberObject, { action } from "@ember/object";
import I18n from "I18n";
import OpenComposer from "discourse/mixins/open-composer";
import PreloadStore from "discourse/lib/preload-store";
@ -130,19 +130,22 @@ const DiscoveryCategoriesRoute = DiscourseRoute.extend(OpenComposer, {
});
},
actions: {
@action
triggerRefresh() {
this.refresh();
},
@action
createCategory() {
this.transitionTo("newCategory");
},
@action
reorderCategories() {
showModal("reorderCategories");
},
@action
createTopic() {
if (this.get("currentUser.has_topic_draft")) {
this.openTopicDraft();
@ -151,11 +154,11 @@ const DiscoveryCategoriesRoute = DiscourseRoute.extend(OpenComposer, {
}
},
@action
didTransition() {
next(() => this.controllerFor("application").set("showFooter", true));
return true;
},
},
});
export default DiscoveryCategoriesRoute;

View File

@ -8,6 +8,7 @@ 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, {
queryParams: {
@ -44,7 +45,7 @@ export default DiscourseRoute.extend(OpenComposer, {
}
},
actions: {
@action
loading() {
this.controllerFor("discovery").loadingBegan();
@ -52,6 +53,7 @@ export default DiscourseRoute.extend(OpenComposer, {
return true;
},
@action
loadingComplete() {
this.controllerFor("discovery").loadingComplete();
if (!this.session.get("topicListScrollPosition")) {
@ -59,6 +61,7 @@ export default DiscourseRoute.extend(OpenComposer, {
}
},
@action
didTransition() {
this.send("loadingComplete");
@ -67,10 +70,12 @@ export default DiscourseRoute.extend(OpenComposer, {
},
// clear a pinned topic
@action
clearPin(topic) {
topic.clearPin();
},
@action
createTopic() {
if (this.get("currentUser.has_topic_draft")) {
this.openTopicDraft();
@ -79,11 +84,13 @@ export default DiscourseRoute.extend(OpenComposer, {
}
},
@action
dismissReadTopics(dismissTopics) {
const operationType = dismissTopics ? "topics" : "posts";
this.send("dismissRead", operationType);
},
@action
dismissRead(operationType) {
const controller = this.controllerFor("discovery/topics");
controller.send("dismissRead", operationType, {
@ -91,5 +98,4 @@ export default DiscourseRoute.extend(OpenComposer, {
includeSubcategories: !controller.noSubcategories,
});
},
},
});

View File

@ -1,14 +1,14 @@
import DiscourseRoute from "discourse/routes/discourse";
import { action } from "@ember/object";
export default DiscourseRoute.extend({
serialize() {
return "";
},
actions: {
@action
didTransition() {
this.controllerFor("application").set("showFooter", true);
return true;
},
},
});

View File

@ -9,6 +9,7 @@ import I18n from "I18n";
import PreloadStore from "discourse/lib/preload-store";
import { ajax } from "discourse/lib/ajax";
import { escapeExpression } from "discourse/lib/utilities";
import { action } from "@ember/object";
export default DiscourseRoute.extend({
queryParams: {
@ -64,10 +65,9 @@ export default DiscourseRoute.extend({
});
},
actions: {
@action
didTransition() {
this.controllerFor("full-page-search")._showFooter();
return true;
},
},
});

View File

@ -1,6 +1,6 @@
import DiscourseRoute from "discourse/routes/discourse";
import I18n from "I18n";
import { get } from "@ember/object";
import { action, get } from "@ember/object";
export function buildGroupPage(type) {
return DiscourseRoute.extend({
@ -29,11 +29,10 @@ export function buildGroupPage(type) {
this.render("group-activity-posts");
},
actions: {
@action
didTransition() {
return true;
},
},
});
}

View File

@ -1,5 +1,6 @@
import DiscourseRoute from "discourse/routes/discourse";
import I18n from "I18n";
import { action } from "@ember/object";
export default DiscourseRoute.extend({
titleToken() {
@ -14,9 +15,8 @@ export default DiscourseRoute.extend({
this.controllerFor("group-manage-logs").setProperties({ model });
},
actions: {
@action
willTransition() {
this.controllerFor("group-manage-logs").reset();
},
},
});

View File

@ -1,6 +1,7 @@
import RestrictedUserRoute from "discourse/routes/restricted-user";
import UserBadge from "discourse/models/user-badge";
import showModal from "discourse/lib/show-modal";
import { action } from "@ember/object";
export default RestrictedUserRoute.extend({
showFooter: true,
@ -33,9 +34,8 @@ export default RestrictedUserRoute.extend({
});
},
actions: {
@action
showAvatarSelector(user) {
showModal("avatar-selector").setProperties({ user });
},
},
});

View File

@ -1,4 +1,5 @@
import RestrictedUserRoute from "discourse/routes/restricted-user";
import { action } from "@ember/object";
export default RestrictedUserRoute.extend({
showFooter: true,
@ -34,7 +35,7 @@ export default RestrictedUserRoute.extend({
.finally(() => controller.set("loading", false));
},
actions: {
@action
willTransition(transition) {
this._super(...arguments);
@ -56,5 +57,4 @@ export default RestrictedUserRoute.extend({
transition.abort();
return false;
},
},
});

View File

@ -1,5 +1,6 @@
import DiscourseRoute from "discourse/routes/discourse";
import { isPresent } from "@ember/utils";
import { action } from "@ember/object";
export default DiscourseRoute.extend({
model(params) {
@ -74,9 +75,8 @@ export default DiscourseRoute.extend({
this.messageBus.unsubscribe("/reviewable_claimed");
},
actions: {
@action
refreshRoute() {
this.refresh();
},
},
});

View File

@ -4,6 +4,7 @@ import Draft from "discourse/models/draft";
import { isEmpty } from "@ember/utils";
import { isTesting } from "discourse-common/config/environment";
import { schedule } from "@ember/runloop";
import { action } from "@ember/object";
// This route is used for retrieving a topic based on params
export default DiscourseRoute.extend({
@ -114,16 +115,12 @@ export default DiscourseRoute.extend({
}
},
actions: {
@action
willTransition() {
this.controllerFor("topic").set(
"previousURL",
document.location.pathname
);
this.controllerFor("topic").set("previousURL", document.location.pathname);
// NOTE: omitting this return can break the back button when transitioning quickly between
// topics and the latest page.
return true;
},
},
});

View File

@ -2,7 +2,7 @@ import { cancel, later, schedule } from "@ember/runloop";
import DiscourseRoute from "discourse/routes/discourse";
import DiscourseURL from "discourse/lib/url";
import { ID_CONSTRAINT } from "discourse/models/topic";
import { get } from "@ember/object";
import { action, get } from "@ember/object";
import { isEmpty } from "@ember/utils";
import { inject as service } from "@ember/service";
import { setTopicId } from "discourse/lib/topic-list-tracker";
@ -60,7 +60,7 @@ const TopicRoute = DiscourseRoute.extend({
}
},
actions: {
@action
showInvite() {
let invitePanelTitle;
@ -86,17 +86,20 @@ const TopicRoute = DiscourseRoute.extend({
});
},
@action
showFlags(model) {
let controller = showModal("flag", { model });
controller.setProperties({ flagTopic: false });
},
@action
showFlagTopic() {
const model = this.modelFor("topic");
let controller = showModal("flag", { model });
controller.setProperties({ flagTopic: true });
},
@action
showPagePublish() {
const model = this.modelFor("topic");
showModal("publish-page", {
@ -105,6 +108,7 @@ const TopicRoute = DiscourseRoute.extend({
});
},
@action
showTopicTimerModal() {
const model = this.modelFor("topic");
@ -117,12 +121,14 @@ const TopicRoute = DiscourseRoute.extend({
this.controllerFor("modal").set("modalClass", "edit-topic-timer-modal");
},
@action
showTopicSlowModeUpdate() {
const model = this.modelFor("topic");
showModal("edit-slow-mode", { model });
},
@action
showChangeTimestamp() {
showModal("change-timestamp", {
model: this.modelFor("topic"),
@ -130,6 +136,7 @@ const TopicRoute = DiscourseRoute.extend({
});
},
@action
showFeatureTopic() {
showModal("featureTopic", {
model: this.modelFor("topic"),
@ -139,6 +146,7 @@ const TopicRoute = DiscourseRoute.extend({
this.controllerFor("feature_topic").reset();
},
@action
showHistory(model, revision) {
let historyController = showModal("history", {
model,
@ -149,6 +157,7 @@ const TopicRoute = DiscourseRoute.extend({
historyController.set("topicController", this.controllerFor("topic"));
},
@action
showGrantBadgeModal() {
showModal("grant-badge", {
model: this.modelFor("topic"),
@ -156,11 +165,13 @@ const TopicRoute = DiscourseRoute.extend({
});
},
@action
showRawEmail(model) {
showModal("raw-email", { model });
this.controllerFor("raw_email").loadRawEmail(model.get("id"));
},
@action
moveToTopic() {
showModal("move-to-topic", {
model: this.modelFor("topic"),
@ -168,6 +179,7 @@ const TopicRoute = DiscourseRoute.extend({
});
},
@action
changeOwner() {
showModal("change-owner", {
model: this.modelFor("topic"),
@ -176,6 +188,7 @@ const TopicRoute = DiscourseRoute.extend({
},
// Use replaceState to update the URL once it changes
@action
postChangedRoute(currentPost) {
// do nothing if we are transitioning to another route
if (this.isTransitioning || TopicRoute.disableReplaceState) {
@ -183,10 +196,8 @@ const TopicRoute = DiscourseRoute.extend({
}
const topic = this.modelFor("topic");
if (topic && currentPost) {
let postUrl;
if (currentPost > 1) {
postUrl = topic.urlForPostNumber(currentPost);
} else {
@ -225,6 +236,7 @@ const TopicRoute = DiscourseRoute.extend({
}
},
@action
didTransition() {
const controller = this.controllerFor("topic");
controller._showFooter();
@ -233,13 +245,13 @@ const TopicRoute = DiscourseRoute.extend({
return true;
},
@action
willTransition() {
this._super(...arguments);
cancel(this.scheduledReplace);
this.set("isTransitioning", true);
return true;
},
},
// replaceState can be very slow on Android Chrome. This function debounces replaceState
// within a topic until scrolling stops

View File

@ -1,5 +1,6 @@
import DiscourseRoute from "discourse/routes/discourse";
import I18n from "I18n";
import { action } from "@ember/object";
export default DiscourseRoute.extend({
model() {
@ -38,10 +39,9 @@ export default DiscourseRoute.extend({
this.appEvents.off("draft:destroyed", this, this.refresh);
},
actions: {
@action
didTransition() {
this.controllerFor("user-activity")._showFooter();
return true;
},
},
});

View File

@ -1,6 +1,7 @@
import DiscourseRoute from "discourse/routes/discourse";
import UserBadge from "discourse/models/user-badge";
import ViewingActionType from "discourse/mixins/viewing-action-type";
import { action } from "@ember/object";
export default DiscourseRoute.extend(ViewingActionType, {
model() {
@ -19,10 +20,9 @@ export default DiscourseRoute.extend(ViewingActionType, {
this.render("user/badges", { into: "user" });
},
actions: {
@action
didTransition() {
this.controllerFor("application").set("showFooter", true);
return true;
},
},
});

View File

@ -1,5 +1,6 @@
import DiscourseRoute from "discourse/routes/discourse";
import Invite from "discourse/models/invite";
import { action } from "@ember/object";
export default DiscourseRoute.extend({
model(params) {
@ -26,9 +27,8 @@ export default DiscourseRoute.extend({
});
},
actions: {
@action
triggerRefresh() {
this.refresh();
},
},
});

View File

@ -1,5 +1,6 @@
import DiscourseRoute from "discourse/routes/discourse";
import ViewingActionType from "discourse/mixins/viewing-action-type";
import { action } from "@ember/object";
export default DiscourseRoute.extend(ViewingActionType, {
controllerName: "user-notifications",
@ -9,12 +10,11 @@ export default DiscourseRoute.extend(ViewingActionType, {
this.render("user/notifications");
},
actions: {
@action
didTransition() {
this.controllerFor("user-notifications")._showFooter();
return true;
},
},
model(params) {
const username = this.modelFor("user").get("username");

View File

@ -1,6 +1,7 @@
import DiscourseRoute from "discourse/routes/discourse";
import I18n from "I18n";
import User from "discourse/models/user";
import { action } from "@ember/object";
export default DiscourseRoute.extend({
titleToken() {
@ -10,15 +11,15 @@ export default DiscourseRoute.extend({
}
},
actions: {
@action
undoRevokeApiKey(key) {
key.undoRevoke();
},
@action
revokeApiKey(key) {
key.revoke();
},
},
beforeModel() {
if (this.siteSettings.hide_user_profiles_from_public && !this.currentUser) {

View File

@ -3,6 +3,7 @@ import I18n from "I18n";
import { ajax } from "discourse/lib/ajax";
import { popupAjaxError } from "discourse/lib/ajax-error";
import { Promise } from "rsvp";
import { action } from "@ember/object";
export default DiscourseRoute.extend({
queryParams: {
@ -55,10 +56,9 @@ export default DiscourseRoute.extend({
]);
},
actions: {
@action
didTransition() {
this.controllerFor("users")._showFooter();
return true;
},
},
});