FIX: Scroll to top on badge pages (#13694)

FIX: Scroll to top on badge pages (#13694)

…so we don’t end up at a random point on the page after a transition.

diff --git a/app/assets/javascripts/discourse/app/routes/badges-index.js b/app/assets/javascripts/discourse/app/routes/badges-index.js
index 63b2cac..1b3b34b 100644
--- a/app/assets/javascripts/discourse/app/routes/badges-index.js
+++ b/app/assets/javascripts/discourse/app/routes/badges-index.js
@@ -2,6 +2,8 @@ import Badge from "discourse/models/badge";
 import DiscourseRoute from "discourse/routes/discourse";
 import I18n from "I18n";
 import PreloadStore from "discourse/lib/preload-store";
+import { scrollTop } from "discourse/mixins/scroll-top";
+import { action } from "@ember/object";
 
 export default DiscourseRoute.extend({
   model() {
@@ -18,10 +20,10 @@ export default DiscourseRoute.extend({
     return I18n.t("badges.title");
   },
 
-  actions: {
-    didTransition() {
-      this.controllerFor("application").set("showFooter", true);
-      return true;
-    },
+  @action
+  didTransition() {
+    this.controllerFor("application").set("showFooter", true);
+    scrollTop();
+    return true;
   },
 });
diff --git a/app/assets/javascripts/discourse/app/routes/badges-show.js b/app/assets/javascripts/discourse/app/routes/badges-show.js
index 81a05dd..3cfc9dc 100644
--- a/app/assets/javascripts/discourse/app/routes/badges-show.js
+++ b/app/assets/javascripts/discourse/app/routes/badges-show.js
@@ -2,7 +2,9 @@ import Badge from "discourse/models/badge";
 import DiscourseRoute from "discourse/routes/discourse";
 import PreloadStore from "discourse/lib/preload-store";
 import UserBadge from "discourse/models/user-badge";
+import { scrollTop } from "discourse/mixins/scroll-top";
 import { hash } from "rsvp";
+import { action } from "@ember/object";
 
 export default DiscourseRoute.extend({
   queryParams: {
@@ -10,12 +12,6 @@ export default DiscourseRoute.extend({
       refreshModel: true,
     },
   },
-  actions: {
-    didTransition() {
-      this.controllerFor("badges/show")._showFooter();
-      return true;
-    },
-  },
 
   serialize(model) {
     return model.getProperties("id", "slug");
@@ -68,4 +64,11 @@ export default DiscourseRoute.extend({
     controller.set("userBadges", this.userBadgesGrant);
     controller.set("userBadgesAll", this.userBadgesAll);
   },
+
+  @action
+  didTransition() {
+    this.controllerFor("badges/show")._showFooter();
+    scrollTop();
+    return true;
+  },
 });

GitHub sha: efac01d259b320272fb4f3fe86d77091c2c876e5

This commit appears in #13694 which was approved by SamSaffron. It was merged by SamSaffron.