🫢Step by Step Study (part 2)👆

Step 1: ProductCard.component

import Link from 'next/link';
import Image from 'next/image';
import { paddedPrice } from './../../utils/functions/functions';
const ProductCard = ({ databaseId, name, price, slug, image, }: ProductCardProps) => {
  if (price) {
    price = paddedPrice(price as string, ' ');
  }
  return (
    <div className="group">
      <div className="aspect-[3/4] overflow-hidden bg-gray-100">
        <Link href={`/product/${slug}?id=${databaseId}`} className='relative block h-full'>
          {image?.sourceUrl ? (
            <Image
              src={image.sourceUrl}
              alt={name}
              fill
              className="w-full h-full object-cover object-center transition duration-300 group-hover:scale-105"
              priority={databaseId === 1}
              sizes="(max-width: 640px) 100vw, (max-width: 1024px) 50vw, 25vw"
            />
          ) : (
            <div className="h-full w-full bg-gray-100 flex items-center justify-center">
              <span className="text-gray-400">No image</span>
            </div>
          )}
        </Link>
      </div>
      <Link href={`/product/${slug}?id=${databaseId}`}>
        <div className="mt-4">
          <p className="text-base font-bold text-center cursor-pointer hover:text-gray-600 transition-colors">
            {name}
          </p>
        </div>
      </Link>
      <div className="mt-2 text-center">
        <span className="text-gray-900">{price}</span>
      </div>
    </div>
  )
}
export default ProductCard;

Step 2: Stady getUniqueProductTypes

src\components\Product\ProductFilters.component.tsx

src\components\Product\ProductList.component.tsx

— Tìm hiểu new Maparrow-up-right

Step 3. Study toggleProductType

src\hooks\useProductFilters.ts

src\components\Product\ProductList.component.tsx

src\components\Product\ProductFilters.component.tsx

src\components\UI\Checkbox.component.tsx

Step 4: selectedTypes

Kết quả bộ lọc

src\hooks\useProductFilters.ts

file-archive
86KB

Step 5.1 : add allPaColors, allPaSizes

src\utils\gql\GQL_QUERIES.ts

Step 5.2 sizes, toggleSize

file-archive
86KB

Step 5.3 colors, toogleColor

src\components\Product\ProductFilters.component.tsx

src\components\Product\ProductList.component.tsx

src\hooks\useProductFilters.ts

Step 5.4 Nghiên cứu cách sử dụng src\hooks\useProductFilters.ts bằng cách sử dụng một ví dụ test, setTest

Step 6. RangeSlider

file-archive
87KB

Step 7. Sorting

src\hooks\useProductFilters.ts

src\components\Product\ProductList.component.tsx

Step 8 categories

src\pages\categories.tsx

src\components\Category\Categories.component.tsx

Step 9 Category Detail

src\pages\category\[slug].tsx

file-archive
90KB

Source code gốc

file-archive
589KB

Last updated

Was this helpful?