Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
frontend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
frontend
Commits
bb9842bc
Commit
bb9842bc
authored
Feb 26, 2025
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
search results page
parent
e52386b8
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
161 additions
and
162 deletions
+161
-162
search-results.tsx
pages/search-results.tsx
+2
-2
SearchResults.tsx
ui/pages/SearchResults.tsx
+22
-22
SearchResultListItem.tsx
ui/searchResults/SearchResultListItem.tsx
+38
-40
SearchResultTableItem.tsx
ui/searchResults/SearchResultTableItem.tsx
+85
-86
SearchResultsInput.tsx
ui/searchResults/SearchResultsInput.tsx
+14
-12
No files found.
pages/search-results.tsx
View file @
bb9842bc
...
...
@@ -8,12 +8,12 @@ import PageNextJs from 'nextjs/PageNextJs';
import
LayoutSearchResults
from
'
ui/shared/layout/LayoutSearchResults
'
;
//
const SearchResults = dynamic(() => import('ui/pages/SearchResults'), { ssr: false });
const
SearchResults
=
dynamic
(()
=>
import
(
'
ui/pages/SearchResults
'
),
{
ssr
:
false
});
const
Page
:
NextPageWithLayout
<
Props
>
=
(
props
:
Props
)
=>
{
return
(
<
PageNextJs
pathname=
"/search-results"
query=
{
props
.
query
}
>
{
/* <SearchResults/> */
}
<
SearchResults
/>
</
PageNextJs
>
);
};
...
...
ui/pages/SearchResults.tsx
View file @
bb9842bc
import
{
Box
,
chakra
,
Table
,
Tbody
,
Tr
,
Th
,
Show
,
Hide
}
from
'
@chakra-ui/react
'
;
import
{
Box
,
chakra
}
from
'
@chakra-ui/react
'
;
import
{
useRouter
}
from
'
next/router
'
;
import
type
{
FormEvent
}
from
'
react
'
;
import
React
from
'
react
'
;
...
...
@@ -11,20 +11,20 @@ import { useSettingsContext } from 'lib/contexts/settings';
import
*
as
regexp
from
'
lib/regexp
'
;
import
getQueryParamString
from
'
lib/router/getQueryParamString
'
;
import
removeQueryParam
from
'
lib/router/removeQueryParam
'
;
import
{
Skeleton
}
from
'
toolkit/chakra/skeleton
'
;
import
{
TableBody
,
TableColumnHeader
,
TableHeaderSticky
,
TableRoot
,
TableRow
}
from
'
toolkit/chakra/table
'
;
import
useMarketplaceApps
from
'
ui/marketplace/useMarketplaceApps
'
;
import
SearchResultListItem
from
'
ui/searchResults/SearchResultListItem
'
;
import
SearchResultsInput
from
'
ui/searchResults/SearchResultsInput
'
;
import
SearchResultTableItem
from
'
ui/searchResults/SearchResultTableItem
'
;
import
ActionBar
,
{
ACTION_BAR_HEIGHT_DESKTOP
}
from
'
ui/shared/ActionBar
'
;
import
AppErrorBoundary
from
'
ui/shared/AppError/AppErrorBoundary
'
;
import
Skeleton
from
'
ui/shared/chakra/Skeleton
'
;
import
ContentLoader
from
'
ui/shared/ContentLoader
'
;
import
DataFetchAlert
from
'
ui/shared/DataFetchAlert
'
;
import
*
as
Layout
from
'
ui/shared/layout/components
'
;
import
PageTitle
from
'
ui/shared/Page/PageTitle
'
;
import
Pagination
from
'
ui/shared/pagination/Pagination
'
;
import
type
{
SearchResultAppItem
}
from
'
ui/shared/search/utils
'
;
import
Thead
from
'
ui/shared/TheadSticky
'
;
import
HeaderAlert
from
'
ui/snippets/header/HeaderAlert
'
;
import
HeaderDesktop
from
'
ui/snippets/header/HeaderDesktop
'
;
import
HeaderMobile
from
'
ui/snippets/header/HeaderMobile
'
;
...
...
@@ -144,7 +144,7 @@ const SearchResultsPageContent = () => {
return
(
<>
<
Show
below=
"lg"
ssr=
{
false
}
>
<
Box
hideFrom=
"lg"
>
{
displayedItems
.
map
((
item
,
index
)
=>
(
<
SearchResultListItem
key=
{
(
isLoading
?
'
placeholder_
'
:
'
actual_
'
)
+
index
}
...
...
@@ -154,18 +154,18 @@ const SearchResultsPageContent = () => {
addressFormat=
{
settingsContext
?.
addressFormat
}
/>
))
}
</
Show
>
<
Hide
below=
"lg"
ssr=
{
false
}
>
<
Table
fontWeight=
{
500
}
>
<
T
head
top=
{
pagination
.
isVisible
?
ACTION_BAR_HEIGHT_DESKTOP
:
0
}
>
<
T
r
>
<
T
h
width=
"30%"
>
Search result
</
Th
>
<
T
h
width=
"35%"
/>
<
T
h
width=
"35%"
pr=
{
10
}
/>
<
T
h
width=
"150px"
>
Category
</
Th
>
</
T
r
>
</
T
head
>
<
T
b
ody
>
</
Box
>
<
Box
hideBelow=
"lg"
>
<
Table
Root
fontWeight=
{
500
}
>
<
T
ableHeaderSticky
top=
{
pagination
.
isVisible
?
ACTION_BAR_HEIGHT_DESKTOP
:
0
}
>
<
T
ableRow
>
<
T
ableColumnHeader
width=
"30%"
>
Search result
</
TableColumnHeader
>
<
T
ableColumnHeader
width=
"35%"
/>
<
T
ableColumnHeader
width=
"35%"
pr=
{
10
}
/>
<
T
ableColumnHeader
width=
"150px"
>
Category
</
TableColumnHeader
>
</
T
ableRow
>
</
T
ableHeaderSticky
>
<
T
ableB
ody
>
{
displayedItems
.
map
((
item
,
index
)
=>
(
<
SearchResultTableItem
key=
{
(
isLoading
?
'
placeholder_
'
:
'
actual_
'
)
+
index
}
...
...
@@ -175,9 +175,9 @@ const SearchResultsPageContent = () => {
addressFormat=
{
settingsContext
?.
addressFormat
}
/>
))
}
</
T
b
ody
>
</
Table
>
</
Hide
>
</
T
ableB
ody
>
</
Table
Root
>
</
Box
>
</>
);
})();
...
...
@@ -190,7 +190,7 @@ const SearchResultsPageContent = () => {
const
resultsCount
=
pagination
.
page
===
1
&&
!
data
?.
next_page_params
?
displayedItems
.
length
:
'
50+
'
;
const
text
=
isLoading
&&
pagination
.
page
===
1
?
(
<
Skeleton
h=
{
6
}
w=
"280px"
borderRadius=
"full"
mb=
{
pagination
.
isVisible
?
0
:
6
}
/>
<
Skeleton
loading
h=
{
6
}
w=
"280px"
borderRadius=
"full"
mb=
{
pagination
.
isVisible
?
0
:
6
}
/>
)
:
(
(
<>
...
...
@@ -214,9 +214,9 @@ const SearchResultsPageContent = () => {
return
(
<>
<
Box
display=
{
{
base
:
'
block
'
,
lg
:
'
none
'
}
}
>
{
text
}
</
Box
>
<
Box
hideFrom=
"lg"
>
{
text
}
</
Box
>
<
ActionBar
mt=
{
{
base
:
0
,
lg
:
-
6
}
}
alignItems=
"center"
>
<
Box
display=
{
{
base
:
'
none
'
,
lg
:
'
block
'
}
}
>
{
text
}
</
Box
>
<
Box
hideBelow=
"lg"
>
{
text
}
</
Box
>
<
Pagination
{
...
pagination
}
/>
</
ActionBar
>
</>
...
...
ui/searchResults/SearchResultListItem.tsx
View file @
bb9842bc
import
{
chakra
,
Flex
,
Grid
,
Image
,
Box
,
Text
,
useColorMode
,
Tag
}
from
'
@chakra-ui/react
'
;
import
{
chakra
,
Flex
,
Grid
,
Box
,
Text
}
from
'
@chakra-ui/react
'
;
import
React
from
'
react
'
;
import
xss
from
'
xss
'
;
...
...
@@ -12,7 +12,11 @@ import dayjs from 'lib/date/dayjs';
import
highlightText
from
'
lib/highlightText
'
;
import
*
as
mixpanel
from
'
lib/mixpanel/index
'
;
import
{
saveToRecentKeywords
}
from
'
lib/recentSearchKeywords
'
;
import
Skeleton
from
'
ui/shared/chakra/Skeleton
'
;
import
{
useColorMode
}
from
'
toolkit/chakra/color-mode
'
;
import
{
Image
}
from
'
toolkit/chakra/image
'
;
import
{
Link
}
from
'
toolkit/chakra/link
'
;
import
{
Skeleton
}
from
'
toolkit/chakra/skeleton
'
;
import
{
Tag
}
from
'
toolkit/chakra/tag
'
;
import
ContractCertifiedLabel
from
'
ui/shared/ContractCertifiedLabel
'
;
import
*
as
AddressEntity
from
'
ui/shared/entities/address/AddressEntity
'
;
import
*
as
BlobEntity
from
'
ui/shared/entities/blob/BlobEntity
'
;
...
...
@@ -25,7 +29,6 @@ import EntityTagIcon from 'ui/shared/EntityTags/EntityTagIcon';
import
{
ADDRESS_REGEXP
}
from
'
ui/shared/forms/validators/address
'
;
import
HashStringShortenDynamic
from
'
ui/shared/HashStringShortenDynamic
'
;
import
IconSvg
from
'
ui/shared/IconSvg
'
;
import
LinkInternal
from
'
ui/shared/links/LinkInternal
'
;
import
ListItemMobile
from
'
ui/shared/ListItemMobile/ListItemMobile
'
;
import
type
{
SearchResultAppItem
}
from
'
ui/shared/search/utils
'
;
import
{
getItemCategory
,
searchItemTitles
}
from
'
ui/shared/search/utils
'
;
...
...
@@ -58,22 +61,22 @@ const SearchResultListItem = ({ data, searchTerm, isLoading, addressFormat }: Pr
return
(
<
Flex
alignItems=
"center"
overflow=
"hidden"
>
<
TokenEntity
.
Icon
token=
{
{
...
data
,
type
:
data
.
token_type
}
}
isLoading=
{
isLoading
}
/>
<
Link
Internal
<
Link
href=
{
route
({
pathname
:
'
/token/[hash]
'
,
query
:
{
hash
:
data
.
address
}
})
}
fontWeight=
{
700
}
wordBreak=
"break-all"
isL
oading=
{
isLoading
}
l
oading=
{
isLoading
}
onClick=
{
handleLinkClick
}
overflow=
"hidden"
>
<
Skeleton
isLoaded=
{
!
isLoading
}
loading=
{
isLoading
}
dangerouslySetInnerHTML=
{
{
__html
:
highlightText
(
name
,
searchTerm
)
}
}
whiteSpace=
"nowrap"
overflow=
"hidden"
textOverflow=
"ellipsis"
/>
</
Link
Internal
>
</
Link
>
{
data
.
certified
&&
<
ContractCertifiedLabel
iconSize=
{
4
}
boxSize=
{
4
}
ml=
{
1
}
/>
}
{
data
.
is_verified_via_admin_panel
&&
!
data
.
certified
&&
<
IconSvg
name=
"certified"
boxSize=
{
4
}
ml=
{
1
}
color=
"green.500"
/>
}
</
Flex
>
...
...
@@ -108,8 +111,7 @@ const SearchResultListItem = ({ data, searchTerm, isLoading, addressFormat }: Pr
<
AddressEntity
.
Content
asProp=
{
shouldHighlightHash
?
'
mark
'
:
'
span
'
}
address=
{
{
...
address
,
hash
}
}
fontSize=
"sm"
lineHeight=
{
5
}
textStyle=
"sm"
fontWeight=
{
700
}
/>
</
AddressEntity
.
Link
>
...
...
@@ -122,15 +124,15 @@ const SearchResultListItem = ({ data, searchTerm, isLoading, addressFormat }: Pr
return
(
<
Flex
alignItems=
"center"
>
<
IconSvg
name=
"publictags_slim"
boxSize=
{
6
}
mr=
{
2
}
color=
"gray.500"
/>
<
Link
Internal
<
Link
href=
{
route
({
pathname
:
'
/address/[hash]
'
,
query
:
{
hash
:
data
.
address
}
})
}
fontWeight=
{
700
}
wordBreak=
"break-all"
isL
oading=
{
isLoading
}
l
oading=
{
isLoading
}
onClick=
{
handleLinkClick
}
>
<
span
dangerouslySetInnerHTML=
{
{
__html
:
highlightText
(
data
.
name
,
searchTerm
)
}
}
/>
</
Link
Internal
>
</
Link
>
</
Flex
>
);
}
...
...
@@ -146,18 +148,18 @@ const SearchResultListItem = ({ data, searchTerm, isLoading, addressFormat }: Pr
src=
{
colorMode
===
'
dark
'
&&
data
.
app
.
logoDarkMode
?
data
.
app
.
logoDarkMode
:
data
.
app
.
logo
}
alt=
{
`${ data.app.title } app icon`
}
/>
<
Link
Internal
<
Link
href=
{
data
.
app
.
external
?
route
({
pathname
:
'
/apps
'
,
query
:
{
selectedAppId
:
data
.
app
.
id
}
})
:
route
({
pathname
:
'
/apps/[id]
'
,
query
:
{
id
:
data
.
app
.
id
}
})
}
fontWeight=
{
700
}
wordBreak=
"break-all"
isL
oading=
{
isLoading
}
l
oading=
{
isLoading
}
onClick=
{
handleLinkClick
}
>
{
title
}
</
Link
Internal
>
</
Link
>
</
Flex
>
);
}
...
...
@@ -203,8 +205,7 @@ const SearchResultListItem = ({ data, searchTerm, isLoading, addressFormat }: Pr
<
TxEntity
.
Content
asProp=
"mark"
hash=
{
data
.
transaction_hash
}
fontSize=
"sm"
lineHeight=
{
5
}
textStyle=
"sm"
fontWeight=
{
700
}
/>
</
TxEntity
.
Link
>
...
...
@@ -224,8 +225,7 @@ const SearchResultListItem = ({ data, searchTerm, isLoading, addressFormat }: Pr
<
BlobEntity
.
Content
asProp=
"mark"
hash=
{
data
.
blob_hash
}
fontSize=
"sm"
lineHeight=
{
5
}
textStyle=
"sm"
fontWeight=
{
700
}
/>
</
BlobEntity
.
Link
>
...
...
@@ -245,8 +245,7 @@ const SearchResultListItem = ({ data, searchTerm, isLoading, addressFormat }: Pr
<
UserOpEntity
.
Content
asProp=
"mark"
hash=
{
data
.
user_operation_hash
}
fontSize=
"sm"
lineHeight=
{
5
}
textStyle=
"sm"
fontWeight=
{
700
}
/>
</
UserOpEntity
.
Link
>
...
...
@@ -258,22 +257,21 @@ const SearchResultListItem = ({ data, searchTerm, isLoading, addressFormat }: Pr
return
(
<
EnsEntity
.
Container
>
<
EnsEntity
.
Icon
protocol=
{
data
.
ens_info
.
protocol
}
/>
<
Link
Internal
<
Link
href=
{
route
({
pathname
:
'
/address/[hash]
'
,
query
:
{
hash
:
data
.
address
}
})
}
fontWeight=
{
700
}
wordBreak=
"break-all"
isL
oading=
{
isLoading
}
l
oading=
{
isLoading
}
onClick=
{
handleLinkClick
}
overflow=
"hidden"
>
<
Skeleton
isLoaded=
{
!
isLoading
}
<
Box
dangerouslySetInnerHTML=
{
{
__html
:
highlightText
(
data
.
ens_info
.
name
,
searchTerm
)
}
}
whiteSpace=
"nowrap"
overflow=
"hidden"
textOverflow=
"ellipsis"
/>
</
Link
Internal
>
</
Link
>
</
EnsEntity
.
Container
>
);
}
...
...
@@ -289,13 +287,13 @@ const SearchResultListItem = ({ data, searchTerm, isLoading, addressFormat }: Pr
return
(
<
Grid
templateColumns=
{
templateCols
}
alignItems=
"center"
gap=
{
2
}
>
<
Skeleton
isLoaded=
{
!
isLoading
}
overflow=
"hidden"
display=
"flex"
alignItems=
"center"
>
<
Skeleton
loading=
{
isLoading
}
overflow=
"hidden"
display=
"flex"
alignItems=
"center"
>
<
Text
whiteSpace=
"nowrap"
overflow=
"hidden"
>
<
HashStringShortenDynamic
hash=
{
hash
}
isTooltipDisabled
/>
</
Text
>
{
data
.
is_smart_contract_verified
&&
<
IconSvg
name=
"status/success"
boxSize=
"14px"
color=
"green.500"
ml=
{
1
}
flexShrink=
{
0
}
/>
}
</
Skeleton
>
<
Skeleton
isLoaded=
{
!
isLoading
}
overflow=
"hidden"
whiteSpace=
"nowrap"
textOverflow=
"ellipsis"
fontWeight=
{
700
}
>
<
Skeleton
loading=
{
isLoading
}
overflow=
"hidden"
whiteSpace=
"nowrap"
textOverflow=
"ellipsis"
fontWeight=
{
700
}
>
{
data
.
token_type
===
'
ERC-20
'
&&
data
.
exchange_rate
&&
`$${ Number(data.exchange_rate).toLocaleString() }`
}
{
data
.
token_type
!==
'
ERC-20
'
&&
data
.
total_supply
&&
`Items ${ Number(data.total_supply).toLocaleString() }`
}
</
Skeleton
>
...
...
@@ -307,15 +305,15 @@ const SearchResultListItem = ({ data, searchTerm, isLoading, addressFormat }: Pr
const
isFutureBlock
=
data
.
timestamp
===
undefined
;
if
(
isFutureBlock
)
{
return
<
Skeleton
isLoaded=
{
!
isLoading
}
>
Learn estimated time for this block to be created.
</
Skeleton
>;
return
<
Skeleton
loading=
{
isLoading
}
>
Learn estimated time for this block to be created.
</
Skeleton
>;
}
return
(
<>
<
Skeleton
isLoaded=
{
!
isLoading
}
as=
{
shouldHighlightHash
?
'
mark
'
:
'
span
'
}
display=
"block"
whiteSpace=
"nowrap"
overflow=
"hidden"
mb=
{
1
}
>
<
Skeleton
loading=
{
isLoading
}
as=
{
shouldHighlightHash
?
'
mark
'
:
'
span
'
}
display=
"block"
whiteSpace=
"nowrap"
overflow=
"hidden"
mb=
{
1
}
>
<
HashStringShortenDynamic
hash=
{
data
.
block_hash
}
/>
</
Skeleton
>
<
Skeleton
isLoaded=
{
!
isLoading
}
color=
"text_
secondary"
mr=
{
2
}
>
<
Skeleton
loading=
{
isLoading
}
color=
"text.
secondary"
mr=
{
2
}
>
<
span
>
{
dayjs
(
data
.
timestamp
).
format
(
'
llll
'
)
}
</
span
>
</
Skeleton
>
</>
...
...
@@ -323,13 +321,13 @@ const SearchResultListItem = ({ data, searchTerm, isLoading, addressFormat }: Pr
}
case
'
transaction
'
:
{
return
(
<
Text
variant=
"
secondary"
>
{
dayjs
(
data
.
timestamp
).
format
(
'
llll
'
)
}
</
Text
>
<
Text
color=
"text.
secondary"
>
{
dayjs
(
data
.
timestamp
).
format
(
'
llll
'
)
}
</
Text
>
);
}
case
'
user_operation
'
:
{
return
(
<
Text
variant=
"
secondary"
>
{
dayjs
(
data
.
timestamp
).
format
(
'
llll
'
)
}
</
Text
>
<
Text
color=
"text.
secondary"
>
{
dayjs
(
data
.
timestamp
).
format
(
'
llll
'
)
}
</
Text
>
);
}
case
'
label
'
:
{
...
...
@@ -370,8 +368,8 @@ const SearchResultListItem = ({ data, searchTerm, isLoading, addressFormat }: Pr
<
span
dangerouslySetInnerHTML=
{
{
__html
:
shouldHighlightHash
?
xss
(
addressName
)
:
highlightText
(
addressName
,
searchTerm
)
}
}
/>
{
data
.
ens_info
&&
(
data
.
ens_info
.
names_count
>
1
?
<
chakra
.
span
color=
"text
_
secondary"
>
(
{
data
.
ens_info
.
names_count
>
39
?
'
40+
'
:
`+${ data.ens_info.names_count - 1 }`
}
)
</
chakra
.
span
>
:
<
chakra
.
span
color=
"text
_
secondary"
>
{
expiresText
}
</
chakra
.
span
>
<
chakra
.
span
color=
"text
.
secondary"
>
(
{
data
.
ens_info
.
names_count
>
39
?
'
40+
'
:
`+${ data.ens_info.names_count - 1 }`
}
)
</
chakra
.
span
>
:
<
chakra
.
span
color=
"text
.
secondary"
>
{
expiresText
}
</
chakra
.
span
>
)
}
</
Text
>
{
data
.
certified
&&
<
ContractCertifiedLabel
iconSize=
{
4
}
boxSize=
{
4
}
ml=
{
1
}
/>
}
...
...
@@ -399,8 +397,8 @@ const SearchResultListItem = ({ data, searchTerm, isLoading, addressFormat }: Pr
</
Box
>
{
data
.
ens_info
.
names_count
>
1
?
<
chakra
.
span
color=
"text
_
secondary"
>
(
{
data
.
ens_info
.
names_count
>
39
?
'
40+
'
:
`+${ data.ens_info.names_count - 1 }`
}
)
</
chakra
.
span
>
:
<
chakra
.
span
color=
"text
_
secondary"
>
{
expiresText
}
</
chakra
.
span
>
<
chakra
.
span
color=
"text
.
secondary"
>
(
{
data
.
ens_info
.
names_count
>
39
?
'
40+
'
:
`+${ data.ens_info.names_count - 1 }`
}
)
</
chakra
.
span
>
:
<
chakra
.
span
color=
"text
.
secondary"
>
{
expiresText
}
</
chakra
.
span
>
}
</
Flex
>
);
...
...
@@ -414,10 +412,10 @@ const SearchResultListItem = ({ data, searchTerm, isLoading, addressFormat }: Pr
const
category
=
getItemCategory
(
data
);
return
(
<
ListItemMobile
py=
{
3
}
fontSiz
e=
"sm"
rowGap=
{
2
}
>
<
Grid
templateColumns=
"1fr auto"
w=
"100%"
overflow=
"hidden"
lineHeight=
{
6
}
>
<
ListItemMobile
py=
{
3
}
textStyl
e=
"sm"
rowGap=
{
2
}
>
<
Grid
templateColumns=
"1fr auto"
w=
"100%"
overflow=
"hidden"
>
{
firstRow
}
<
Skeleton
isLoaded=
{
!
isLoading
}
color=
"text_
secondary"
ml=
{
8
}
textTransform=
"capitalize"
>
<
Skeleton
loading=
{
isLoading
}
color=
"text.
secondary"
ml=
{
8
}
textTransform=
"capitalize"
>
<
span
>
{
category
?
searchItemTitles
[
category
].
itemTitleShort
:
''
}
</
span
>
</
Skeleton
>
</
Grid
>
...
...
ui/searchResults/SearchResultTableItem.tsx
View file @
bb9842bc
import
{
chakra
,
T
r
,
Td
,
Text
,
Flex
,
Image
,
Box
,
useColorMode
,
Tag
}
from
'
@chakra-ui/react
'
;
import
{
chakra
,
T
ext
,
Flex
,
Box
}
from
'
@chakra-ui/react
'
;
import
React
from
'
react
'
;
import
xss
from
'
xss
'
;
...
...
@@ -12,7 +12,12 @@ import dayjs from 'lib/date/dayjs';
import
highlightText
from
'
lib/highlightText
'
;
import
*
as
mixpanel
from
'
lib/mixpanel/index
'
;
import
{
saveToRecentKeywords
}
from
'
lib/recentSearchKeywords
'
;
import
Skeleton
from
'
ui/shared/chakra/Skeleton
'
;
import
{
useColorMode
}
from
'
toolkit/chakra/color-mode
'
;
import
{
Image
}
from
'
toolkit/chakra/image
'
;
import
{
Link
}
from
'
toolkit/chakra/link
'
;
import
{
Skeleton
}
from
'
toolkit/chakra/skeleton
'
;
import
{
TableCell
,
TableRow
}
from
'
toolkit/chakra/table
'
;
import
{
Tag
}
from
'
toolkit/chakra/tag
'
;
import
ContractCertifiedLabel
from
'
ui/shared/ContractCertifiedLabel
'
;
import
*
as
AddressEntity
from
'
ui/shared/entities/address/AddressEntity
'
;
import
*
as
BlobEntity
from
'
ui/shared/entities/blob/BlobEntity
'
;
...
...
@@ -25,7 +30,6 @@ import EntityTagIcon from 'ui/shared/EntityTags/EntityTagIcon';
import
{
ADDRESS_REGEXP
}
from
'
ui/shared/forms/validators/address
'
;
import
HashStringShortenDynamic
from
'
ui/shared/HashStringShortenDynamic
'
;
import
IconSvg
from
'
ui/shared/IconSvg
'
;
import
LinkInternal
from
'
ui/shared/links/LinkInternal
'
;
import
type
{
SearchResultAppItem
}
from
'
ui/shared/search/utils
'
;
import
{
getItemCategory
,
searchItemTitles
}
from
'
ui/shared/search/utils
'
;
...
...
@@ -57,45 +61,45 @@ const SearchResultTableItem = ({ data, searchTerm, isLoading, addressFormat }: P
return
(
<>
<
T
d
fontSize=
"sm"
>
<
T
ableCell
>
<
Flex
alignItems=
"center"
>
<
TokenEntity
.
Icon
token=
{
{
...
data
,
type
:
data
.
token_type
}
}
isLoading=
{
isLoading
}
/>
<
Link
Internal
<
Link
href=
{
route
({
pathname
:
'
/token/[hash]
'
,
query
:
{
hash
:
data
.
address
}
})
}
fontWeight=
{
700
}
wordBreak=
"break-all"
overflow=
"hidden"
isL
oading=
{
isLoading
}
l
oading=
{
isLoading
}
onClick=
{
handleLinkClick
}
>
<
Skeleton
isLoaded=
{
!
isLoading
}
loading=
{
isLoading
}
overflow=
"hidden"
textOverflow=
"ellipsis"
whiteSpace=
"nowrap"
dangerouslySetInnerHTML=
{
{
__html
:
highlightText
(
name
,
searchTerm
)
}
}
/>
</
Link
Internal
>
</
Link
>
{
data
.
certified
&&
<
ContractCertifiedLabel
iconSize=
{
4
}
boxSize=
{
4
}
ml=
{
1
}
/>
}
{
data
.
is_verified_via_admin_panel
&&
!
data
.
certified
&&
<
IconSvg
name=
"certified"
boxSize=
{
4
}
ml=
{
1
}
color=
"green.500"
/>
}
</
Flex
>
</
T
d
>
<
T
d
fontSize=
"sm"
verticalAlign=
"middle"
>
<
Skeleton
isLoaded=
{
!
isLoading
}
whiteSpace=
"nowrap"
overflow=
"hidden"
display=
"flex"
alignItems=
"center"
>
</
T
ableCell
>
<
T
ableCell
verticalAlign=
"middle"
>
<
Skeleton
loading=
{
isLoading
}
whiteSpace=
"nowrap"
overflow=
"hidden"
display=
"flex"
alignItems=
"center"
>
<
Box
overflow=
"hidden"
whiteSpace=
"nowrap"
w=
{
data
.
is_smart_contract_verified
?
'
calc(100%-28px)
'
:
'
unset
'
}
>
<
HashStringShortenDynamic
hash=
{
hash
}
/>
</
Box
>
{
data
.
is_smart_contract_verified
&&
<
IconSvg
name=
"status/success"
boxSize=
"14px"
color=
"green.500"
ml=
{
1
}
flexShrink=
{
0
}
/>
}
</
Skeleton
>
</
T
d
>
<
T
d
fontSize=
"sm"
verticalAlign=
"middle"
isNumeric
>
<
Skeleton
isLoaded=
{
!
isLoading
}
whiteSpace=
"nowrap"
overflow=
"hidden"
>
</
T
ableCell
>
<
T
ableCell
verticalAlign=
"middle"
isNumeric
>
<
Skeleton
loading=
{
isLoading
}
whiteSpace=
"nowrap"
overflow=
"hidden"
>
<
Text
overflow=
"hidden"
whiteSpace=
"nowrap"
textOverflow=
"ellipsis"
fontWeight=
{
700
}
>
{
data
.
token_type
===
'
ERC-20
'
&&
data
.
exchange_rate
&&
`$${ Number(data.exchange_rate).toLocaleString() }`
}
{
data
.
token_type
!==
'
ERC-20
'
&&
data
.
total_supply
&&
`Items ${ Number(data.total_supply).toLocaleString() }`
}
</
Text
>
</
Skeleton
>
</
T
d
>
</
T
ableCell
>
</>
);
}
...
...
@@ -121,7 +125,7 @@ const SearchResultTableItem = ({ data, searchTerm, isLoading, addressFormat }: P
return
(
<>
<
T
d
fontSize=
"sm"
colSpan=
{
(
addressName
||
data
.
type
===
'
metadata_tag
'
)
?
1
:
3
}
verticalAlign=
"middle"
>
<
T
ableCell
colSpan=
{
(
addressName
||
data
.
type
===
'
metadata_tag
'
)
?
1
:
3
}
verticalAlign=
"middle"
>
<
AddressEntity
.
Container
>
<
AddressEntity
.
Icon
address=
{
address
}
/>
<
AddressEntity
.
Link
...
...
@@ -131,16 +135,15 @@ const SearchResultTableItem = ({ data, searchTerm, isLoading, addressFormat }: P
<
AddressEntity
.
Content
asProp=
{
shouldHighlightHash
?
'
mark
'
:
'
span
'
}
address=
{
{
...
address
,
hash
}
}
fontSize=
"sm"
lineHeight=
{
5
}
textStyle=
"sm"
fontWeight=
{
700
}
/>
</
AddressEntity
.
Link
>
<
AddressEntity
.
Copy
address=
{
{
...
address
,
hash
}
}
/>
</
AddressEntity
.
Container
>
</
T
d
>
</
T
ableCell
>
{
addressName
&&
(
<
T
d
colSpan=
{
data
.
type
===
'
metadata_tag
'
?
1
:
2
}
fontSize=
"sm"
verticalAlign=
"middle"
>
<
T
ableCell
colSpan=
{
data
.
type
===
'
metadata_tag
'
?
1
:
2
}
verticalAlign=
"middle"
>
<
Flex
alignItems=
"center"
>
<
Text
overflow=
"hidden"
...
...
@@ -150,19 +153,19 @@ const SearchResultTableItem = ({ data, searchTerm, isLoading, addressFormat }: P
<
span
dangerouslySetInnerHTML=
{
{
__html
:
shouldHighlightHash
?
xss
(
addressName
)
:
highlightText
(
addressName
,
searchTerm
)
}
}
/>
{
data
.
ens_info
&&
(
data
.
ens_info
.
names_count
>
1
?
(
<
chakra
.
span
color=
"text
_
secondary"
>
<
chakra
.
span
color=
"text
.
secondary"
>
{
data
.
ens_info
.
names_count
>
39
?
'
40+
'
:
`+${ data.ens_info.names_count - 1 }`
}
</
chakra
.
span
>
)
:
<
chakra
.
span
color=
"text
_
secondary"
>
{
expiresText
}
</
chakra
.
span
>
<
chakra
.
span
color=
"text
.
secondary"
>
{
expiresText
}
</
chakra
.
span
>
)
}
</
Text
>
{
data
.
certified
&&
<
ContractCertifiedLabel
iconSize=
{
4
}
boxSize=
{
4
}
mx=
{
1
}
/>
}
</
Flex
>
</
T
d
>
</
T
ableCell
>
)
}
{
data
.
type
===
'
metadata_tag
'
&&
(
<
T
d
colSpan=
{
addressName
?
1
:
2
}
fontSize=
"sm"
verticalAlign=
"middle"
>
<
T
ableCell
colSpan=
{
addressName
?
1
:
2
}
verticalAlign=
"middle"
>
<
Flex
justifyContent=
"flex-end"
>
{
/* we show regular tag because we don't need all meta info here, but need to highlight search term */
}
<
Tag
display=
"flex"
alignItems=
"center"
>
...
...
@@ -170,7 +173,7 @@ const SearchResultTableItem = ({ data, searchTerm, isLoading, addressFormat }: P
<
span
dangerouslySetInnerHTML=
{
{
__html
:
highlightText
(
data
.
metadata
.
name
,
searchTerm
)
}
}
/>
</
Tag
>
</
Flex
>
</
T
d
>
</
T
ableCell
>
)
}
</>
);
...
...
@@ -181,29 +184,29 @@ const SearchResultTableItem = ({ data, searchTerm, isLoading, addressFormat }: P
return
(
<>
<
T
d
fontSize=
"sm"
>
<
T
ableCell
>
<
Flex
alignItems=
"center"
>
<
IconSvg
name=
"publictags_slim"
boxSize=
{
6
}
mr=
{
2
}
color=
"gray.500"
/>
<
Link
Internal
<
Link
href=
{
route
({
pathname
:
'
/address/[hash]
'
,
query
:
{
hash
:
data
.
address
}
})
}
fontWeight=
{
700
}
wordBreak=
"break-all"
isL
oading=
{
isLoading
}
l
oading=
{
isLoading
}
onClick=
{
handleLinkClick
}
>
<
span
dangerouslySetInnerHTML=
{
{
__html
:
highlightText
(
data
.
name
,
searchTerm
)
}
}
/>
</
Link
Internal
>
</
Link
>
</
Flex
>
</
T
d
>
<
T
d
fontSize=
"sm"
verticalAlign=
"middle"
>
</
T
ableCell
>
<
T
ableCell
verticalAlign=
"middle"
>
<
Flex
alignItems=
"center"
overflow=
"hidden"
>
<
Box
overflow=
"hidden"
whiteSpace=
"nowrap"
w=
{
data
.
is_smart_contract_verified
?
'
calc(100%-28px)
'
:
'
unset
'
}
>
<
HashStringShortenDynamic
hash=
{
hash
}
/>
</
Box
>
{
data
.
is_smart_contract_verified
&&
<
IconSvg
name=
"status/success"
boxSize=
"14px"
color=
"green.500"
ml=
{
1
}
flexShrink=
{
0
}
/>
}
</
Flex
>
</
T
d
>
<
T
d
></
Td
>
</
T
ableCell
>
<
T
ableCell
/
>
</>
);
}
...
...
@@ -212,7 +215,7 @@ const SearchResultTableItem = ({ data, searchTerm, isLoading, addressFormat }: P
const
title
=
<
span
dangerouslySetInnerHTML=
{
{
__html
:
highlightText
(
data
.
app
.
title
,
searchTerm
)
}
}
/>;
return
(
<>
<
T
d
fontSize=
"sm"
>
<
T
ableCell
>
<
Flex
alignItems=
"center"
>
<
Image
borderRadius=
"base"
...
...
@@ -221,21 +224,21 @@ const SearchResultTableItem = ({ data, searchTerm, isLoading, addressFormat }: P
src=
{
colorMode
===
'
dark
'
&&
data
.
app
.
logoDarkMode
?
data
.
app
.
logoDarkMode
:
data
.
app
.
logo
}
alt=
{
`${ data.app.title } app icon`
}
/>
<
Link
Internal
<
Link
href=
{
data
.
app
.
external
?
route
({
pathname
:
'
/apps
'
,
query
:
{
selectedAppId
:
data
.
app
.
id
}
})
:
route
({
pathname
:
'
/apps/[id]
'
,
query
:
{
id
:
data
.
app
.
id
}
})
}
fontWeight=
{
700
}
wordBreak=
"break-all"
isL
oading=
{
isLoading
}
l
oading=
{
isLoading
}
onClick=
{
handleLinkClick
}
>
{
title
}
</
Link
Internal
>
</
Link
>
</
Flex
>
</
T
d
>
<
T
d
fontSize=
"sm"
verticalAlign=
"middle"
colSpan=
{
2
}
>
</
T
ableCell
>
<
T
ableCell
verticalAlign=
"middle"
colSpan=
{
2
}
>
<
Text
overflow=
"hidden"
whiteSpace=
"nowrap"
...
...
@@ -243,7 +246,7 @@ const SearchResultTableItem = ({ data, searchTerm, isLoading, addressFormat }: P
>
{
data
.
app
.
description
}
</
Text
>
</
T
d
>
</
T
ableCell
>
</>
);
}
...
...
@@ -257,7 +260,7 @@ const SearchResultTableItem = ({ data, searchTerm, isLoading, addressFormat }: P
return
(
<>
<
T
d
fontSize=
"sm"
>
<
T
ableCell
>
<
BlockEntity
.
Container
>
<
BlockEntity
.
Icon
isLoading=
{
isLoading
}
/>
<
BlockEntity
.
Link
...
...
@@ -268,33 +271,32 @@ const SearchResultTableItem = ({ data, searchTerm, isLoading, addressFormat }: P
<
BlockEntity
.
Content
asProp=
{
shouldHighlightHash
?
'
span
'
:
'
mark
'
}
number=
{
Number
(
data
.
block_number
)
}
fontSize=
"sm"
lineHeight=
{
5
}
textStyle=
"sm"
fontWeight=
{
700
}
isLoading=
{
isLoading
}
/>
</
BlockEntity
.
Link
>
</
BlockEntity
.
Container
>
</
T
d
>
<
T
d
fontSize=
"sm"
verticalAlign=
"middle"
colSpan=
{
isFutureBlock
?
2
:
1
}
>
</
T
ableCell
>
<
T
ableCell
fontSize=
"sm"
verticalAlign=
"middle"
colSpan=
{
isFutureBlock
?
2
:
1
}
>
{
isFutureBlock
?
(
<
Skeleton
isLoaded=
{
!
isLoading
}
>
Learn estimated time for this block to be created.
</
Skeleton
>
<
Skeleton
loading=
{
isLoading
}
>
Learn estimated time for this block to be created.
</
Skeleton
>
)
:
(
<
Flex
columnGap=
{
2
}
alignItems=
"center"
>
{
data
.
block_type
===
'
reorg
'
&&
!
isLoading
&&
<
Tag
flexShrink=
{
0
}
>
Reorg
</
Tag
>
}
{
data
.
block_type
===
'
uncle
'
&&
!
isLoading
&&
<
Tag
flexShrink=
{
0
}
>
Uncle
</
Tag
>
}
<
Skeleton
isLoaded=
{
!
isLoading
}
overflow=
"hidden"
whiteSpace=
"nowrap"
as=
{
shouldHighlightHash
?
'
mark
'
:
'
span
'
}
display=
"block"
>
<
Skeleton
loading=
{
isLoading
}
overflow=
"hidden"
whiteSpace=
"nowrap"
as=
{
shouldHighlightHash
?
'
mark
'
:
'
span
'
}
display=
"block"
>
<
HashStringShortenDynamic
hash=
{
data
.
block_hash
}
/>
</
Skeleton
>
</
Flex
>
)
}
</
T
d
>
</
T
ableCell
>
{
!
isFutureBlock
&&
(
<
T
d
fontSize=
"sm"
verticalAlign=
"middle"
isNumeric
>
<
Skeleton
isLoaded=
{
!
isLoading
}
color=
"text_
secondary"
>
<
T
ableCell
fontSize=
"sm"
verticalAlign=
"middle"
isNumeric
>
<
Skeleton
loading=
{
isLoading
}
color=
"text.
secondary"
>
<
span
>
{
dayjs
(
data
.
timestamp
).
format
(
'
llll
'
)
}
</
span
>
</
Skeleton
>
</
T
d
>
</
T
ableCell
>
)
}
</>
);
...
...
@@ -303,7 +305,7 @@ const SearchResultTableItem = ({ data, searchTerm, isLoading, addressFormat }: P
case
'
transaction
'
:
{
return
(
<>
<
T
d
colSpan=
{
2
}
fontSize=
"sm"
>
<
T
ableCell
colSpan=
{
2
}
fontSize=
"sm"
>
<
TxEntity
.
Container
>
<
TxEntity
.
Icon
/>
<
TxEntity
.
Link
...
...
@@ -314,23 +316,22 @@ const SearchResultTableItem = ({ data, searchTerm, isLoading, addressFormat }: P
<
TxEntity
.
Content
asProp=
"mark"
hash=
{
data
.
transaction_hash
}
fontSize=
"sm"
lineHeight=
{
5
}
textStyle=
"sm"
fontWeight=
{
700
}
/>
</
TxEntity
.
Link
>
</
TxEntity
.
Container
>
</
T
d
>
<
T
d
fontSize=
"sm"
verticalAlign=
"middle"
isNumeric
>
<
Text
variant=
"
secondary"
>
{
dayjs
(
data
.
timestamp
).
format
(
'
llll
'
)
}
</
Text
>
</
T
d
>
</
T
ableCell
>
<
T
ableCell
fontSize=
"sm"
verticalAlign=
"middle"
isNumeric
>
<
Text
color=
"text.
secondary"
>
{
dayjs
(
data
.
timestamp
).
format
(
'
llll
'
)
}
</
Text
>
</
T
ableCell
>
</>
);
}
case
'
blob
'
:
{
return
(
<
T
d
colSpan=
{
3
}
fontSize=
"sm"
>
<
T
ableCell
colSpan=
{
3
}
fontSize=
"sm"
>
<
BlobEntity
.
Container
>
<
BlobEntity
.
Icon
/>
<
BlobEntity
.
Link
...
...
@@ -341,20 +342,19 @@ const SearchResultTableItem = ({ data, searchTerm, isLoading, addressFormat }: P
<
BlobEntity
.
Content
asProp=
"mark"
hash=
{
data
.
blob_hash
}
fontSize=
"sm"
lineHeight=
{
5
}
textStyle=
"sm"
fontWeight=
{
700
}
/>
</
BlobEntity
.
Link
>
</
BlobEntity
.
Container
>
</
T
d
>
</
T
ableCell
>
);
}
case
'
user_operation
'
:
{
return
(
<>
<
T
d
colSpan=
{
2
}
fontSize=
"sm"
>
<
T
ableCell
colSpan=
{
2
}
fontSize=
"sm"
>
<
UserOpEntity
.
Container
>
<
UserOpEntity
.
Icon
/>
<
UserOpEntity
.
Link
...
...
@@ -365,16 +365,15 @@ const SearchResultTableItem = ({ data, searchTerm, isLoading, addressFormat }: P
<
UserOpEntity
.
Content
asProp=
"mark"
hash=
{
data
.
user_operation_hash
}
fontSize=
"sm"
lineHeight=
{
5
}
textStyle=
"sm"
fontWeight=
{
700
}
/>
</
UserOpEntity
.
Link
>
</
UserOpEntity
.
Container
>
</
T
d
>
<
T
d
fontSize=
"sm"
verticalAlign=
"middle"
isNumeric
>
<
Text
variant=
"
secondary"
>
{
dayjs
(
data
.
timestamp
).
format
(
'
llll
'
)
}
</
Text
>
</
T
d
>
</
T
ableCell
>
<
T
ableCell
fontSize=
"sm"
verticalAlign=
"middle"
isNumeric
>
<
Text
color=
"text.
secondary"
>
{
dayjs
(
data
.
timestamp
).
format
(
'
llll
'
)
}
</
Text
>
</
T
ableCell
>
</>
);
}
...
...
@@ -385,40 +384,40 @@ const SearchResultTableItem = ({ data, searchTerm, isLoading, addressFormat }: P
return
(
<>
<
T
d
fontSize=
"sm"
>
<
T
ableCell
fontSize=
"sm"
>
<
EnsEntity
.
Container
>
<
EnsEntity
.
Icon
protocol=
{
data
.
ens_info
.
protocol
}
/>
<
Link
Internal
<
Link
href=
{
route
({
pathname
:
'
/address/[hash]
'
,
query
:
{
hash
:
data
.
address
}
})
}
fontWeight=
{
700
}
wordBreak=
"break-all"
isL
oading=
{
isLoading
}
l
oading=
{
isLoading
}
onClick=
{
handleLinkClick
}
overflow=
"hidden"
>
<
Skeleton
isLoaded=
{
!
isLoading
}
loading=
{
isLoading
}
dangerouslySetInnerHTML=
{
{
__html
:
highlightText
(
data
.
ens_info
.
name
,
searchTerm
)
}
}
whiteSpace=
"nowrap"
overflow=
"hidden"
textOverflow=
"ellipsis"
/>
</
Link
Internal
>
</
Link
>
</
EnsEntity
.
Container
>
</
T
d
>
<
T
d
>
</
T
ableCell
>
<
T
ableCell
>
<
Flex
alignItems=
"center"
overflow=
"hidden"
>
<
Box
overflow=
"hidden"
whiteSpace=
"nowrap"
w=
{
data
.
is_smart_contract_verified
?
'
calc(100%-28px)
'
:
'
unset
'
}
>
<
HashStringShortenDynamic
hash=
{
hash
}
/>
</
Box
>
{
data
.
is_smart_contract_verified
&&
<
IconSvg
name=
"status/success"
boxSize=
"14px"
color=
"green.500"
ml=
{
1
}
flexShrink=
{
0
}
/>
}
</
Flex
>
</
T
d
>
<
T
d
>
</
T
ableCell
>
<
T
ableCell
>
{
data
.
ens_info
.
names_count
>
1
?
<
chakra
.
span
color=
"text
_
secondary"
>
(
{
data
.
ens_info
.
names_count
>
39
?
'
40+
'
:
`+${ data.ens_info.names_count - 1 }`
}
)
</
chakra
.
span
>
:
<
chakra
.
span
color=
"text
_
secondary"
>
{
expiresText
}
</
chakra
.
span
>
}
</
T
d
>
<
chakra
.
span
color=
"text
.
secondary"
>
(
{
data
.
ens_info
.
names_count
>
39
?
'
40+
'
:
`+${ data.ens_info.names_count - 1 }`
}
)
</
chakra
.
span
>
:
<
chakra
.
span
color=
"text
.
secondary"
>
{
expiresText
}
</
chakra
.
span
>
}
</
T
ableCell
>
</>
);
}
...
...
@@ -428,14 +427,14 @@ const SearchResultTableItem = ({ data, searchTerm, isLoading, addressFormat }: P
const
category
=
getItemCategory
(
data
);
return
(
<
T
r
>
<
T
ableRow
>
{
content
}
<
T
d
fontSize=
"sm"
textTransform=
"capitalize"
verticalAlign=
"middle"
>
<
Skeleton
isLoaded=
{
!
isLoading
}
color=
"text_
secondary"
display=
"inline-block"
>
<
T
ableCell
fontSize=
"sm"
textTransform=
"capitalize"
verticalAlign=
"middle"
>
<
Skeleton
loading=
{
isLoading
}
color=
"text.
secondary"
display=
"inline-block"
>
<
span
>
{
category
?
searchItemTitles
[
category
].
itemTitle
:
''
}
</
span
>
</
Skeleton
>
</
T
d
>
</
T
r
>
</
T
ableCell
>
</
T
ableRow
>
);
};
...
...
ui/searchResults/SearchResultsInput.tsx
View file @
bb9842bc
import
{
PopoverTrigger
,
PopoverContent
,
PopoverBody
,
useDisclosure
}
from
'
@chakra-ui/react
'
;
import
{
debounce
}
from
'
es-toolkit
'
;
import
type
{
FormEvent
,
FocusEvent
}
from
'
react
'
;
import
React
from
'
react
'
;
import
useIsMobile
from
'
lib/hooks/useIsMobile
'
;
import
{
getRecentSearchKeywords
}
from
'
lib/recentSearchKeywords
'
;
import
Popover
from
'
ui/shared/chakra/Popover
'
;
import
{
PopoverBody
,
PopoverContent
,
PopoverRoot
,
PopoverTrigger
}
from
'
toolkit/chakra/popover
'
;
import
{
useDisclosure
}
from
'
toolkit/hooks/useDisclosure
'
;
import
SearchBarBackdrop
from
'
ui/snippets/searchBar/SearchBarBackdrop
'
;
import
SearchBarInput
from
'
ui/snippets/searchBar/SearchBarInput
'
;
import
SearchBarRecentKeywords
from
'
ui/snippets/searchBar/SearchBarRecentKeywords
'
;
...
...
@@ -17,7 +17,7 @@ type Props = {
};
const
SearchResultsInput
=
({
searchTerm
,
handleSubmit
,
handleSearchTermChange
}:
Props
)
=>
{
const
{
isO
pen
,
onClose
,
onOpen
}
=
useDisclosure
();
const
{
o
pen
,
onClose
,
onOpen
}
=
useDisclosure
();
const
inputRef
=
React
.
useRef
<
HTMLFormElement
>
(
null
);
const
menuRef
=
React
.
useRef
<
HTMLDivElement
>
(
null
);
const
menuWidth
=
React
.
useRef
<
number
>
(
0
);
...
...
@@ -25,6 +25,10 @@ const SearchResultsInput = ({ searchTerm, handleSubmit, handleSearchTermChange }
const
recentSearchKeywords
=
getRecentSearchKeywords
();
const
handleOpenChange
=
React
.
useCallback
(({
open
}:
{
open
:
boolean
})
=>
{
open
&&
onOpen
();
},
[
onOpen
]);
const
handleFocus
=
React
.
useCallback
(()
=>
{
onOpen
();
},
[
onOpen
]);
...
...
@@ -47,7 +51,7 @@ const SearchResultsInput = ({ searchTerm, handleSubmit, handleSearchTermChange }
inputRef
.
current
?.
querySelector
(
'
input
'
)?.
focus
();
},
[
handleSearchTermChange
]);
const
menuPaddingX
=
isMobile
?
32
:
0
;
const
menuPaddingX
=
isMobile
?
24
:
0
;
const
calculateMenuWidth
=
React
.
useCallback
(()
=>
{
menuWidth
.
current
=
(
inputRef
.
current
?.
getBoundingClientRect
().
width
||
0
)
-
menuPaddingX
;
},
[
menuPaddingX
]);
...
...
@@ -68,17 +72,15 @@ const SearchResultsInput = ({ searchTerm, handleSubmit, handleSearchTermChange }
};
},
[
calculateMenuWidth
]);
const
isSuggestOpen
=
isO
pen
&&
recentSearchKeywords
.
length
>
0
&&
searchTerm
.
trim
().
length
===
0
;
const
isSuggestOpen
=
o
pen
&&
recentSearchKeywords
.
length
>
0
&&
searchTerm
.
trim
().
length
===
0
;
return
(
<>
<
Popover
isO
pen=
{
isSuggestOpen
}
<
Popover
Root
o
pen=
{
isSuggestOpen
}
autoFocus=
{
false
}
onClose=
{
onClose
}
placement=
"bottom-start"
offset=
{
isMobile
?
[
16
,
-
12
]
:
[
0
,
8
]
}
isLazy
onOpenChange=
{
handleOpenChange
}
positioning=
{
{
offset
:
{
mainAxis
:
isMobile
?
0
:
8
,
crossAxis
:
isMobile
?
12
:
0
}
}
}
>
<
PopoverTrigger
>
<
SearchBarInput
...
...
@@ -98,7 +100,7 @@ const SearchResultsInput = ({ searchTerm, handleSubmit, handleSearchTermChange }
<
SearchBarRecentKeywords
onClick=
{
handleSearchTermChange
}
onClear=
{
onClose
}
/>
</
PopoverBody
>
</
PopoverContent
>
</
Popover
>
</
Popover
Root
>
<
SearchBarBackdrop
isOpen=
{
isSuggestOpen
}
/>
</>
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment