mirror of
https://github.com/vercel/commerce.git
synced 2025-06-19 05:31:22 +00:00
Fixes in search hook
This commit is contained in:
parent
874cf9d5b3
commit
7f2a0d903a
@ -22,9 +22,9 @@ export const handler: SWRHook<SearchProductsHook> = {
|
||||
|
||||
if (search) url.searchParams.set('search', search)
|
||||
if (Number.isInteger(categoryId))
|
||||
url.searchParams.set('category', String(categoryId))
|
||||
url.searchParams.set('categoryId', String(categoryId))
|
||||
if (Number.isInteger(brandId))
|
||||
url.searchParams.set('brand', String(brandId))
|
||||
url.searchParams.set('brandId', String(brandId))
|
||||
if (sort) url.searchParams.set('sort', sort)
|
||||
|
||||
return fetch({
|
||||
|
@ -55,7 +55,10 @@ export type ProductTypes = {
|
||||
}
|
||||
|
||||
export type SearchProductsHook<T extends ProductTypes = ProductTypes> = {
|
||||
data: T['product'][]
|
||||
data: {
|
||||
products: T['product'][]
|
||||
found: boolean
|
||||
}
|
||||
body: T['searchBody']
|
||||
input: T['searchBody']
|
||||
fetcherInput: T['searchBody']
|
||||
@ -65,13 +68,7 @@ export type ProductsSchema<T extends ProductTypes = ProductTypes> = {
|
||||
endpoint: {
|
||||
options: {}
|
||||
handlers: {
|
||||
getProducts: {
|
||||
data: {
|
||||
products: T['product'][]
|
||||
found: boolean
|
||||
}
|
||||
body: SearchProductsHook<T>['body']
|
||||
}
|
||||
getProducts: SearchProductsHook<T>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,6 @@ import {
|
||||
getDesignerPath,
|
||||
useSearchMeta,
|
||||
} from '@lib/search'
|
||||
import { Product } from '@commerce/types'
|
||||
|
||||
// TODO(bc) Remove this. This should come from the API
|
||||
import getSlug from '@lib/get-slug'
|
||||
|
Loading…
x
Reference in New Issue
Block a user