A platform for community discussion. Free, open, simple.
FIX: Make subcategories page more like categories (#29240)
Bianca Nenciuc1f078cacfdc
diff --git a/app/assets/javascripts/discourse/app/components/discovery/categories-display.gjs b/app/assets/javascripts/discourse/app/components/discovery/categories-display.gjsindex 2674b52ce95..e1e0bd8d6ce 100644--- a/app/assets/javascripts/discourse/app/components/discovery/categories-display.gjs+++ b/app/assets/javascripts/discourse/app/components/discovery/categories-display.gjs@@ -36,6 +36,7 @@ const globalComponents = {};export default class CategoriesDisplay extends Component {+ @service router;@service siteSettings;@service site;@@ -69,7 +70,10 @@ export default class CategoriesDisplay extends Component {}get categoriesComponent() {- if (this.args.parentCategory) {+ if (+ this.args.parentCategory &&+ this.router.currentRouteName === "discovery.category"+ ) {return this.#componentForSubcategories;} else {return this.#globalComponent;diff --git a/app/models/category_list.rb b/app/models/category_list.rbindex 02f97560781..53224a8e475 100644--- a/app/models/category_list.rb+++ b/app/models/category_list.rb@@ -133,22 +133,15 @@ class CategoryListdef find_categoriesquery = Category.includes(CategoryList.included_associations).secured(@guardian)-- query =- query.where(- "categories.parent_category_id = ?",- @options[:parent_category_id].to_i,- ) if @options[:parent_category_id].present?-query = self.class.order_categories(query)+ if @options[:parent_category_id].present? || @guardian.can_lazy_load_categories?+ query = query.where(parent_category_id: @options[:parent_category_id])+ end+page = [1, @options[:page].to_i].max- if @guardian.can_lazy_load_categories? && @options[:parent_category_id].blank?- query =- query- .where(parent_category_id: nil)- .limit(CATEGORIES_PER_PAGE)- .offset((page - 1) * CATEGORIES_PER_PAGE)+ if @guardian.can_lazy_load_categories?+ query = query.limit(CATEGORIES_PER_PAGE).offset((page - 1) * CATEGORIES_PER_PAGE)elsif page > 1# Pagination is supported only when lazy load is enabled. If it is not,# everything is returned on page 1.