From 37bda78dec58cb8c218849a77620d95682b201b9 Mon Sep 17 00:00:00 2001 From: Miqdad Date: Tue, 26 Aug 2025 15:38:29 +0700 Subject: Major Fix --- src/lib/category/components/Breadcrumb.jsx | 180 +++++++---------------------- 1 file changed, 44 insertions(+), 136 deletions(-) (limited to 'src/lib/category') diff --git a/src/lib/category/components/Breadcrumb.jsx b/src/lib/category/components/Breadcrumb.jsx index b369d781..e691e379 100644 --- a/src/lib/category/components/Breadcrumb.jsx +++ b/src/lib/category/components/Breadcrumb.jsx @@ -9,106 +9,57 @@ import { import Link from 'next/link'; import React from 'react'; import { useQuery } from 'react-query'; -import useDevice from '@/core/hooks/useDevice'; const Breadcrumb = ({ categoryId }) => { - const { isDesktop, isMobile } = useDevice(); - const breadcrumbs = useQuery( ['category-breadcrumbs', categoryId], async () => await odooApi('GET', `/api/v1/category/${categoryId}/category-breadcrumb`) ); - const cats = breadcrumbs.data ?? []; - const total = cats.length; - - const showEllipsis = total > 2; - const parent = total >= 2 ? cats[total - 2] : null; - const last = total ? cats[total - 1] : null; - const hiddenText = showEllipsis - ? cats - .slice(0, total - 2) - .map((c) => c.name) - .join(' / ') - : ''; - - // ===== MOBILE: 2 BARIS -> (1) Home/..//Parent (2) Last (wrap) ===== - if (isMobile) { - return ( -
- - {/* Baris 1 */} - - - - Home - - - - {showEllipsis && ( - - - .. - - - )} - - {parent && ( - - - {parent.name} - - - )} - - - {/* Baris 2 */} - {last && ( - - - - {last.name} - - - - )} - -
- ); - } + const items = breadcrumbs.data ?? []; + const lastIdx = items.length - 1; - // ===== DESKTOP: biarkan seperti semula ===== - if (isDesktop) { - return ( -
- - - - - Home - - + return ( +
+ + + {/* Home */} + + + Home + + - {cats.map((category, index) => ( - - {index === cats.length - 1 ? ( - + {/* Categories */} + {items.map((category, index) => { + const isLast = index === lastIdx; + return ( + + {isLast ? ( + // HANYA yang terakhir boleh turun/wrap di mobile + {category.name} ) : ( @@ -119,57 +70,14 @@ const Breadcrumb = ({ categoryId }) => { category.name, category.id )} - className='!text-danger-500 whitespace-nowrap' + className='!text-danger-500' > {category.name} )} - ))} - - -
- ); - } - - // Fallback → layout desktop - return ( -
- - - - - Home - - - {cats.map((category, index) => ( - - {index === cats.length - 1 ? ( - - {category.name} - - ) : ( - - {category.name} - - )} - - ))} + ); + })}
-- cgit v1.2.3