Skip to content

Commit

Permalink
Merge pull request vercel#13 from DSCO-Co/callamsBranch
Browse files Browse the repository at this point in the history
Callams branch
  • Loading branch information
KindaCallam-io committed Mar 30, 2023
2 parents ac4a724 + ce01839 commit 39e9b0b
Show file tree
Hide file tree
Showing 16 changed files with 50 additions and 19 deletions.
6 changes: 3 additions & 3 deletions packages/bigcommerce/src/lib/normalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ function normalizeLineItem(item: any): LineItem {
}

export function normalizeCategory(category: BCCategory): Category {
console.log('------------------ DEBUG ------------------');
console.log(category);
console.log('------------------ DEBUG ------------------');
// console.log('------------------ DEBUG ------------------');
// console.log(category);
// console.log('------------------ DEBUG ------------------');
return {
id: `${category.entityId}`,
name: category.name,
Expand Down
9 changes: 7 additions & 2 deletions site/components/common/Avatar/Avatar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FC, useRef, useEffect } from 'react'
import { FC, useRef } from 'react'
import { useUserAvatar } from '@lib/hooks/useUserAvatar'

interface Props {
Expand All @@ -13,12 +13,17 @@ const Avatar: FC<Props> = ({}) => {
return (
<div
ref={ref}
style={{ backgroundImage: userAvatar }}
className="inline-block h-8 w-8 rounded-full border-2 border-primary hover:border-secondary focus:border-secondary transition-colors ease-linear"
>
<img
src={userAvatar}
alt="User Avatar"
className="rounded-full h-full w-full object-cover"
/>
{/* Add an image - We're generating a gradient as placeholder <img></img> */}
</div>
)
}

export default Avatar

2 changes: 1 addition & 1 deletion site/components/common/Navbar/Navbar.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
}

.logo {
@apply cursor-pointer rounded-full border transform duration-100 ease-in-out;
@apply cursor-pointer rounded-full transform duration-100 ease-in-out;

&:hover {
@apply shadow-md;
Expand Down
2 changes: 1 addition & 1 deletion site/components/product/ProductView/ProductView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const ProductView: FC<ProductViewProps> = ({ product, relatedProducts }) => {
noNameTag
product={p}
key={p.path}
variant="simple"
variant="simple-stylized"
className="animated fadeIn"
imgProps={{
alt: p.name,
Expand Down
21 changes: 16 additions & 5 deletions site/components/search.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import cn from 'clsx'
import type { SearchPropsType } from '@lib/search-props'
import type { SearchPropsType } from '@lib/search-props'
import commerce from '@lib/api/commerce'
import ErrorMessage from './ui/ErrorMessage'
import type { GetStaticPropsContext, InferGetStaticPropsType } from 'next'

import Link from 'next/link'
import { useState } from 'react'
Expand Down Expand Up @@ -34,10 +37,10 @@ import {
getDesignerPath,
useSearchMeta,
} from '@lib/search'
import ErrorMessage from './ui/ErrorMessage'
import commerce from '@lib/api/commerce'

export default function Search({ categories, brands }: SearchPropsType) {


export default function Search({categories, brands, products }: SearchPropsType) {
const [currentPage, setCurrentPage] = useState(1)
const itemsPerPage = 9

Expand All @@ -61,11 +64,13 @@ export default function Search({ categories, brands }: SearchPropsType) {
// of those is selected
const query = filterQuery({ sort })


const { pathname, category, brand } = useSearchMeta(asPath)

const activeCategory = categories.find((cat: any) => cat.slug === category)
const activeBrand = brands.find((b: Brand) => b.slug === brand)


const { data, error } = useSearch({
search: typeof q === 'string' ? q : '',
categoryId: activeCategory?.id,
Expand All @@ -80,6 +85,11 @@ export default function Search({ categories, brands }: SearchPropsType) {
return <ErrorMessage error={error} />
}


console.log("all products", products)
console.log("all categories", categories)


const handleClick = (event: any, filter: string) => {
if (filter !== activeFilter) {
setToggleFilter(true)
Expand Down Expand Up @@ -304,6 +314,7 @@ export default function Search({ categories, brands }: SearchPropsType) {
<Products
categories={categories}
brands={brands}
products={products}
currentPage={currentPage}
itemsPerPage={itemsPerPage}
/>
Expand Down Expand Up @@ -407,7 +418,7 @@ export default function Search({ categories, brands }: SearchPropsType) {
</div>
</div>
<Pagination
totalItems={data ? data.products.length : 0}
totalItems={products ? products.length : 0}
itemsPerPage={itemsPerPage}
currentPage={currentPage}
onPageChange={handlePageChange}
Expand Down
4 changes: 3 additions & 1 deletion site/components/search/Products/products.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ import ErrorMessage from '../../ui/ErrorMessage'
interface ProductsProps extends ProductsPropsType {
currentPage: number
itemsPerPage: number
products: any
}

export default function Products({
categories,
brands,
products,
currentPage,
itemsPerPage,
}: ProductsProps) {
Expand Down Expand Up @@ -60,7 +62,7 @@ export default function Products({
return <ErrorMessage error={error} />
}

const paginatedProducts = data?.products.slice(
const paginatedProducts = products.slice(
(currentPage - 1) * itemsPerPage,
currentPage * itemsPerPage
)
Expand Down
2 changes: 1 addition & 1 deletion site/components/ui/Pagination/Pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function Pagination({
}

return (
<nav className="flex items-center justify-between border-t border-gray-200 px-4 sm:px-0 mb-8">
<nav className="flex items-center justify-between border-t border-gray-200 px-4 sm:px-0 mb-8 mx-auto max-w-4xl">
<div className="-mt-px flex">
<a
href="#"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@
transition-timing-function: ease;
transition-property: transform, fill;
color: currentColor;

}

.icon.loading {
fill: var(--pink-light);
color: transparent; /* Add this line */
}

.icon.inWishlist {
fill: var(--pink);
color: transparent; /* Add this line */
}

@screen lg {
Expand Down
11 changes: 6 additions & 5 deletions site/lib/hooks/useUserAvatar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ export const useUserAvatar = (name = 'userAvatar') => {
const { userAvatar, setUserAvatar } = useUI()

useEffect(() => {
if (!userAvatar && localStorage.getItem(name)) {
if (!userAvatar && localStorage.getItem(name) && localStorage.getItem(name)?.endsWith('.png')) {
// Get bg from localStorage and push it to the context.
setUserAvatar(localStorage.getItem(name))
}
if (!localStorage.getItem(name)) {
// bg not set locally, generating one, setting localStorage and context to persist.
const bg = getRandomPairOfColors()
const value = `linear-gradient(140deg, ${bg[0]}, ${bg[1]} 100%)`
// In useUserAvatar hookc
if (localStorage.getItem(name)) {
// Avatar not set locally, using the image and setting localStorage and context to persist.
const randomPuppy = Math.floor(Math.random() * 5) + 1 // Generates a random number between 1 and 5
const value = `/puppies/puppy_icon_${randomPuppy}.png`
localStorage.setItem(name, value)
setUserAvatar(value)
}
Expand Down
9 changes: 9 additions & 0 deletions site/lib/search-props.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,22 @@ export async function getSearchStaticProps({
locales,
}: GetStaticPropsContext) {
const config = { locale, locales }
const productsPromise = commerce.getAllProducts({
variables: { first: 50},
config,
preview,
// Saleor provider only
...({ featured: true } as any),
})
const pagesPromise = commerce.getAllPages({ config, preview })
const siteInfoPromise = commerce.getSiteInfo({ config, preview })
const { pages } = await pagesPromise
const { products } = await productsPromise
const { categories, brands } = await siteInfoPromise
return {
props: {
pages,
products,
categories,
brands,
},
Expand Down
Binary file added site/public/puppies/puppy_icon_1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added site/public/puppies/puppy_icon_2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added site/public/puppies/puppy_icon_3.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added site/public/puppies/puppy_icon_4.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added site/public/puppies/puppy_icon_5.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added site/public/puppy_icon_1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 39e9b0b

Please sign in to comment.