CKAD-75-store-categories-categoryPages

This commit is contained in:
Aditya 2021-11-17 15:34:48 +05:30
parent 737612656f
commit a85584d999
6 changed files with 34334 additions and 5837 deletions

View File

@ -31,4 +31,4 @@ const fetchGraphqlApi: (getConfig: () => ElasticpathConfig) => GraphQLFetcher =
return { data: json.data, res } return { data: json.data, res }
} }
export default fetchGraphqlApi export default fetchGraphqlApi

View File

@ -1,17 +1,53 @@
import { SWRHook } from '@commerce/utils/types' import { SWRHook } from '@commerce/utils/types'
import useSearch, { UseSearch } from '@commerce/product/use-search' import useSearch, { UseSearch } from '@commerce/product/use-search'
import type { SearchProductsHook } from '../types/product'
import epClient from '../utils/ep-client'
import normalizeProducts from '../utils/normalize'
export default useSearch as UseSearch<typeof handler> export default useSearch as UseSearch<typeof handler>
export const handler: SWRHook<any> = { export type SearchProductsInput = {
search?: string
sort?: string
}
export const handler: SWRHook<SearchProductsHook> = {
fetchOptions: { fetchOptions: {
query: '', url: 'Products',
method: 'All',
}, },
async fetcher({ input, options, fetch }) {}, async fetcher({ input: { search, sort }, options, fetch }) {
useHook: () => () => { // Use a dummy base as we only care about the relative path
return { let url = new URL(options.url!, 'http://api.moltin.com')
data: {
products: [], if (search) url.searchParams.set('search', search)
}, if (sort) url.searchParams.set('sort', sort)
if(sort){
let productsRes = await epClient.PCM.Sort(sort).All();
let products = await normalizeProducts(productsRes.data);
return {
products: products,
}
}
else{
let productsRes = await epClient.PCM.All()
let products = await normalizeProducts(productsRes.data);
return {
products: products
}
} }
}, },
} useHook: ({ useData }) => (input = {}) => {
return useData({
input: [
['search', input.search],
['sort', input.sort],
],
swrOptions: {
revalidateOnFocus: false,
...input.swrOptions,
},
})
},
}

View File

@ -0,0 +1 @@
export * from '@commerce/types/product'

View File

@ -31,4 +31,4 @@ const fetchGraphqlApi: (getConfig: () => LocalConfig) => GraphQLFetcher =
return { data: json.data, res } return { data: json.data, res }
} }
export default fetchGraphqlApi export default fetchGraphqlApi

28456
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

11656
yarn.lock

File diff suppressed because it is too large Load Diff