From d26133d39e7d9cd510fdc72d239303f4ba918bdd Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Sat, 11 Mar 2023 13:37:29 +0700 Subject: create useDevice hooks, optimize DesktopView and MobileView, and show category API data --- src/lib/category/components/Category.jsx | 77 ++++++++++++++++++++++++-------- src/lib/home/components/HeroBanner.jsx | 67 ++++++++++++++------------- 2 files changed, 92 insertions(+), 52 deletions(-) (limited to 'src/lib') diff --git a/src/lib/category/components/Category.jsx b/src/lib/category/components/Category.jsx index 21e2ec6f..5ba45cc7 100644 --- a/src/lib/category/components/Category.jsx +++ b/src/lib/category/components/Category.jsx @@ -1,28 +1,69 @@ +import odooApi from '@/core/api/odooApi' import Link from '@/core/components/elements/Link/Link' import DesktopView from '@/core/components/views/DesktopView' +import { useEffect, useState } from 'react' const Category = () => { + const [categories, setCategories] = useState([]) + + useEffect(() => { + const loadCategories = async () => { + let dataCategories = await odooApi('GET', '/api/v1/category/tree') + dataCategories = dataCategories.map((category) => { + category.childs = category.childs.map((child1Category) => { + return { + ...child1Category, + isOpen: false + } + }) + return { + ...category, + isOpen: false + } + }) + setCategories(dataCategories) + } + loadCategories() + }, []) + return ( -
-
- Alat Potong & Pelengkap Mesin -
-
Alat Potong & Pelengkap Mesin
-
-
-
- Alat Ukur & Instrument -
-
Alat Ukur & Instrument
-
-
-
- Komponen Mekanikal & Hardware -
-
Komponen Mekanikal & Hardware
+
+ {categories.map((category) => ( +
+ + {category.name} + +
+
+ {category.childs.map((child1Category) => ( +
+ + {child1Category.name} + +
+ {child1Category.childs.map((child2Category) => ( + + {child2Category.name} + + ))} +
+
+ ))} +
+
-
+ ))}
) diff --git a/src/lib/home/components/HeroBanner.jsx b/src/lib/home/components/HeroBanner.jsx index e6690c01..95f590fc 100644 --- a/src/lib/home/components/HeroBanner.jsx +++ b/src/lib/home/components/HeroBanner.jsx @@ -1,7 +1,6 @@ import ImageSkeleton from '@/core/components/elements/Skeleton/ImageSkeleton' import useHeroBanner from '../hooks/useHeroBanner' import Image from '@/core/components/elements/Image/Image' -import MobileView from '@/core/components/views/MobileView' // Swiper import { Swiper, SwiperSlide } from 'swiper/react' @@ -9,44 +8,44 @@ import { Pagination, Autoplay } from 'swiper' import 'swiper/css' import 'swiper/css/pagination' import 'swiper/css/autoplay' - -const swiperBanner = { - pagination: { dynamicBullets: true }, - autoplay: { - delay: 6000, - disableOnInteraction: false - }, - modules: [Pagination, Autoplay] -} +import useDevice from '@/core/hooks/useDevice' const HeroBanner = () => { + const { isMobile } = useDevice() const { heroBanners } = useHeroBanner() + const swiperBanner = { + pagination: { dynamicBullets: isMobile ? true : false, clickable: true }, + autoplay: { + delay: 6000, + disableOnInteraction: false + }, + modules: [Pagination, Autoplay] + } + return ( - -
- {heroBanners.isLoading && } - {!heroBanners.isLoading && ( - - {heroBanners.data?.map((banner, index) => ( - - {banner.name} - - ))} - - )} -
-
+
+ {heroBanners.isLoading && } + {!heroBanners.isLoading && ( + + {heroBanners.data?.map((banner, index) => ( + + {banner.name} + + ))} + + )} +
) } -- cgit v1.2.3