Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/adapt-with-new-asset-api' into k…
Browse files Browse the repository at this point in the history
…yberai-filter-sort
  • Loading branch information
nguyenhoaidanh committed Sep 22, 2023
2 parents 8fffeba + 993d8a6 commit 3c7494e
Showing 1 changed file with 35 additions and 19 deletions.
54 changes: 35 additions & 19 deletions src/pages/TrueSightV2/pages/SingleToken.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Trans, t } from '@lingui/macro'
import { rgba } from 'polished'
import { stringify } from 'querystring'
import { ReactNode, useEffect, useLayoutEffect, useRef, useState } from 'react'
import React, { ReactNode, useCallback, useEffect, useRef, useState } from 'react'
import { ChevronLeft } from 'react-feather'
import Skeleton, { SkeletonTheme } from 'react-loading-skeleton'
import { useLocation, useNavigate, useParams, useSearchParams } from 'react-router-dom'
Expand Down Expand Up @@ -159,7 +159,7 @@ export const defaultExplorePageToken = {
assetId: 1,
}

const StyledTokenDescription = styled.div<{ show?: boolean }>`
const StyledTokenDescription = styled.span<{ show?: boolean }>`
text-overflow: ellipsis;
overflow: hidden;
font-size: 12px;
Expand Down Expand Up @@ -187,11 +187,16 @@ const TokenDescription = ({ description }: { description: string }) => {
const theme = useTheme()
const [show, setShow] = useState(true)
const [isTextExceeded, setIsTextExceeded] = useState(false)
const ref = useRef<HTMLDivElement>(null)
console.log('🚀 ~ file: SingleToken.tsx:191 ~ TokenDescription ~ isTextExceeded:', isTextExceeded)

useLayoutEffect(() => {
setIsTextExceeded((!!description && ref.current && ref.current?.clientWidth <= ref.current?.scrollWidth) || false)
}, [description])
const ref = useCallback(
(el: HTMLDivElement) => {
if (el && !!description) {
setIsTextExceeded(el.clientHeight > 18 || el.scrollWidth > el.clientWidth || false)
}
},
[description],
)

useEffect(() => {
const hideBtn = document.getElementById('hide-token-description-span')
Expand All @@ -204,19 +209,30 @@ const TokenDescription = ({ description }: { description: string }) => {

return (
<Row style={{ position: 'relative' }}>
<StyledTokenDescription
ref={ref}
show={show}
dangerouslySetInnerHTML={{
__html:
linkify(description) +
(isTextExceeded
? `<span style="color:${
theme.primary
}; cursor:pointer; margin-left:4px;" id="hide-token-description-span">${t`Hide`}</span>`
: ''),
}}
/>
<StyledTokenDescription ref={ref} show={show}>
<span
dangerouslySetInnerHTML={{
__html: linkify(description),
}}
/>
{isTextExceeded && show && (
<Text
as="span"
fontSize="12px"
color={theme.primary}
width="fit-content"
style={{
padding: '0 6px',
cursor: 'pointer',
flexBasis: 'fit-content',
whiteSpace: 'nowrap',
}}
onClick={() => setShow(false)}
>
Hide
</Text>
)}
</StyledTokenDescription>
{isTextExceeded && !show && (
<Text
as="span"
Expand Down

0 comments on commit 3c7494e

Please sign in to comment.