-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add cart add wishlist
- Loading branch information
Showing
16 changed files
with
303 additions
and
230 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,49 @@ | ||
import ProductCard from '../../components/Products/ProductCard'; | ||
import ProductCardSkeleton from '../../components/Products/ProductCardSkeleton'; | ||
import { useState } from 'react'; | ||
import { Product } from '../../types/Types'; | ||
import { BiSolidCircle } from 'react-icons/bi'; | ||
import { useSelector } from 'react-redux'; | ||
// import ProductCard from '../../components/Products/ProductCard'; | ||
// import ProductCardSkeleton from '../../components/Products/ProductCardSkeleton'; | ||
// import { Product } from '../../types/Types'; | ||
// import { BiSolidCircle } from 'react-icons/bi'; | ||
// import { useGetProductsQuery } from '../../services/productApi'; | ||
|
||
const perPage = 8; | ||
// const perPage = 10; | ||
|
||
export default function NewArrivals() { | ||
const [currentPage, setCurrentPage] = useState(0); | ||
const { isLoading, productsDataList: productsList } = useSelector((state: any) => state.products); | ||
const next = () => { | ||
setCurrentPage(prevPage => Math.min(prevPage + 1, Math.floor(productsList.length / perPage))); | ||
}; | ||
// export default function NewArrivals() { | ||
// const { data: productsList, isLoading, isSuccess } = useGetProductsQuery() | ||
// // const [currentPage, setCurrentPage] = useState(0); | ||
// // const { isLoading, productsDataList: productsList } = useSelector((state: any) => state.products); | ||
// const next = () => { | ||
// setCurrentPage(prevPage => Math.min(prevPage + 1, Math.floor(productsList.data.length / perPage))); | ||
// }; | ||
|
||
const prev = () => { | ||
setCurrentPage(prevPage => Math.max(prevPage - 1, 0)); | ||
}; | ||
// const prev = () => { | ||
// setCurrentPage(prevPage => Math.max(prevPage - 1, 0)); | ||
// }; | ||
|
||
const startIndex = currentPage * perPage; | ||
const endIndex = startIndex + perPage; | ||
const sortedProducts = [...productsList].sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime()).slice(0, 13); | ||
const allProductsOnPage = sortedProducts.slice(startIndex, endIndex); | ||
// const startIndex = currentPage * perPage; | ||
// const endIndex = startIndex + perPage; | ||
// const sortedProducts = [...productsList.data].sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime()).slice(0, 13); | ||
// const allProductsOnPage = sortedProducts.slice(startIndex, endIndex); | ||
|
||
return ( | ||
<div className='new-arrivals'> | ||
<div className='arrivals-header py-5'> | ||
<h1 className='text-3xl font-bold'>New Arrivals</h1> | ||
</div> | ||
<div className='grid grid-cols-2 gap-0 sm:grid-cols-0 sm:gap-2 md:grid-cols-3 md:gap-3 lg:grid-cols-4 lg:gap-4'> | ||
{isLoading | ||
? Array.from({ length: perPage }).map((_, index) => <ProductCardSkeleton key={index} />) | ||
: allProductsOnPage.map((product: Product) => <ProductCard key={product.id} product={product} />)} | ||
</div> | ||
<div className='next-previous flex justify-center items-center gap-2 p-7'> | ||
<BiSolidCircle | ||
onClick={prev} | ||
className={`cursor-pointer text-2xl ${currentPage === 0 ? 'text-grayColor' : ''}`} | ||
/> | ||
<BiSolidCircle | ||
onClick={next} | ||
className={`cursor-pointer text-2xl ${ | ||
currentPage >= Math.floor(productsList.length / perPage) ? 'text-grayColor' : '' | ||
}`} | ||
/> | ||
</div> | ||
</div> | ||
); | ||
} | ||
// return ( | ||
// <div className='new-arrivals'> | ||
// <div className='arrivals-header py-5'> | ||
// <h1 className='text-3xl font-bold'>New Arrivals</h1> | ||
// </div> | ||
// <div className='flex justify-between items-start flex-wrap gap-1 sm:justify-between md:justify-start md:gap-2'> | ||
// {isLoading | ||
// ? Array.from({ length: perPage }).map((_, index) => <ProductCardSkeleton key={index} />) | ||
// : allProductsOnPage.map((product: Product) => <ProductCard key={product.id} product={product} />)} | ||
// </div> | ||
// <div className='next-previous flex justify-center items-center gap-2 p-7'> | ||
// <BiSolidCircle | ||
// onClick={prev} | ||
// className={`cursor-pointer text-2xl ${currentPage === 0 ? 'text-grayColor' : ''}`} | ||
// /> | ||
// <BiSolidCircle | ||
// onClick={next} | ||
// className={`cursor-pointer text-2xl ${currentPage >= Math.floor(productsList.data.length / perPage) ? 'text-grayColor' : '' | ||
// }`} | ||
// /> | ||
// </div> | ||
// </div> | ||
// ); | ||
// } |
Oops, something went wrong.