FIX: refresh "/categories" on logo click (#6891)

FIX: refresh “/categories” on logo click (#6891)

  • FIX: refresh discovery categories on logo click

  • Fix prettier offence

diff --git a/app/assets/javascripts/discourse/controllers/discovery/categories.js.es6 b/app/assets/javascripts/discourse/controllers/discovery/categories.js.es6
index 1175eed..dedcef9 100644
--- a/app/assets/javascripts/discourse/controllers/discovery/categories.js.es6
+++ b/app/assets/javascripts/discourse/controllers/discovery/categories.js.es6
@@ -46,5 +46,10 @@ export default DiscoveryController.extend({
         ? "categories_only"
         : style;
     return Ember.String.dasherize(componentName);
+  },
+  actions: {
+    refresh() {
+      this.send("triggerRefresh");
+    }
   }
 });
diff --git a/app/assets/javascripts/discourse/mixins/url-refresh.js.es6 b/app/assets/javascripts/discourse/mixins/url-refresh.js.es6
index 7720e92..4b30762 100644
--- a/app/assets/javascripts/discourse/mixins/url-refresh.js.es6
+++ b/app/assets/javascripts/discourse/mixins/url-refresh.js.es6
@@ -13,6 +13,6 @@ export default {
   willDestroyElement() {
     this._super(...arguments);
 
-    this.appEvents.off("url:refresh", this, this.refresh);
+    this.appEvents.off("url:refresh");
   }
 };
diff --git a/app/assets/javascripts/discourse/routes/discovery-categories.js.es6 b/app/assets/javascripts/discourse/routes/discovery-categories.js.es6
index e8b3f48..2b77d5b 100644
--- a/app/assets/javascripts/discourse/routes/discovery-categories.js.es6
+++ b/app/assets/javascripts/discourse/routes/discovery-categories.js.es6
@@ -94,24 +94,8 @@ const DiscoveryCategoriesRoute = Discourse.Route.extend(OpenComposer, {
   },
 
   actions: {
-    refresh() {
-      const controller = this.controllerFor("discovery/categories");
-      const discController = this.controllerFor("discovery");
-
-      // Don't refresh if we're still loading
-      if (!discController || discController.get("loading")) {
-        return;
-      }
-
-      // If we `send('loading')` here, due to returning true it bubbles up to the
-      // router and ember throws an error due to missing `handlerInfos`.
-      // Lesson learned: Don't call `loading` yourself.
-      discController.set("loading", true);
-
-      this.model().then(model => {
-        this.setupController(controller, model);
-        controller.send("loadingComplete");
-      });
+    triggerRefresh() {
+      this.refresh();
     },
 
     createCategory() {
diff --git a/app/assets/javascripts/discourse/templates/discovery/categories.hbs b/app/assets/javascripts/discourse/templates/discovery/categories.hbs
index 907b864..6a5c91b 100644
--- a/app/assets/javascripts/discourse/templates/discovery/categories.hbs
+++ b/app/assets/javascripts/discourse/templates/discovery/categories.hbs
@@ -1,4 +1,4 @@
-{{#discovery-categories refresh=refresh}}
+{{#discovery-categories refresh=(action "refresh")}}
   {{component categoryPageStyle
               categories=model.categories
               latestTopicOnly=latestTopicOnly
diff --git a/app/assets/javascripts/discourse/templates/mobile/discovery/categories.hbs b/app/assets/javascripts/discourse/templates/mobile/discovery/categories.hbs
index 907b864..6a5c91b 100644
--- a/app/assets/javascripts/discourse/templates/mobile/discovery/categories.hbs
+++ b/app/assets/javascripts/discourse/templates/mobile/discovery/categories.hbs
@@ -1,4 +1,4 @@
-{{#discovery-categories refresh=refresh}}
+{{#discovery-categories refresh=(action "refresh")}}
   {{component categoryPageStyle
               categories=model.categories
               latestTopicOnly=latestTopicOnly

GitHub sha: 2274d6d7

1 Like