summaryrefslogtreecommitdiff
path: root/src/pages/index.js
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2023-02-03 17:03:45 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2023-02-03 17:03:45 +0700
commitcd01ba82733062db99075ad7690bdb52fb85745a (patch)
treedf86ed690452945463abc77263ac058d5b7f9823 /src/pages/index.js
parent87af032177192ed1d5d7c68cab911ed102e647bc (diff)
no message
Diffstat (limited to 'src/pages/index.js')
-rw-r--r--src/pages/index.js50
1 files changed, 5 insertions, 45 deletions
diff --git a/src/pages/index.js b/src/pages/index.js
index 49300883..fcf47b34 100644
--- a/src/pages/index.js
+++ b/src/pages/index.js
@@ -16,6 +16,8 @@ import Layout from "@/components/layouts/Layout";
import ManufactureCard from "@/components/manufactures/ManufactureCard";
import Footer from "@/components/layouts/Footer";
import Image from "@/components/elements/Image";
+import ProductCategories from "@/components/products/ProductCategories";
+import { LazyLoadComponent } from "react-lazy-load-image-component";
export async function getServerSideProps() {
const heroBanners = await apiOdoo('GET', `/api/v1/banner?type=index-a-1`);
@@ -26,8 +28,6 @@ export async function getServerSideProps() {
export default function Home({ heroBanners }) {
const [manufactures, setManufactures] = useState(null);
const [popularProducts, setPopularProducts] = useState(null);
- const [categoryProductIds, setCategoryProductIds] = useState(null);
- const [categoryProducts, setCategoryProducts] = useState([]);
useEffect(() => {
const getManufactures = async () => {
@@ -43,33 +43,6 @@ export default function Home({ heroBanners }) {
getPopularProducts();
}, []);
- useEffect(() => {
- const getCategoryProductIds = async () => {
- if (!categoryProductIds) {
- const dataCategoryProductIds = await apiOdoo('GET', '/api/v1/categories_homepage/ids');
- setCategoryProductIds(dataCategoryProductIds)
- }
- }
- getCategoryProductIds();
- }, [ categoryProductIds ]);
-
- useEffect(() => {
- const getCategoryProducts = async () => {
- const currentCategoryId = categoryProductIds ? categoryProductIds[categoryProducts.length] : false;
- if (currentCategoryId) {
- const isAdded = categoryProducts.findIndex((categoryProduct) => categoryProduct.id == currentCategoryId);
- if (isAdded < 0) {
- const dataCategoryProducts = await apiOdoo('GET', `/api/v1/categories_homepage?id=${currentCategoryId}`);
- setCategoryProducts((categoryProducts) => ([
- ...categoryProducts,
- ...dataCategoryProducts
- ]));
- }
- }
- }
- getCategoryProducts();
- }, [ categoryProducts, categoryProductIds ]);
-
return (
<>
<Header title='Home - Indoteknik' />
@@ -104,22 +77,9 @@ export default function Home({ heroBanners }) {
<ProductSlider products={popularProducts} simpleProductTitleLine />
</div>
- { categoryProducts?.map((categoryProduct, index) => (
- <div className="my-6 px-4 pt-4 relative" key={index}>
- <ProductSlider
- products={categoryProduct ? {
- products: categoryProduct.products,
- banner: {
- image: categoryProduct.image,
- name: categoryProduct.name,
- url: `/shop/search?category=${categoryProduct.name}`
- }
- } : null}
- simpleProductTitleLine
- bannerMode
- />
- </div>
- )) }
+ <LazyLoadComponent>
+ <ProductCategories />
+ </LazyLoadComponent>
<div className="px-4">
<h5 className="h2 mb-2">Platform Belanja B2B Alat Teknik & Industri di Indonesia</h5>