mirror of
https://github.com/vercel/commerce.git
synced 2025-07-22 20:26:49 +00:00
Added useSearch hook
This commit is contained in:
3
pages/api/bigcommerce/catalog/products.ts
Normal file
3
pages/api/bigcommerce/catalog/products.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import catalogProductsApi from '@lib/bigcommerce/api/catalog/products'
|
||||
|
||||
export default catalogProductsApi()
|
@@ -4,8 +4,6 @@ import { Layout } from '@components/core'
|
||||
import { Grid, Marquee, Hero } from '@components/ui'
|
||||
import { ProductCard } from '@components/product'
|
||||
import getSiteInfo from '@lib/bigcommerce/api/operations/get-site-info'
|
||||
import { useEffect } from 'react'
|
||||
import { useRouter } from 'next/router'
|
||||
|
||||
export async function getStaticProps({ preview }: GetStaticPropsContext) {
|
||||
const { products } = await getAllProducts()
|
||||
@@ -21,12 +19,6 @@ export default function Home({
|
||||
categories,
|
||||
brands,
|
||||
}: InferGetStaticPropsType<typeof getStaticProps>) {
|
||||
const router = useRouter()
|
||||
|
||||
useEffect(() => {
|
||||
router.prefetch('/search')
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<div className="mt-3">
|
||||
<Grid items={products.slice(0, 3)} wrapper={ProductCard} />
|
||||
|
@@ -1,9 +1,10 @@
|
||||
import { GetStaticPropsContext, InferGetStaticPropsType } from 'next'
|
||||
import getAllProducts from '@lib/bigcommerce/api/operations/get-all-products'
|
||||
import { Layout } from '@components/core'
|
||||
import { Grid, Marquee, Hero } from '@components/ui'
|
||||
import { ProductCard } from '@components/product'
|
||||
import getSiteInfo from '@lib/bigcommerce/api/operations/get-site-info'
|
||||
import useSearch from '@lib/bigcommerce/products/use-search'
|
||||
import { Layout } from '@components/core'
|
||||
import { Grid } from '@components/ui'
|
||||
import { ProductCard } from '@components/product'
|
||||
import { useRouter } from 'next/router'
|
||||
|
||||
export async function getStaticProps({ preview }: GetStaticPropsContext) {
|
||||
@@ -21,6 +22,10 @@ export default function Home({
|
||||
brands,
|
||||
}: InferGetStaticPropsType<typeof getStaticProps>) {
|
||||
const router = useRouter()
|
||||
const search = useSearch({ search: router.query.search as string })
|
||||
|
||||
console.log('SEARCH', search)
|
||||
|
||||
return (
|
||||
<div className="grid grid-cols-12 gap-8 mt-3 mb-20">
|
||||
<div className="col-span-2">
|
||||
|
Reference in New Issue
Block a user