From 51fb7cb3adeb99c428e716a17cc524b5dbbe3da7 Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Fri, 5 Jul 2024 17:00:48 +0700
Subject: <iman> fix bug sequence brands homepage

---
 src/lib/home/components/PreferredBrand.jsx | 38 ++++++++++++++++++++++++++----
 1 file changed, 33 insertions(+), 5 deletions(-)

(limited to 'src/lib/home/components/PreferredBrand.jsx')

diff --git a/src/lib/home/components/PreferredBrand.jsx b/src/lib/home/components/PreferredBrand.jsx
index 571c4745..ec09aa4e 100644
--- a/src/lib/home/components/PreferredBrand.jsx
+++ b/src/lib/home/components/PreferredBrand.jsx
@@ -1,13 +1,41 @@
 import { Swiper, SwiperSlide } from 'swiper/react'
+import { useCallback, useEffect, useState } from 'react'
 import usePreferredBrand from '../hooks/usePreferredBrand'
 import PreferredBrandSkeleton from './Skeleton/PreferredBrandSkeleton'
 import BrandCard from '@/lib/brand/components/BrandCard'
 import useDevice from '@/core/hooks/useDevice'
 import Link from '@/core/components/elements/Link/Link'
+import axios from 'axios'
 
 const PreferredBrand = () => {
   let query = 'level_s'
   let params = 'prioritas'
+  const [isLoading, setIsLoading] = useState(true)
+  const [startWith, setStartWith] = useState(null)
+  const [manufactures, setManufactures] = useState([])
+
+  const loadBrand = useCallback(async () => {
+    setIsLoading(true)
+    const name = startWith ? `${startWith}*` : ''
+    const result = await axios(`${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/brands?params=${name}`)
+    
+    setIsLoading(false)
+    setManufactures((manufactures) => [...result.data])
+  }, [startWith])
+
+  const toggleStartWith = (alphabet) => {
+    setManufactures([])
+    if (alphabet == startWith) {
+      setStartWith(null)
+      return
+    }
+    setStartWith(alphabet)
+  }
+
+  useEffect(() => {
+    loadBrand()
+  }, [loadBrand])
+
   const { preferredBrands } = usePreferredBrand(query)
   const { isMobile, isDesktop } = useDevice()
 
@@ -21,12 +49,12 @@ const PreferredBrand = () => {
           </Link>
         )}
       </div>
-      {preferredBrands.isLoading && <PreferredBrandSkeleton />}
-      {!preferredBrands.isLoading && (
+      {manufactures.isLoading && <PreferredBrandSkeleton />}
+      {!manufactures.isLoading && (
         <Swiper slidesPerView={isMobile ? 3.5 : 7.5} spaceBetween={isMobile ? 12 : 24} freeMode>
-          {preferredBrands.data?.data.map((brand) => (
-            <SwiperSlide key={brand.id}>
-              <BrandCard brand={brand} />
+          {manufactures.map((manufacture) => (
+            <SwiperSlide key={manufacture.id}>
+              <BrandCard brand={manufacture} />
             </SwiperSlide>
           ))}
         </Swiper>
-- 
cgit v1.2.3


From 937013e8bf9f176c18a31d94205b9116d2a02224 Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Tue, 16 Jul 2024 15:52:08 +0700
Subject: <iman> update button lihat semua mobile

---
 src/lib/home/components/PreferredBrand.jsx | 5 +++++
 1 file changed, 5 insertions(+)

(limited to 'src/lib/home/components/PreferredBrand.jsx')

diff --git a/src/lib/home/components/PreferredBrand.jsx b/src/lib/home/components/PreferredBrand.jsx
index 571c4745..ef5e743e 100644
--- a/src/lib/home/components/PreferredBrand.jsx
+++ b/src/lib/home/components/PreferredBrand.jsx
@@ -20,6 +20,11 @@ const PreferredBrand = () => {
             Lihat Semua
           </Link>
         )}
+        {isMobile && (
+          <Link href='/shop/brands' className='!text-red-500 font-semibold sm:text-h-sm'>
+            Lihat Semua
+          </Link>
+        )}
       </div>
       {preferredBrands.isLoading && <PreferredBrandSkeleton />}
       {!preferredBrands.isLoading && (
-- 
cgit v1.2.3

