From 0ecb7ba546cd1fdd3811f76aa09b20642ab4952c Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Mon, 11 Nov 2024 11:21:47 +0700
Subject: <iman> update redis category management mobile

---
 src/lib/home/components/CategoryDynamicMobile.jsx | 40 +++++------------------
 1 file changed, 9 insertions(+), 31 deletions(-)

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

diff --git a/src/lib/home/components/CategoryDynamicMobile.jsx b/src/lib/home/components/CategoryDynamicMobile.jsx
index 55654b0e..6ede1147 100644
--- a/src/lib/home/components/CategoryDynamicMobile.jsx
+++ b/src/lib/home/components/CategoryDynamicMobile.jsx
@@ -37,42 +37,20 @@ const CategoryDynamicMobile = () => {
   const [categoryManagement, setCategoryManagement] = useState([]);
   const [isLoading, setIsLoading] = useState(false);
 
-  const loadCategoryManagement = useCallback(async () => {
-    const cachedData = getFromLocalStorage('homepage_categoryDynamic');
-
-    if (cachedData) {
-      // Hitung selisih waktu antara saat ini dengan waktu terakhir data di-fetch
-      const elapsedTime = getElapsedTime(cachedData.lastFetchedTime);
-
-      if (elapsedTime < 24 * 60 * 60 * 1000) {
-        setCategoryManagement(cachedData.value);
-        return;
-      }
-    }
-
-    const latestVersion = await fetchCategoryManagementVersion();
-    if (cachedData && cachedData.version === latestVersion) {
-      // perbarui waktu
-      saveToLocalStorage(
-        'homepage_categoryDynamic',
-        cachedData.value,
-        latestVersion
-      );
-      setCategoryManagement(cachedData.value);
-    } else {
+  useEffect(() => {
+    const fetchCategoryData = async () => {
       setIsLoading(true);
-      const items = await fetchCategoryManagementSolr();
+      const res = await fetch('/api/category-management');
+      const { data } = await res.json();
+      if (data) {
+        setCategoryManagement(data);
+      }
       setIsLoading(false);
+    };
 
-      saveToLocalStorage('homepage_categoryDynamic', items, latestVersion);
-      setCategoryManagement(items);
-    }
+    fetchCategoryData();
   }, []);
 
-  useEffect(() => {
-    loadCategoryManagement();
-  }, [loadCategoryManagement]);
-
   useEffect(() => {
     if (categoryManagement?.length > 0) {
       const initialSelections = categoryManagement.reduce((acc, category) => {
-- 
cgit v1.2.3

