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


From 0d3c0cf6a00ef81bfdb944490e48f16af41fc029 Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Wed, 13 Nov 2024 10:08:16 +0700
Subject: <iman> add radis

---
 src/lib/home/components/CategoryDynamicMobile.jsx | 23 -----------------------
 1 file changed, 23 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 6ede1147..67ae6f5f 100644
--- a/src/lib/home/components/CategoryDynamicMobile.jsx
+++ b/src/lib/home/components/CategoryDynamicMobile.jsx
@@ -9,29 +9,6 @@ import {
   fetchCategoryManagementVersion,
 } from '../api/categoryManagementApi';
 
-const saveToLocalStorage = (key, data, version) => {
-  const now = new Date();
-  const item = {
-    value: data,
-    version: version,
-    lastFetchedTime: now.getTime(),
-  };
-  localStorage.setItem(key, JSON.stringify(item));
-};
-
-const getFromLocalStorage = (key) => {
-  const itemStr = localStorage.getItem(key);
-  if (!itemStr) return null;
-
-  const item = JSON.parse(itemStr);
-  return item;
-};
-
-const getElapsedTime = (lastFetchedTime) => {
-  const now = new Date();
-  return now.getTime() - lastFetchedTime;
-};
-
 const CategoryDynamicMobile = () => {
   const [selectedCategory, setSelectedCategory] = useState({});
   const [categoryManagement, setCategoryManagement] = useState([]);
-- 
cgit v1.2.3

