FIX: ensures category order keeps consistent (#10165)

FIX: ensures category order keeps consistent (#10165)

Before this change:

  • first full page load would get category defaults defined un cateory settings
  • a navigation to a topic and then back to categories list would reset defaut to the ones defined in discovery/topics
diff --git a/app/assets/javascripts/discourse/app/controllers/discovery/topics.js b/app/assets/javascripts/discourse/app/controllers/discovery/topics.js
index 2434da4..3ea86d3 100644
--- a/app/assets/javascripts/discourse/app/controllers/discovery/topics.js
+++ b/app/assets/javascripts/discourse/app/controllers/discovery/topics.js
@@ -21,7 +21,7 @@ const controllerOpts = {
   showTopicPostBadges: not("discoveryTopics.new"),
   redirectedReason: alias("currentUser.redirected_to_top.reason"),
 
-  order: "default",
+  order: null,
   ascending: false,
   expandGloballyPinned: false,
   expandAllPinned: false,
@@ -37,11 +37,11 @@ const controllerOpts = {
     changeSort(sortBy) {
       if (sortBy === this.order) {
         this.toggleProperty("ascending");
+        this.model.refreshSort(sortBy, this.ascending);
       } else {
         this.setProperties({ order: sortBy, ascending: false });
+        this.model.refreshSort(sortBy, false);
       }
-
-      this.model.refreshSort(sortBy, this.ascending);
     },
 
     // Show newly inserted topics
diff --git a/lib/topic_query.rb b/lib/topic_query.rb
index 5f86586..d8cdfe8 100644
--- a/lib/topic_query.rb
+++ b/lib/topic_query.rb
@@ -684,6 +684,9 @@ class TopicQuery
         if sort_order
           options[:order] = sort_order
           options[:ascending] = !!sort_ascending ? 'true' : 'false'
+        else
+          options[:order] = 'default'
+          options[:ascending] = 'false'
         end
       end
     end

GitHub sha: 9b7000db

This commit appears in #10165 which was merged by jjaffeux.