Skip to content

Commit

Permalink
Update BlockHashLink for mobile
Browse files Browse the repository at this point in the history
  • Loading branch information
csillag committed Feb 23, 2024
1 parent b429827 commit 2c2b9aa
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions src/app/components/Blocks/BlockLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { RouteUtils } from '../../utils/route-utils'
import { TrimLinkLabel } from '../TrimLinkLabel'
import { SearchScope } from '../../../types/searchScope'
import { useScreenSize } from '../../hooks/useScreensize'
import { AdaptiveTrimmer } from '../AdaptiveTrimmer/AdaptiveTrimmer'

export const BlockLink: FC<{ scope: SearchScope; height: number }> = ({ scope, height }) => (
<Typography variant="mono">
Expand All @@ -23,15 +24,34 @@ export const BlockHashLink: FC<{
alwaysTrim?: boolean
}> = ({ scope, hash, height, alwaysTrim }) => {
const { isTablet } = useScreenSize()
return (
<Typography variant="mono">
{isTablet || alwaysTrim ? (
<TrimLinkLabel label={hash} to={RouteUtils.getBlockRoute(scope, height)} />
) : (
<Link component={RouterLink} to={RouteUtils.getBlockRoute(scope, height)}>
const to = RouteUtils.getBlockRoute(scope, height)

if (alwaysTrim) {
// Table view
return (
<Typography variant="mono">
<TrimLinkLabel label={hash} to={to} />
</Typography>
)
}

if (!isTablet) {
// Desktop view
return (
<Typography variant="mono">
<Link component={RouterLink} to={to}>
{hash}
</Link>
)}
</Typography>
)
}

// Mobile view
return (
<Typography variant="mono" sx={{ maxWidth: '100%', overflowX: 'hidden' }}>
<Link component={RouterLink} to={to}>
<AdaptiveTrimmer text={hash} strategy="middle" />
</Link>
</Typography>
)
}

0 comments on commit 2c2b9aa

Please sign in to comment.