From ba023d9022189343d83998af8586ea65ddf1cf28 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Wed, 1 Feb 2023 09:15:32 +0700 Subject: Fix get category homepage --- src/pages/index.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src/pages') diff --git a/src/pages/index.js b/src/pages/index.js index b233f81e..94be7f3a 100644 --- a/src/pages/index.js +++ b/src/pages/index.js @@ -42,11 +42,18 @@ export default function Home({ heroBanners }) { getPopularProducts(); const getCategoryProducts = async () => { - const dataCategoryProducts = await apiOdoo('GET', '/api/v1/categories_homepage'); - setCategoryProducts(dataCategoryProducts); + if (!categoryProducts) { + const categoryIds = await apiOdoo('GET', '/api/v1/categories_homepage/ids'); + const categories = []; + for (const id in categoryIds) { + const dataCategoryProducts = await apiOdoo('GET', `/api/v1/categories_homepage?id=${id}`); + categories.push(...dataCategoryProducts); + setCategoryProducts(categories); + } + } } getCategoryProducts(); - }, []); + }, [ categoryProducts ]); return ( <> -- cgit v1.2.3