A platform for community discussion. Free, open, simple.
DEV: Move `toggleAnonymous` out of app route (#24077)
Jarek Radosz9a497d9e220b
diff --git a/app/assets/javascripts/discourse/app/components/user-menu/profile-tab-content.hbs b/app/assets/javascripts/discourse/app/components/user-menu/profile-tab-content.hbsindex 06cf201fe7c..a5a0f0c4f96 100644--- a/app/assets/javascripts/discourse/app/components/user-menu/profile-tab-content.hbs+++ b/app/assets/javascripts/discourse/app/components/user-menu/profile-tab-content.hbs@@ -102,7 +102,7 @@}}><DButton- @action={{route-action "toggleAnonymous"}}+ @action={{this.toggleAnonymous}}class="btn-flat profile-tab-btn">{{#if this.currentUser.is_anonymous}}diff --git a/app/assets/javascripts/discourse/app/components/user-menu/profile-tab-content.js b/app/assets/javascripts/discourse/app/components/user-menu/profile-tab-content.jsindex 903814dae3b..27285b09992 100644--- a/app/assets/javascripts/discourse/app/components/user-menu/profile-tab-content.js+++ b/app/assets/javascripts/discourse/app/components/user-menu/profile-tab-content.js@@ -3,7 +3,9 @@ import { action } from "@ember/object";import { inject as service } from "@ember/service";import DoNotDisturbModal from "discourse/components/modal/do-not-disturb";import UserStatusModal from "discourse/components/modal/user-status";+import { ajax } from "discourse/lib/ajax";import DoNotDisturb from "discourse/lib/do-not-disturb";+import { userPath } from "discourse/lib/url";const _extraItems = [];@@ -92,4 +94,10 @@ export default class UserMenuProfileTabContent extends Component {},});}++ @action+ async toggleAnonymous() {+ await ajax(userPath("toggle-anon"), { type: "POST" });+ window.location.reload();+ }}diff --git a/app/assets/javascripts/discourse/app/routes/application.js b/app/assets/javascripts/discourse/app/routes/application.jsindex 22257e754af..58278832c95 100644--- a/app/assets/javascripts/discourse/app/routes/application.js+++ b/app/assets/javascripts/discourse/app/routes/application.js@@ -3,13 +3,12 @@ import { inject as service } from "@ember/service";import ForgotPassword from "discourse/components/modal/forgot-password";import KeyboardShortcutsHelp from "discourse/components/modal/keyboard-shortcuts-help";import LoginModal from "discourse/components/modal/login";-import { ajax } from "discourse/lib/ajax";import { setting } from "discourse/lib/computed";import cookie from "discourse/lib/cookie";import logout from "discourse/lib/logout";import mobile from "discourse/lib/mobile";import showModal from "discourse/lib/show-modal";-import DiscourseURL, { userPath } from "discourse/lib/url";+import DiscourseURL from "discourse/lib/url";import Category from "discourse/models/category";import Composer from "discourse/models/composer";import { findAll } from "discourse/models/login-method";@@ -66,12 +65,6 @@ const ApplicationRoute = DiscourseRoute.extend({},actions: {- toggleAnonymous() {- ajax(userPath("toggle-anon"), { type: "POST" }).then(() => {- window.location.reload();- });- },-toggleMobileView() {mobile.toggleMobileView();},diff --git a/app/assets/javascripts/discourse/app/templates/application.hbs b/app/assets/javascripts/discourse/app/templates/application.hbsindex b08663389cd..5fb69275a9d 100644--- a/app/assets/javascripts/discourse/app/templates/application.hbs+++ b/app/assets/javascripts/discourse/app/templates/application.hbs@@ -15,7 +15,6 @@@showLogin={{route-action "showLogin"}}@showKeyboard={{route-action "showKeyboardShortcutsHelp"}}@toggleMobileView={{route-action "toggleMobileView"}}- @toggleAnonymous={{route-action "toggleAnonymous"}}@logout={{route-action "logout"}}@sidebarEnabled={{this.sidebarEnabled}}@navigationMenuQueryParamOverride={{this.navigationMenuQueryParamOverride}}