forked from crowetic/commerce
Update use-search.tsx
This commit is contained in:
parent
8d801ce5d7
commit
469ed2cdfb
@ -1,13 +1,10 @@
|
|||||||
import useCommerceSearch from '@commerce/products/use-search'
|
import useCommerceSearch from '@commerce/products/use-search'
|
||||||
import {
|
import { getAllProductsQuery } from '@framework/utils/queries'
|
||||||
getAllProductsQuery,
|
|
||||||
getCollectionProductsQuery,
|
|
||||||
} from '@framework/utils/queries'
|
|
||||||
|
|
||||||
import type { Product } from 'framework/bigcommerce/schema'
|
import type { Product } from 'framework/bigcommerce/schema'
|
||||||
import type { HookFetcher } from '@commerce/utils/types'
|
import type { HookFetcher } from '@commerce/utils/types'
|
||||||
import type { SwrOptions } from '@commerce/utils/use-data'
|
import type { SwrOptions } from '@commerce/utils/use-data'
|
||||||
import type { ProductEdge } from '@framework/schema'
|
import type { ProductConnection, ProductEdge } from '@framework/schema'
|
||||||
|
|
||||||
import getSearchVariables from '@framework/utils/get-search-variables'
|
import getSearchVariables from '@framework/utils/get-search-variables'
|
||||||
|
|
||||||
@ -30,25 +27,19 @@ export type SearchProductsData = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const fetcher: HookFetcher<
|
export const fetcher: HookFetcher<
|
||||||
SearchRequestProductsData,
|
SearchProductsData,
|
||||||
SearchProductsInput
|
SearchProductsInput
|
||||||
> = (options, input, fetch) => {
|
> = async (options, input, fetch) => {
|
||||||
return fetch({
|
const resp = await fetch({
|
||||||
query: options?.query,
|
query: options?.query,
|
||||||
method: options?.method,
|
method: options?.method,
|
||||||
variables: {
|
variables: getSearchVariables(input),
|
||||||
...getSearchVariables(input),
|
})
|
||||||
},
|
const edges = resp.products?.edges
|
||||||
}).then(
|
return {
|
||||||
(resp): SearchProductsData => {
|
products: edges?.map(({ node: p }: ProductEdge) => normalizeProduct(p)),
|
||||||
const edges = resp.products?.edges
|
found: !!edges?.length,
|
||||||
|
}
|
||||||
return {
|
|
||||||
products: edges?.map(({ node: p }: ProductEdge) => normalizeProduct(p)),
|
|
||||||
found: !!edges?.length,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function extendHook(
|
export function extendHook(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user