summaryrefslogtreecommitdiff
path: root/src/lib/home/components/CategoryDynamicMobile.jsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/home/components/CategoryDynamicMobile.jsx')
-rw-r--r--src/lib/home/components/CategoryDynamicMobile.jsx56
1 files changed, 25 insertions, 31 deletions
diff --git a/src/lib/home/components/CategoryDynamicMobile.jsx b/src/lib/home/components/CategoryDynamicMobile.jsx
index 4a8f13cf..67ae6f5f 100644
--- a/src/lib/home/components/CategoryDynamicMobile.jsx
+++ b/src/lib/home/components/CategoryDynamicMobile.jsx
@@ -4,52 +4,46 @@ import Link from 'next/link';
import { createSlug } from '@/core/utils/slug';
import { Swiper, SwiperSlide } from 'swiper/react';
import 'swiper/css';
-import { fetchCategoryManagementSolr } from '../api/categoryManagementApi';
+import {
+ fetchCategoryManagementSolr,
+ fetchCategoryManagementVersion,
+} from '../api/categoryManagementApi';
const CategoryDynamicMobile = () => {
const [selectedCategory, setSelectedCategory] = useState({});
const [categoryManagement, setCategoryManagement] = useState([]);
const [isLoading, setIsLoading] = useState(false);
- const loadBrand = useCallback(async () => {
- setIsLoading(true);
- const items = await fetchCategoryManagementSolr();
+ useEffect(() => {
+ const fetchCategoryData = async () => {
+ setIsLoading(true);
+ const res = await fetch('/api/category-management');
+ const { data } = await res.json();
+ if (data) {
+ setCategoryManagement(data);
+ }
+ setIsLoading(false);
+ };
- setIsLoading(false);
- setCategoryManagement(items);
+ fetchCategoryData();
}, []);
useEffect(() => {
- loadBrand();
- }, [loadBrand]);
-
- useEffect(() => {
- const loadPromo = async () => {
- try {
- if (categoryManagement?.length > 0) {
- const initialSelections = categoryManagement.reduce(
- (acc, category) => {
- if (category.categories.length > 0) {
- acc[category.id] = category.categories[0].id_level_2;
- }
- return acc;
- },
- {}
- );
- setSelectedCategory(initialSelections);
+ if (categoryManagement?.length > 0) {
+ const initialSelections = categoryManagement.reduce((acc, category) => {
+ if (category.categories.length > 0) {
+ acc[category.id] = category.categories[0].id_level_2;
}
- } catch (loadError) {
- // console.error("Error loading promo items:", loadError);
- }
- };
-
- loadPromo();
+ return acc;
+ }, {});
+ setSelectedCategory(initialSelections);
+ }
}, [categoryManagement]);
- const handleCategoryLevel2Click = (categoryIdI, idLevel2) => {
+ const handleCategoryLevel2Click = (categoryId, idLevel2) => {
setSelectedCategory((prev) => ({
...prev,
- [categoryIdI]: idLevel2,
+ [categoryId]: idLevel2,
}));
};