mirror of
https://github.com/vercel/commerce.git
synced 2025-06-19 13:41:22 +00:00
Improved Categories
This commit is contained in:
parent
b47021c4a0
commit
f1b4368149
@ -4,6 +4,8 @@ import filterEdges from '../api/utils/filter-edges'
|
|||||||
import { BigcommerceConfig, getConfig } from '../api'
|
import { BigcommerceConfig, getConfig } from '../api'
|
||||||
import { categoryTreeItemFragment } from '../api/fragments/category-tree'
|
import { categoryTreeItemFragment } from '../api/fragments/category-tree'
|
||||||
import { Category } from '@commerce/types'
|
import { Category } from '@commerce/types'
|
||||||
|
import getSlug from '@lib/get-slug'
|
||||||
|
import { CategoryTreeItem } from '@framework/schema'
|
||||||
|
|
||||||
// Get 3 levels of categories
|
// Get 3 levels of categories
|
||||||
export const getSiteInfoQuery = /* GraphQL */ `
|
export const getSiteInfoQuery = /* GraphQL */ `
|
||||||
@ -49,6 +51,8 @@ export type CategoriesTree = NonNullable<
|
|||||||
GetSiteInfoQuery['site']['categoryTree']
|
GetSiteInfoQuery['site']['categoryTree']
|
||||||
>
|
>
|
||||||
|
|
||||||
|
export type CategoryItem = Pick<CategoryTreeItem, 'entityId' | 'name' | 'path'>
|
||||||
|
|
||||||
export type BrandEdge = NonNullable<
|
export type BrandEdge = NonNullable<
|
||||||
NonNullable<GetSiteInfoQuery['site']['brands']['edges']>[0]
|
NonNullable<GetSiteInfoQuery['site']['brands']['edges']>[0]
|
||||||
>
|
>
|
||||||
@ -57,7 +61,7 @@ export type Brands = BrandEdge[]
|
|||||||
|
|
||||||
export type GetSiteInfoResult<
|
export type GetSiteInfoResult<
|
||||||
T extends { categories: any[]; brands: any[] } = {
|
T extends { categories: any[]; brands: any[] } = {
|
||||||
categories: CategoriesTree
|
categories: Category[]
|
||||||
brands: Brands
|
brands: Brands
|
||||||
}
|
}
|
||||||
> = T
|
> = T
|
||||||
@ -95,11 +99,20 @@ async function getSiteInfo({
|
|||||||
query,
|
query,
|
||||||
{ variables }
|
{ variables }
|
||||||
)
|
)
|
||||||
const categories = data.site?.categoryTree
|
|
||||||
|
let categories = data!.site!.categoryTree?.map(
|
||||||
|
({ entityId, name, path }: any) => ({
|
||||||
|
id: `${entityId}`,
|
||||||
|
name,
|
||||||
|
slug: getSlug(path),
|
||||||
|
path,
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
const brands = data.site?.brands?.edges
|
const brands = data.site?.brands?.edges
|
||||||
|
|
||||||
return {
|
return {
|
||||||
categories: (categories as RecursiveRequired<typeof categories>) ?? [],
|
categories: categories ?? [],
|
||||||
brands: filterEdges(brands as RecursiveRequired<typeof brands>),
|
brands: filterEdges(brands as RecursiveRequired<typeof brands>),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,12 +13,9 @@ import useSearch from '@framework/product/use-search'
|
|||||||
import getAllPages from '@framework/common/get-all-pages'
|
import getAllPages from '@framework/common/get-all-pages'
|
||||||
import getSiteInfo from '@framework/common/get-site-info'
|
import getSiteInfo from '@framework/common/get-site-info'
|
||||||
|
|
||||||
|
import getSlug from '@lib/get-slug'
|
||||||
import rangeMap from '@lib/range-map'
|
import rangeMap from '@lib/range-map'
|
||||||
|
|
||||||
// TODO(bc) Remove this. This should come from the API
|
|
||||||
import getSlug from '@lib/get-slug'
|
|
||||||
|
|
||||||
// TODO (bc) : Remove or standarize this.
|
|
||||||
const SORT = Object.entries({
|
const SORT = Object.entries({
|
||||||
'latest-desc': 'Latest arrivals',
|
'latest-desc': 'Latest arrivals',
|
||||||
'trending-desc': 'Trending',
|
'trending-desc': 'Trending',
|
||||||
|
@ -22,8 +22,8 @@
|
|||||||
"@components/*": ["components/*"],
|
"@components/*": ["components/*"],
|
||||||
"@commerce": ["framework/commerce"],
|
"@commerce": ["framework/commerce"],
|
||||||
"@commerce/*": ["framework/commerce/*"],
|
"@commerce/*": ["framework/commerce/*"],
|
||||||
"@framework": ["framework/vendure"],
|
"@framework": ["framework/bigcommerce"],
|
||||||
"@framework/*": ["framework/vendure/*"]
|
"@framework/*": ["framework/bigcommerce/*"]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"include": ["next-env.d.ts", "**/*.d.ts", "**/*.ts", "**/*.tsx", "**/*.js"],
|
"include": ["next-env.d.ts", "**/*.d.ts", "**/*.ts", "**/*.tsx", "**/*.js"],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user