From d1b289daaacb716d32ba4f13322434644293b5b7 Mon Sep 17 00:00:00 2001 From: David Taylor Date: Fri, 5 Feb 2021 09:16:18 +0000 Subject: [PATCH] DEV: Cleanup detection of user summary route for header collapsing (#11985) Previously it was using various willTransition and didTransition hooks which can be quite fragile, especially when removing the intermediate loading state. --- .../javascripts/discourse/app/controllers/user.js | 11 ++++++----- .../app/routes/build-admin-user-posts-route.js | 1 - .../javascripts/discourse/app/routes/user-summary.js | 6 ------ app/assets/javascripts/discourse/app/routes/user.js | 8 -------- 4 files changed, 6 insertions(+), 20 deletions(-) diff --git a/app/assets/javascripts/discourse/app/controllers/user.js b/app/assets/javascripts/discourse/app/controllers/user.js index a2b531f8a38..cfa79ddfb69 100644 --- a/app/assets/javascripts/discourse/app/controllers/user.js +++ b/app/assets/javascripts/discourse/app/controllers/user.js @@ -1,6 +1,6 @@ import Controller, { inject } from "@ember/controller"; import EmberObject, { computed, set } from "@ember/object"; -import { alias, and, gt, not, or } from "@ember/object/computed"; +import { alias, and, equal, gt, not, or } from "@ember/object/computed"; import CanCheckEmails from "discourse/mixins/can-check-emails"; import User from "discourse/models/user"; import I18n from "I18n"; @@ -14,7 +14,6 @@ import { prioritizeNameInUx } from "discourse/lib/settings"; import { inject as service } from "@ember/service"; export default Controller.extend(CanCheckEmails, { - indexStream: false, router: service(), userNotifications: inject("user-notifications"), currentPath: alias("router._router.currentPath"), @@ -36,17 +35,19 @@ export default Controller.extend(CanCheckEmails, { return !isEmpty(background.toString()); }, + isSummaryRoute: equal("router.currentRouteName", "user.summary"), + @discourseComputed( "model.profile_hidden", - "indexStream", + "isSummaryRoute", "viewingSelf", "forceExpand" ) - collapsedInfo(profileHidden, indexStream, viewingSelf, forceExpand) { + collapsedInfo(profileHidden, isSummaryRoute, viewingSelf, forceExpand) { if (profileHidden) { return true; } - return (!indexStream || viewingSelf) && !forceExpand; + return (!isSummaryRoute || viewingSelf) && !forceExpand; }, canMuteOrIgnoreUser: or("model.can_ignore_user", "model.can_mute_user"), hasGivenFlags: gt("model.number_of_flags_given", 0), diff --git a/app/assets/javascripts/discourse/app/routes/build-admin-user-posts-route.js b/app/assets/javascripts/discourse/app/routes/build-admin-user-posts-route.js index e19026692e3..b56971fdae5 100644 --- a/app/assets/javascripts/discourse/app/routes/build-admin-user-posts-route.js +++ b/app/assets/javascripts/discourse/app/routes/build-admin-user-posts-route.js @@ -6,7 +6,6 @@ export default function (filter) { return DiscourseRoute.extend({ actions: { didTransition() { - this.controllerFor("user").set("indexStream", true); this.controllerFor("user-posts")._showFooter(); return true; }, diff --git a/app/assets/javascripts/discourse/app/routes/user-summary.js b/app/assets/javascripts/discourse/app/routes/user-summary.js index a3812871019..d7fefead284 100644 --- a/app/assets/javascripts/discourse/app/routes/user-summary.js +++ b/app/assets/javascripts/discourse/app/routes/user-summary.js @@ -11,10 +11,4 @@ export default DiscourseRoute.extend({ return user.summary(); }, - - actions: { - didTransition() { - this.controllerFor("user").set("indexStream", true); - }, - }, }); diff --git a/app/assets/javascripts/discourse/app/routes/user.js b/app/assets/javascripts/discourse/app/routes/user.js index b8f7437d31f..5a3435eb72c 100644 --- a/app/assets/javascripts/discourse/app/routes/user.js +++ b/app/assets/javascripts/discourse/app/routes/user.js @@ -11,14 +11,6 @@ export default DiscourseRoute.extend({ }, actions: { - willTransition(transition) { - // will reset the indexStream when transitioning to routes that aren't "indexStream" - // otherwise the "header" will jump - const isIndexStream = transition.targetName === "user.summary"; - this.controllerFor("user").set("indexStream", isIndexStream); - return true; - }, - undoRevokeApiKey(key) { key.undoRevoke(); },