From bcf7be5a0c1d9635383605afc0600386b0b356ea Mon Sep 17 00:00:00 2001 From: Miqdad Date: Tue, 26 Aug 2025 11:41:54 +0700 Subject: Push --- .../product-detail/components/Breadcrumb.tsx | 79 +++++++++++++++------- 1 file changed, 54 insertions(+), 25 deletions(-) (limited to 'src-migrate/modules/product-detail/components/Breadcrumb.tsx') diff --git a/src-migrate/modules/product-detail/components/Breadcrumb.tsx b/src-migrate/modules/product-detail/components/Breadcrumb.tsx index f41859a9..ba53aca4 100644 --- a/src-migrate/modules/product-detail/components/Breadcrumb.tsx +++ b/src-migrate/modules/product-detail/components/Breadcrumb.tsx @@ -1,41 +1,70 @@ -import React, { Fragment } from 'react' -import { useQuery } from 'react-query' -import { getProductCategoryBreadcrumb } from '~/services/product' -import Link from 'next/link' -import { createSlug } from '~/libs/slug' +import React, { Fragment } from 'react'; +import { useQuery } from 'react-query'; +import { getProductCategoryBreadcrumb } from '~/services/product'; +import Link from 'next/link'; +import { createSlug } from '~/libs/slug'; type Props = { - id: number, - name: string -} + id: number; + name: string; +}; + +const MAX_VISIBLE_CATEGORIES = 2; // tampilkan 2 level terakhir const Breadcrumb = ({ id, name }: Props) => { - const query = useQuery({ - queryKey: ['product-category-breadcrumb'], + const { data: breadcrumbs = [] } = useQuery({ + queryKey: ['product-category-breadcrumb', id], // penting: ikutkan id queryFn: () => getProductCategoryBreadcrumb(id), - refetchOnWindowFocus: false - }) + refetchOnWindowFocus: false, + }); - const breadcrumbs = query.data || [] + const total = breadcrumbs.length; + const showEllipsis = total > MAX_VISIBLE_CATEGORIES; + const visible = showEllipsis + ? breadcrumbs.slice(total - MAX_VISIBLE_CATEGORIES) + : breadcrumbs; + const hiddenText = showEllipsis + ? breadcrumbs + .slice(0, total - MAX_VISIBLE_CATEGORIES) + .map((c) => c.name) + .join(' / ') + : ''; return ( -
- Home - / - {breadcrumbs.map((category, index) => ( - +
+ + Home + + / + + {showEllipsis && ( + <> + + … + + / + + )} + + {visible.map((category, index) => ( + {category.name} - / + / ))} - {name} + + {name}
- ) -} + ); +}; -export default Breadcrumb \ No newline at end of file +export default Breadcrumb; -- cgit v1.2.3 From 2403eae1686c565364691022d294123a16f4f031 Mon Sep 17 00:00:00 2001 From: Miqdad Date: Tue, 26 Aug 2025 12:04:46 +0700 Subject: Fix Breadcrumb & image --- .../product-detail/components/Breadcrumb.tsx | 139 ++++++++++++++++----- 1 file changed, 106 insertions(+), 33 deletions(-) (limited to 'src-migrate/modules/product-detail/components/Breadcrumb.tsx') diff --git a/src-migrate/modules/product-detail/components/Breadcrumb.tsx b/src-migrate/modules/product-detail/components/Breadcrumb.tsx index ba53aca4..d495b77b 100644 --- a/src-migrate/modules/product-detail/components/Breadcrumb.tsx +++ b/src-migrate/modules/product-detail/components/Breadcrumb.tsx @@ -1,68 +1,141 @@ import React, { Fragment } from 'react'; import { useQuery } from 'react-query'; -import { getProductCategoryBreadcrumb } from '~/services/product'; import Link from 'next/link'; +import { getProductCategoryBreadcrumb } from '~/services/product'; import { createSlug } from '~/libs/slug'; +import useDevice from '@/core/hooks/useDevice'; -type Props = { - id: number; - name: string; -}; - -const MAX_VISIBLE_CATEGORIES = 2; // tampilkan 2 level terakhir +type Props = { id: number; name: string }; const Breadcrumb = ({ id, name }: Props) => { + const { isDesktop, isMobile } = useDevice(); + const { data: breadcrumbs = [] } = useQuery({ - queryKey: ['product-category-breadcrumb', id], // penting: ikutkan id + queryKey: ['product-category-breadcrumb', id], queryFn: () => getProductCategoryBreadcrumb(id), refetchOnWindowFocus: false, }); const total = breadcrumbs.length; - const showEllipsis = total > MAX_VISIBLE_CATEGORIES; - const visible = showEllipsis - ? breadcrumbs.slice(total - MAX_VISIBLE_CATEGORIES) - : breadcrumbs; - const hiddenText = showEllipsis + const lastCat = total ? breadcrumbs[total - 1] : null; + const hasHidden = total > 1; + const hiddenText = hasHidden ? breadcrumbs - .slice(0, total - MAX_VISIBLE_CATEGORIES) + .slice(0, total - 1) .map((c) => c.name) .join(' / ') : ''; - return ( -
- + // ===== MOBILE: Home + .. + lastCat + product (truncate) ===== + if (isMobile) { + const crumbsMobile: React.ReactNode[] = []; + + // Home + crumbsMobile.push( + Home - / + ); + + // Indicator kategori tersembunyi (tanpa slash bawaan) + if (hasHidden) { + crumbsMobile.push( + + .. + + ); + } - {showEllipsis && ( - <> - - … - - / - - )} + // Kategori terakhir + if (lastCat) { + crumbsMobile.push( + + {lastCat.name} + + ); + } - {visible.map((category, index) => ( - + // Nama produk (dipotong bila tidak muat) + crumbsMobile.push( + + {name} + + ); + + return ( +
+ {crumbsMobile.map((node, i) => ( + + {node} + {i < crumbsMobile.length - 1 && ( + / + )} + + ))} +
+ ); + } + + // ===== DESKTOP: biarkan seperti semula ===== + if (isDesktop) { + return ( +
+ + Home + + / + {breadcrumbs.map((category, index) => ( + + + {category.name} + + / + + ))} + {name} +
+ ); + } + + // Fallback → layout desktop + return ( +
+ + Home + + / + {breadcrumbs.map((category, index) => ( + {category.name} - / + / ))} - - {name} + {name}
); }; -- cgit v1.2.3 From 8290efa6a098cdef393c255b8384de9c60803f04 Mon Sep 17 00:00:00 2001 From: Miqdad Date: Tue, 26 Aug 2025 12:29:24 +0700 Subject: Detail product done --- src-migrate/modules/product-detail/components/Breadcrumb.tsx | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'src-migrate/modules/product-detail/components/Breadcrumb.tsx') diff --git a/src-migrate/modules/product-detail/components/Breadcrumb.tsx b/src-migrate/modules/product-detail/components/Breadcrumb.tsx index d495b77b..0e263fe9 100644 --- a/src-migrate/modules/product-detail/components/Breadcrumb.tsx +++ b/src-migrate/modules/product-detail/components/Breadcrumb.tsx @@ -26,18 +26,15 @@ const Breadcrumb = ({ id, name }: Props) => { .join(' / ') : ''; - // ===== MOBILE: Home + .. + lastCat + product (truncate) ===== if (isMobile) { const crumbsMobile: React.ReactNode[] = []; - // Home crumbsMobile.push( Home ); - // Indicator kategori tersembunyi (tanpa slash bawaan) if (hasHidden) { crumbsMobile.push( { ); } - // Nama produk (dipotong bila tidak muat) + // Nama produk (dipotong kalau gk muat) crumbsMobile.push( {name} @@ -85,7 +82,7 @@ const Breadcrumb = ({ id, name }: Props) => { ); } - // ===== DESKTOP: biarkan seperti semula ===== + // ===== DESKTOP ===== if (isDesktop) { return (
@@ -113,7 +110,6 @@ const Breadcrumb = ({ id, name }: Props) => { ); } - // Fallback → layout desktop return (
-- cgit v1.2.3