mirror of
https://github.com/vercel/commerce.git
synced 2025-06-08 17:26:59 +00:00
feat: Add categories
This commit is contained in:
parent
703446013b
commit
3c64a258c6
@ -6,6 +6,7 @@
|
|||||||
"vendor": "Commerce Layer",
|
"vendor": "Commerce Layer",
|
||||||
"path": "/women-long-sleeve-shirt",
|
"path": "/women-long-sleeve-shirt",
|
||||||
"slug": "women-long-sleeve-shirt",
|
"slug": "women-long-sleeve-shirt",
|
||||||
|
"categoryId": "clothings",
|
||||||
"price": { "value": 50, "currencyCode": "USD" },
|
"price": { "value": 50, "currencyCode": "USD" },
|
||||||
"descriptionHtml": "<p><span>This relaxed long sleeve tee combines the best of both worlds, proving that cozy can also be chic. 65/35 polyester/viscose. Drop shoulder. Curved bottom hem.</span></p>",
|
"descriptionHtml": "<p><span>This relaxed long sleeve tee combines the best of both worlds, proving that cozy can also be chic. 65/35 polyester/viscose. Drop shoulder. Curved bottom hem.</span></p>",
|
||||||
"images": [
|
"images": [
|
||||||
@ -112,6 +113,7 @@
|
|||||||
"vendor": "Commerce Layer",
|
"vendor": "Commerce Layer",
|
||||||
"path": "/white-enamel-mug",
|
"path": "/white-enamel-mug",
|
||||||
"slug": "white-enamel-mug",
|
"slug": "white-enamel-mug",
|
||||||
|
"categoryId": "household",
|
||||||
"price": { "value": 100, "currencyCode": "USD" },
|
"price": { "value": 100, "currencyCode": "USD" },
|
||||||
"descriptionHtml": "<p><span>Lightweight and durable, this mug is a must-have for every devoted camper. Use it for your favorite beverage or a hot meal, and attach it to your bag for easy access on a hike. Ready for your next camping trip?</span></p>",
|
"descriptionHtml": "<p><span>Lightweight and durable, this mug is a must-have for every devoted camper. Use it for your favorite beverage or a hot meal, and attach it to your bag for easy access on a hike. Ready for your next camping trip?</span></p>",
|
||||||
"images": [
|
"images": [
|
||||||
@ -179,6 +181,7 @@
|
|||||||
"vendor": "Commerce Layer",
|
"vendor": "Commerce Layer",
|
||||||
"path": "/black-visor-flexfit",
|
"path": "/black-visor-flexfit",
|
||||||
"slug": "black-visor-flexfit",
|
"slug": "black-visor-flexfit",
|
||||||
|
"categoryId": "clothings",
|
||||||
"price": { "value": 39.5, "currencyCode": "USD" },
|
"price": { "value": 39.5, "currencyCode": "USD" },
|
||||||
"descriptionHtml": "<p><span>A visor is perfect for the days when you’re not in the mood for a cap, but you still want to protect your peepers from the blinding sun. Made of a quick-drying fabric, it’ll be right for sports activities or just a casual stroll around.</span></p>",
|
"descriptionHtml": "<p><span>A visor is perfect for the days when you’re not in the mood for a cap, but you still want to protect your peepers from the blinding sun. Made of a quick-drying fabric, it’ll be right for sports activities or just a casual stroll around.</span></p>",
|
||||||
"images": [
|
"images": [
|
||||||
@ -253,6 +256,7 @@
|
|||||||
"path": "/black-face-mask",
|
"path": "/black-face-mask",
|
||||||
"slug": "black-face-mask",
|
"slug": "black-face-mask",
|
||||||
"price": { "value": 15, "currencyCode": "USD" },
|
"price": { "value": 15, "currencyCode": "USD" },
|
||||||
|
"categoryId": "clothings",
|
||||||
"descriptionHtml": "<p><span>Durable double-layer, washable cloth face mask. The center seam and elastic ear loops give the mask a close fit, and the treated fabric ensures that it will serve you well.</span></p>",
|
"descriptionHtml": "<p><span>Durable double-layer, washable cloth face mask. The center seam and elastic ear loops give the mask a close fit, and the treated fabric ensures that it will serve you well.</span></p>",
|
||||||
"images": [
|
"images": [
|
||||||
{
|
{
|
||||||
@ -307,6 +311,7 @@
|
|||||||
"vendor": "Commerce Layer",
|
"vendor": "Commerce Layer",
|
||||||
"path": "/gray-women-long-sleeve-shirt",
|
"path": "/gray-women-long-sleeve-shirt",
|
||||||
"slug": "gray-women-long-sleeve-shirt",
|
"slug": "gray-women-long-sleeve-shirt",
|
||||||
|
"categoryId": "clothings",
|
||||||
"price": { "value": 50, "currencyCode": "USD" },
|
"price": { "value": 50, "currencyCode": "USD" },
|
||||||
"descriptionHtml": "<p><span>This relaxed long sleeve tee combines the best of both worlds, proving that cozy can also be chic. 65/35 polyester/viscose. Drop shoulder. Curved bottom hem.</span></p>",
|
"descriptionHtml": "<p><span>This relaxed long sleeve tee combines the best of both worlds, proving that cozy can also be chic. 65/35 polyester/viscose. Drop shoulder. Curved bottom hem.</span></p>",
|
||||||
"images": [
|
"images": [
|
||||||
@ -401,6 +406,7 @@
|
|||||||
"vendor": "Commerce Layer",
|
"vendor": "Commerce Layer",
|
||||||
"path": "/white-face-mask",
|
"path": "/white-face-mask",
|
||||||
"slug": "white-face-mask",
|
"slug": "white-face-mask",
|
||||||
|
"categoryId": "clothings",
|
||||||
"price": { "value": 15, "currencyCode": "USD" },
|
"price": { "value": 15, "currencyCode": "USD" },
|
||||||
"descriptionHtml": "<p><span>Durable double-layer, washable cloth face mask. The center seam and elastic ear loops give the mask a close fit, and the treated fabric ensures that it will serve you well.</span></p>",
|
"descriptionHtml": "<p><span>Durable double-layer, washable cloth face mask. The center seam and elastic ear loops give the mask a close fit, and the treated fabric ensures that it will serve you well.</span></p>",
|
||||||
"images": [
|
"images": [
|
||||||
@ -456,6 +462,7 @@
|
|||||||
"vendor": "Commerce Layer",
|
"vendor": "Commerce Layer",
|
||||||
"path": "/white-beanie",
|
"path": "/white-beanie",
|
||||||
"slug": "white-beanie",
|
"slug": "white-beanie",
|
||||||
|
"categoryId": "clothings",
|
||||||
"price": { "value": 20, "currencyCode": "USD" },
|
"price": { "value": 20, "currencyCode": "USD" },
|
||||||
"descriptionHtml": "<p><span>Soft double-layered customizable beanie. 95% polyester, 5% spandex. Regular fit. Accurately printed, cut, and hand-sewn.</span></p>",
|
"descriptionHtml": "<p><span>Soft double-layered customizable beanie. 95% polyester, 5% spandex. Regular fit. Accurately printed, cut, and hand-sewn.</span></p>",
|
||||||
"images": [
|
"images": [
|
||||||
@ -511,6 +518,7 @@
|
|||||||
"vendor": "Commerce Layer",
|
"vendor": "Commerce Layer",
|
||||||
"path": "/white-duffle-bag",
|
"path": "/white-duffle-bag",
|
||||||
"slug": "white-duffle-bag",
|
"slug": "white-duffle-bag",
|
||||||
|
"categoryId": "featured",
|
||||||
"price": { "value": 250, "currencyCode": "USD" },
|
"price": { "value": 250, "currencyCode": "USD" },
|
||||||
"descriptionHtml": "<p><span>The perfect spacious bag no matter the occasion. It’s great for packing exercise gear when heading to the gym, or throwing in necessities and going on an adventure.</span></p>",
|
"descriptionHtml": "<p><span>The perfect spacious bag no matter the occasion. It’s great for packing exercise gear when heading to the gym, or throwing in necessities and going on an adventure.</span></p>",
|
||||||
"images": [
|
"images": [
|
||||||
|
@ -3,13 +3,18 @@ import useSearch, { UseSearch } from '@commerce/product/use-search'
|
|||||||
import data from '../data.json'
|
import data from '../data.json'
|
||||||
export default useSearch as UseSearch<typeof handler>
|
export default useSearch as UseSearch<typeof handler>
|
||||||
|
|
||||||
const productsFinder = (s: string) => {
|
const productsFinder = (s: string, c?: string, b?: string) => {
|
||||||
const { products } = data
|
const { products } = data
|
||||||
return s
|
let p = products
|
||||||
? products.filter(
|
if (s)
|
||||||
(p) => p.name.toLowerCase().search(s.toLowerCase()) !== -1
|
p = p.filter((p) => p.name.toLowerCase().search(s.toLowerCase()) !== -1)
|
||||||
|
if (c)
|
||||||
|
p = p.filter(
|
||||||
|
(p) => p.categoryId.toLowerCase().search(c.toLowerCase()) !== -1
|
||||||
)
|
)
|
||||||
: []
|
if (b)
|
||||||
|
p = p.filter((p) => p.brandId.toLowerCase().search(b.toLowerCase()) !== -1)
|
||||||
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
export const handler: SWRHook<any> = {
|
export const handler: SWRHook<any> = {
|
||||||
@ -21,8 +26,8 @@ export const handler: SWRHook<any> = {
|
|||||||
},
|
},
|
||||||
useHook:
|
useHook:
|
||||||
({ useData }) =>
|
({ useData }) =>
|
||||||
({ search }) => {
|
({ search, categoryId, brandId }) => {
|
||||||
const products = productsFinder(search)
|
const products = productsFinder(search, categoryId, brandId)
|
||||||
return {
|
return {
|
||||||
data:
|
data:
|
||||||
products.length > 0
|
products.length > 0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user