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.
This commit is contained in:
David Taylor 2021-02-05 09:16:18 +00:00 committed by GitHub
parent f6e6ae5e24
commit d1b289daaa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 6 additions and 20 deletions

View File

@ -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),

View File

@ -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;
},

View File

@ -11,10 +11,4 @@ export default DiscourseRoute.extend({
return user.summary();
},
actions: {
didTransition() {
this.controllerFor("user").set("indexStream", true);
},
},
});

View File

@ -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();
},