summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2023-02-01 10:58:35 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2023-02-01 10:58:35 +0700
commit432ba9f520120e43b0c580627692576d3ef0486f (patch)
tree0a8a85d05b36e70f2697318161cca28be8caa71d /src
parent4d963560f9cddf66b76a7d286cdd00b579c0c32c (diff)
no message
Diffstat (limited to 'src')
-rw-r--r--src/pages/index.js24
1 files changed, 16 insertions, 8 deletions
diff --git a/src/pages/index.js b/src/pages/index.js
index 88824dd4..fd737190 100644
--- a/src/pages/index.js
+++ b/src/pages/index.js
@@ -26,6 +26,7 @@ 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(null);
useEffect(() => {
@@ -43,19 +44,26 @@ export default function Home({ heroBanners }) {
}, []);
useEffect(() => {
+ const getCategoryProductIds = async () => {
+ if (!categoryProductIds) {
+ const dataCategoryProductIds = await apiOdoo('GET', '/api/v1/categories_homepage/ids');
+ setCategoryProductIds(dataCategoryProductIds)
+ }
+ }
+ getCategoryProductIds();
+
const getCategoryProducts = async () => {
- if (!categoryProducts) {
- const categoryIds = await apiOdoo('GET', '/api/v1/categories_homepage/ids');
- const dataCategoryProducts = [];
- for (const id in categoryIds) {
- const dataApiCategoryProducts = await apiOdoo('GET', `/api/v1/categories_homepage?id=${id}`);
- dataCategoryProducts.push(...dataApiCategoryProducts);
- setCategoryProducts(dataCategoryProducts);
+ 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);
}
}
}
getCategoryProducts();
- }, [ categoryProducts ])
+ }, [ categoryProductIds ]);
return (
<>