summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/pages/index.js22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/pages/index.js b/src/pages/index.js
index fd737190..6b6344e6 100644
--- a/src/pages/index.js
+++ b/src/pages/index.js
@@ -27,7 +27,7 @@ export default function Home({ heroBanners }) {
const [manufactures, setManufactures] = useState(null);
const [popularProducts, setPopularProducts] = useState(null);
const [categoryProductIds, setCategoryProductIds] = useState(null);
- const [categoryProducts, setCategoryProducts] = useState(null);
+ const [categoryProducts, setCategoryProducts] = useState([]);
useEffect(() => {
const getManufactures = async () => {
@@ -51,19 +51,25 @@ export default function Home({ heroBanners }) {
}
}
getCategoryProductIds();
+ }, [ categoryProductIds ]);
+ useEffect(() => {
const getCategoryProducts = async () => {
- if (categoryProductIds) {
- let collectionCategoryProducts = [];
- for (const id in categoryProductIds) {
- const dataCategoryProducts = await apiOdoo('GET', `/api/v1/categories_homepage?id=${id}`);
- collectionCategoryProducts.push(...dataCategoryProducts);
- setCategoryProducts(collectionCategoryProducts);
+ const currentCategoryId = categoryProductIds ? categoryProductIds[categoryProducts.length] : false;
+ if (currentCategoryId) {
+ const isAdded = categoryProducts.findIndex((categoryProduct) => categoryProduct.id == currentCategoryId);
+ console.log(isAdded);
+ if (isAdded < 0) {
+ const dataCategoryProducts = await apiOdoo('GET', `/api/v1/categories_homepage?id=${currentCategoryId}`);
+ setCategoryProducts((categoryProducts) => ([
+ ...categoryProducts,
+ ...dataCategoryProducts
+ ]));
}
}
}
getCategoryProducts();
- }, [ categoryProductIds ]);
+ }, [ categoryProducts, categoryProductIds ]);
return (
<>