From 7a8d692db738f2f5f082bebeb2f6ad726c84801d Mon Sep 17 00:00:00 2001 From: titix Date: Thu, 8 Aug 2024 14:41:04 -0300 Subject: [PATCH] refactor: remove logic from html --- src/components/Breadcrumb.tsx | 60 +++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/src/components/Breadcrumb.tsx b/src/components/Breadcrumb.tsx index f917291..bf3f456 100644 --- a/src/components/Breadcrumb.tsx +++ b/src/components/Breadcrumb.tsx @@ -16,35 +16,43 @@ export const Breadcrumb = ({ isChain }: BreadcrumbProps) => { const { chainData } = useData(); const { theme } = useCustomTheme(); const { t } = useTranslation(); + const pathNames = pathname ? pathname.split('/').filter((path) => path) : []; + const breadcrumbItems = pathNames.map((path, index) => { + const isLast = index === pathNames.length - 1; + const displayName = isChain && isLast ? chainData?.metadata?.chainName || path : path; + const href = `/${pathNames.slice(0, index + 1).join('/')}`; + + return { + key: index, + isLast, + displayName, + href, + }; + }); + return ( {t('HOME.home')} - {pathNames.map((path, index) => { - const isLast = index === pathNames.length - 1; - const displayName = isChain ? chainData?.metadata?.chainName : path; - return ( - - - {isLast ? ( - {displayName} - ) : ( - {displayName} - )} - - ); - })} + {breadcrumbItems.map(({ key, isLast, displayName, href }) => ( + + + {isLast ? ( + {displayName} + ) : ( + {displayName} + )} + + ))} ); }; -const BreadcrumbNav = styled('nav')(() => { - return { - display: 'flex', - alignItems: 'center', - }; +const BreadcrumbNav = styled('nav')({ + display: 'flex', + alignItems: 'center', }); const BreadcrumbLink = styled(Link)(() => { @@ -59,17 +67,13 @@ const BreadcrumbLink = styled(Link)(() => { }; }); -const BreadcrumbItem = styled('span')(() => { - return { - display: 'flex', - alignItems: 'center', - }; +const BreadcrumbItem = styled('span')({ + display: 'flex', + alignItems: 'center', }); -const ArrowIcon = styled(Image)(() => { - return { - width: '1.25rem', - }; +const ArrowIcon = styled(Image)({ + width: '1.25rem', }); const BreadcrumbCurrent = styled(Typography)(() => {