forked from crowetic/commerce
bug fixes
This commit is contained in:
parent
32da7ddcc1
commit
8905089fd7
@ -58,7 +58,7 @@ const getProducts: ProductsHandlers['getProducts'] = async ({
|
|||||||
},
|
},
|
||||||
{}
|
{}
|
||||||
)
|
)
|
||||||
const products: Products = []
|
const products: Products = found ? [] : graphqlData.products
|
||||||
|
|
||||||
// Populate the products array with the graphql products, in the order
|
// Populate the products array with the graphql products, in the order
|
||||||
// assigned by the list of entity ids
|
// assigned by the list of entity ids
|
||||||
|
@ -31,9 +31,8 @@ export default function Search({
|
|||||||
const { asPath } = router
|
const { asPath } = router
|
||||||
const { q, sort } = router.query
|
const { q, sort } = router.query
|
||||||
const query = filterQuery({ q, sort })
|
const query = filterQuery({ q, sort })
|
||||||
const pathname = asPath.split('?')[0]
|
|
||||||
|
|
||||||
const { category, brand } = useSearchMeta(asPath)
|
const { pathname, category, brand } = useSearchMeta(asPath)
|
||||||
const activeCategory = categories.find(
|
const activeCategory = categories.find(
|
||||||
(cat) => getSlug(cat.path) === category
|
(cat) => getSlug(cat.path) === category
|
||||||
)
|
)
|
||||||
|
@ -1,11 +1,16 @@
|
|||||||
import { useEffect, useState } from 'react'
|
import { useEffect, useState } from 'react'
|
||||||
|
|
||||||
export function useSearchMeta(asPath: string) {
|
export function useSearchMeta(asPath: string) {
|
||||||
|
const [pathname, setPathname] = useState<string>('/search')
|
||||||
const [category, setCategory] = useState<string | undefined>()
|
const [category, setCategory] = useState<string | undefined>()
|
||||||
const [brand, setBrand] = useState<string | undefined>()
|
const [brand, setBrand] = useState<string | undefined>()
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const parts = asPath.split('/')
|
// Only access asPath after hydration to avoid a server mismatch
|
||||||
|
const path = asPath.split('?')[0]
|
||||||
|
const parts = path.split('/')
|
||||||
|
|
||||||
|
console.log('P', parts)
|
||||||
|
|
||||||
let c = parts[2]
|
let c = parts[2]
|
||||||
let b = parts[3]
|
let b = parts[3]
|
||||||
@ -14,11 +19,12 @@ export function useSearchMeta(asPath: string) {
|
|||||||
c = parts[4]
|
c = parts[4]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setPathname(path)
|
||||||
if (c !== category) setCategory(c)
|
if (c !== category) setCategory(c)
|
||||||
if (b !== brand) setBrand(b)
|
if (b !== brand) setBrand(b)
|
||||||
}, [asPath])
|
}, [asPath])
|
||||||
|
|
||||||
return { category, brand }
|
return { pathname, category, brand }
|
||||||
}
|
}
|
||||||
|
|
||||||
// Removes empty query parameters from the query object
|
// Removes empty query parameters from the query object
|
||||||
|
Loading…
x
Reference in New Issue
Block a user