FIX: Make subcategories page more like categories (#29240)

The subcategories page was not paginated and it was using the
subcategory style from the category settings. The same page style should
be used for categories and subcategories page.
This commit is contained in:
Bianca Nenciu 2024-10-17 19:47:53 +03:00 committed by GitHub
parent 23c486799f
commit c1f078cacf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 14 deletions

View File

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

View File

@ -133,22 +133,15 @@ class CategoryList
def find_categories
query = 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.