fix to category search

This commit is contained in:
Joel Varty
2021-06-22 17:12:31 -04:00
parent 3114388069
commit 00227d8bf0
11 changed files with 50 additions and 12 deletions

View File

@@ -1,6 +1,7 @@
import React, { FC } from 'react'
import React, { FC, useEffect } from 'react'
import Search from '@components/search'
import { ModuleWithInit } from '@agility/nextjs'
import { useRouter } from 'next/router'
interface ICustomData {
categories: any

View File

@@ -95,13 +95,16 @@ const Layout: FC<Props> = (props) => {
const {
children,
pageProps: { agilityProps, categories = [], ...pageProps },
pageProps: { agilityProps, ...pageProps },
} = props
const { acceptedCookies, onAcceptCookies } = useAcceptCookies()
const { locale = 'en-US' } = useRouter()
const navBarlinks = categories.slice(0, 2).map((c) => ({
const categories = agilityProps?.globalData?.sitedata?.categoryLinks || []
const navBarlinks = categories.slice(0, 2).map((c:any) => ({
label: c.name,
href: `/search/${c.slug}`,
}))

View File

@@ -42,10 +42,13 @@ export default function Search({ categories, brands }: SearchPropsType) {
const { pathname, category, brand } = useSearchMeta(asPath)
const activeCategory = categories.find((cat: any) => cat.slug === category)
const activeBrand = brands.find(
(b: any) => getSlug(b.node.path) === `brands/${brand}`
)?.node
const { data } = useSearch({
search: typeof q === 'string' ? q : '',
categoryId: activeCategory?.id,