Skip to content

Commit

Permalink
Merge pull request vercel#47 from DSCO-Co/callamsBranch
Browse files Browse the repository at this point in the history
Callams branch
  • Loading branch information
KindaCallam-io committed May 4, 2023
2 parents 414f28c + afe6cc5 commit 5402bb0
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 227 deletions.
2 changes: 1 addition & 1 deletion site/components/common/Navbar/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ const Navbar: FC<NavbarProps> = ({ links }) => {
>
<Link
href={l.href}
className={`${s.link} ${activeMenu === l.href ? s.linkActive : ''} ${l.href === '/collections/clearance' ? 'bg-rose-500 px-5 text-white !important font-bold' : ''}`}
className={`${s.link} ${activeMenu === l.href ? s.linkActive : ''} ${l.href === '/collections/clearance' ? 'bg-rose-400 px-5 text-white !important font-bold' : ''}`}
>
{l.label}
</Link>
Expand Down
2 changes: 1 addition & 1 deletion site/components/product/ProductCard/ProductCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const ProductCard: FC<ProductCardProps> = ({
className={`${rootClassName} rounded-xl`}
aria-label={product.name}
onClick={() => {
// trackProductViewed(product);
trackProductViewed(product)
}}
>
{variant === 'slim' && <SlimCard product={product} imgProps={imgProps} />}
Expand Down
36 changes: 16 additions & 20 deletions site/components/search.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
import { Layout } from '@components/common'
import {
ConnectedPagination,
ConnectedRefinementList,
ConnectedSortBy,
Container,
CustomHierarchicalMenu,
} from '@components/ui'
import type { SearchPropsType } from '@lib/search-props'
import { useRouter } from 'next/router'
import React from 'react'
import { SearchBox } from 'react-instantsearch-hooks-web'
import React, {useState} from 'react'
import { SearchBox, Configure } from 'react-instantsearch-hooks-web'

import { Button } from '@components/ui'
import { Menu as HeadlessMenu } from '@headlessui/react'
import { Configure } from 'react-instantsearch-hooks-web'
import { ConnectedProducts } from './search/ConnectedProducts'

export default function Search({ }: SearchPropsType) {
const router = useRouter()
const initial = router.asPath.split('collections/')[1]
export default function Search({}: SearchPropsType) {

const [useProducts, setProducts] = useState(null);

return (
<Container>
Expand All @@ -36,16 +33,14 @@ export default function Search({ }: SearchPropsType) {
<CustomHierarchicalMenu
attributes={['categories.lvl0', 'categories.lvl1']}
limit={40}
products={useProducts}
/>

<div>
<h3 className="mt-2 mb-2 text-lg font-medium">Brands</h3>
<ConnectedRefinementList
attribute="brandName"
limit={100}
initial={initial}
/>
</div>
<h3 className="mt-2 mb-2 text-lg font-medium">Brands</h3>
<CustomHierarchicalMenu attributes={['brandName']}
limit={40}
products={useProducts}
/>
</div>
</div>
{/* Mobile Filter */}
Expand All @@ -61,12 +56,13 @@ export default function Search({ }: SearchPropsType) {
<CustomHierarchicalMenu
attributes={['categories.lvl0', 'categories.lvl1']}
limit={40}
products={useProducts}
/>
<h3 className="mt-2 mb-2 text-lg font-medium">Brands</h3>
<ConnectedRefinementList
attribute="brandName"
<CustomHierarchicalMenu
attributes={['brandName']}
limit={100}
initial={initial}
products={useProducts}
/>
</div>
<div className="col-span-1 col-start-3">
Expand All @@ -93,7 +89,7 @@ export default function Search({ }: SearchPropsType) {

{/* Products */}

<ConnectedProducts />
<ConnectedProducts setProducts={setProducts} />

{/* Sort */}
<div className="sticky top-0 order-2 max-h-screen col-span-8 overflow-auto lg:top-32 lg:col-span-2 lg:order-none">
Expand Down
13 changes: 11 additions & 2 deletions site/components/search/ConnectedProducts/connnectProducts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,18 @@ import { Skeleton } from '@components/ui'
import rangeMap from '@lib/range-map'

import { useHits } from 'react-instantsearch-hooks-web'
import { useEffect, useRef, useState } from 'react'

const ConnectedProducts = () => {
const { hits } = useHits()

const ConnectedProducts = ({setProducts}) => {

const { hits } = useHits();

//Pass the products via the setProducts State Hook.
useEffect(() => {
const products: CommerceProduct[] = hits.map((hit: any) =>algoliaHitToProduct(hit));
setProducts(products);
}, [hits]);

const algoliaHitToProduct = (hit: any): CommerceProduct => {
return {
Expand Down
192 changes: 0 additions & 192 deletions site/components/ui/ConnectedRefinementList/ConnectedRefinementList.tsx

This file was deleted.

2 changes: 0 additions & 2 deletions site/components/ui/ConnectedRefinementList/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useHierarchicalMenu } from 'react-instantsearch-hooks-web'
import { useRouter } from 'next/router'
import { useEffect, useState } from 'react'
import { trackProductListViewed } from '@Segment/segmentAnalytics'

type HierarchicalMenuItem = {
/**
Expand Down Expand Up @@ -44,13 +45,11 @@ const getCategoryItemFromRouteName = (
return null
}

const CustomHierarchicalMenu = ({ attributes, limit }) => {
const CustomHierarchicalMenu = ({ attributes, limit, products }) => {
const { items, refine } = useHierarchicalMenu({ attributes, limit })
const router = useRouter()

const [isItemsLoaded, setIsItemsLoaded] = useState(false);


// This effect runs when the "items" value changes. And will tell the other to run when the category items are loaded and can be refined.
useEffect(() => {
if (items) {
Expand All @@ -60,6 +59,10 @@ useEffect(() => {
}
}, [items]);

useEffect(() => {

})

useEffect(() => {
if (!isItemsLoaded) {
return;
Expand All @@ -75,13 +78,14 @@ useEffect(() => {
// If the category item is found, refine the results using the category item's value.
if (categoryItem) {
refine(categoryItem.value);
trackProductListViewed(products, categoryItem.value)
}
}
}, [router.asPath, isItemsLoaded]);

const handleItemClick = (item) => {
const formattedCategory = routeFormatter(item.value)
console.log(router.asPath)

if (item.isRefined) {
// Deselect the item by navigating to the base collections path
refine(item.value)
Expand All @@ -94,6 +98,12 @@ useEffect(() => {
shallow: true,
})
}






}

return (
Expand Down
4 changes: 0 additions & 4 deletions site/components/ui/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
export { default as Button } from './Button'
export { default as Collapse } from './Collapse'
export {
default as ConnectedRefinementList,
default as Custom,
} from './ConnectedRefinementList'
export { default as ConnectedSortBy } from './ConnectedSortBy'
export { default as Container } from './Container'
export { default as Grid } from './Grid'
Expand Down

0 comments on commit 5402bb0

Please sign in to comment.