diff --git a/core/app/[locale]/(default)/(faceted)/category/[slug]/_components/sub-categories.tsx b/core/app/[locale]/(default)/(faceted)/category/[slug]/_components/sub-categories.tsx deleted file mode 100644 index f4493681c0..0000000000 --- a/core/app/[locale]/(default)/(faceted)/category/[slug]/_components/sub-categories.tsx +++ /dev/null @@ -1,21 +0,0 @@ -import { graphql } from '~/client/graphql'; - -export const CategoryTreeFragment = graphql(` - fragment CategoryTreeFragment on Site { - categoryTree(rootEntityId: $categoryId) { - entityId - name - path - children { - entityId - name - path - children { - entityId - name - path - } - } - } - } -`); diff --git a/core/app/[locale]/(default)/(faceted)/category/[slug]/page-data.ts b/core/app/[locale]/(default)/(faceted)/category/[slug]/page-data.ts index 375ef2c6df..dc2fa50610 100644 --- a/core/app/[locale]/(default)/(faceted)/category/[slug]/page-data.ts +++ b/core/app/[locale]/(default)/(faceted)/category/[slug]/page-data.ts @@ -6,8 +6,6 @@ import { graphql, VariablesOf } from '~/client/graphql'; import { revalidate } from '~/client/revalidate-target'; import { BreadcrumbsFragment } from '~/components/breadcrumbs/fragment'; -import { CategoryTreeFragment } from './_components/sub-categories'; - const CategoryPageQuery = graphql( ` query CategoryPageQuery($categoryId: Int!) { @@ -22,11 +20,25 @@ const CategoryPageQuery = graphql( metaKeywords } } - ...CategoryTreeFragment + categoryTree(rootEntityId: $categoryId) { + entityId + name + path + children { + entityId + name + path + children { + entityId + name + path + } + } + } } } `, - [BreadcrumbsFragment, CategoryTreeFragment], + [BreadcrumbsFragment], ); type Variables = VariablesOf; diff --git a/core/app/[locale]/(default)/(faceted)/category/[slug]/page.tsx b/core/app/[locale]/(default)/(faceted)/category/[slug]/page.tsx index ef6c70c800..3b3be1c739 100644 --- a/core/app/[locale]/(default)/(faceted)/category/[slug]/page.tsx +++ b/core/app/[locale]/(default)/(faceted)/category/[slug]/page.tsx @@ -53,6 +53,28 @@ async function getBreadcrumbs(props: Props): Promise { })); } +async function getSubCategoriesFilters(props: Props): Promise { + const { slug } = await props.params; + const categoryId = Number(slug); + const data = await getCategoryPageData({ categoryId }); + const t = await getTranslations('FacetedGroup.MobileSideNav'); + + const categoryTree = data.categoryTree[0]; + + if (categoryTree == null || categoryTree.children.length === 0) return []; + + return [ + { + type: 'link-group', + label: t('subCategories'), + links: categoryTree.children.map((category) => ({ + label: category.name, + href: category.path, + })), + }, + ]; +} + async function getTitle(props: Props): Promise { const category = await getCategory(props); @@ -143,7 +165,10 @@ async function getFilters(props: Props): Promise { searchParams: { ...searchParams, ...parsedSearchParams }, }); - return transformedFacets.filter((facet) => facet != null); + const filters = transformedFacets.filter((facet) => facet != null); + const subCategoriesFilters = await getSubCategoriesFilters(props); + + return [...subCategoriesFilters, ...filters]; } async function getSortLabel(): Promise {