@@ -13,6 +13,9 @@ import Spinner from "@/components/ui/Spinner.vue"
1313/** API */
1414import { search } from " @/services/api/search"
1515
16+ /** Services */
17+ import { shortHex } from " @/services/utils"
18+
1619const wrapperEl = ref ()
1720const inputRef = ref ()
1821const searchTerm = ref (" " )
@@ -57,7 +60,20 @@ const debouncedSearch = useDebounceFn(async () => {
5760 isSearching .value = true
5861
5962 const { data } = await search (searchTerm .value .trim ())
60- results .value = data .value
63+ if (data .value ? .length ) {
64+ results .value = data .value .map (res => {
65+ const metadata = getResultMetadata (res)
66+ return {
67+ ... res,
68+ type: metadata .type ,
69+ title: metadata .title ,
70+ subtitle: metadata .subtitle ,
71+ routerLink: metadata .routerLink ,
72+ }
73+ })
74+ } else {
75+ results .value = []
76+ }
6177
6278 isSearching .value = false
6379}, 250 )
@@ -68,7 +84,7 @@ const handleInput = () => {
6884}
6985
7086const getResultMetadata = (target ) => {
71- let metadata = { type: null , title: null , routerLink: null }
87+ let metadata = { type: null , title: null , subtitle : null , routerLink: null }
7288
7389 switch (target .type .toLowerCase ()) {
7490 case " tx" :
@@ -92,12 +108,7 @@ const getResultMetadata = (target) => {
92108
93109 case " address" :
94110 metadata .type = target .type
95- if (target .result .celestials ? .name ) {
96- metadata .title = target .result .celestials ? .name
97- metadata .subtitle = target .result .hash
98- } else {
99- metadata .title = target .result .alias || target .result .hash
100- }
111+ metadata .title = target .result .celestials ? .name || target .result .alias || target .result .hash
101112 metadata .routerLink = ` /address/${ target .bookmark ? target .result .id : target .result .hash } `
102113 break
103114
@@ -157,12 +168,11 @@ const handleSelect = () => {
157168 < Text size= " 12" weight= " 600" color= " tertiary" > Results< / Text >
158169
159170 < Flex direction= " column" >
160- < NuxtLink v- for = " result in results" : to= " getResultMetadata(result).routerLink" >
161- < Flex align= " center" justify= " between" : class = " $style.item" >
162- < Flex align= " center" gap= " 8" >
163- < Icon : name= " getResultMetadata(result).type" size= " 12" color= " tertiary" / >
164- < Text size= " 13" weight= " 600" color= " primary" > {{ getResultMetadata (result).title }}< / Text >
165- < Text v- if = " getResultMetadata(result).subtitle" size= " 12" weight= " 500" color= " tertiary" > {{ getResultMetadata (result).subtitle }}< / Text >
171+ < NuxtLink v- for = " result in results" : to= " result.routerLink" >
172+ < Flex align= " center" justify= " between" gap= " 4" : class = " $style.item" >
173+ < Flex align= " center" gap= " 8" : class = " $style.title_wrapper" >
174+ < Icon : name= " result.type" size= " 12" color= " tertiary" / >
175+ < Text size= " 13" weight= " 600" color= " primary" : class = " $style.title" > {{ result .title }}< / Text >
166176 < / Flex>
167177
168178 < Text size= " 13" weight= " 500" color= " tertiary" style= " text-transform: capitalize" > {{ result .type }}< / Text >
@@ -208,7 +218,8 @@ const handleSelect = () => {
208218.popup {
209219 position: absolute;
210220 max- width: 600px ;
211- top: 40px ;
221+ /* top: 40px; */
222+ top: calc (100 % + 10px );
212223 left: 0 ;
213224 right: 0 ;
214225 z- index: 1000 ;
@@ -245,19 +256,36 @@ const handleSelect = () => {
245256 & : hover {
246257 background: var (-- op- 5 );
247258 }
259+
260+ .title_wrapper {
261+ width: 90 % ;
262+
263+ .title {
264+ max- width: 100 % ;
265+ text- overflow: ellipsis;
266+ overflow: hidden;
267+ white- space: nowrap;
268+ }
269+ }
248270}
249271
250272@media (max - width : 800px ) {
251273 .wrapper {
252- position: initial ;
274+ position: relative ;
253275 }
254276
255277 .popup {
256278 max- width: initial;
257279
258- top: 160px ;
280+ /* top: 160px; */
259281 left: 12px ;
260282 right: 12px ;
261283 }
284+
285+ .item {
286+ .title_wrapper {
287+ width: 85 % ;
288+ }
289+ }
262290}
263291< / style>
0 commit comments