Skip to content

Commit

Permalink
feat: display symbol on search results. Add highlighting. Trim search…
Browse files Browse the repository at this point in the history
…ed value
  • Loading branch information
nicov-iov committed Nov 11, 2024
1 parent 22b7b5b commit 9407af4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
27 changes: 22 additions & 5 deletions src/components/Search/CtrlSearch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@
<a
:href="result.link"
@touchend.passive="gotoResult($event, i)"
@click="gotoResult($event, i)">
{{ result.name || result.value }}
@click="gotoResult($event, i)"
v-html="highlightedText(result.name || result.value)"
>
</a>
</div>
</template>
Expand Down Expand Up @@ -91,8 +92,15 @@ export default {
'searchTypes',
'fetchSearch'
]),
highlightedText (text) {
const formattedValue = this.formatValue(this.value)
const regex = new RegExp(`(${formattedValue})`, 'gi')
const highlightedText = text.replace(regex, (match) => `<span class="highlight">${match}</span>`)
console.log({ text, regex, highlightedText, results: this.results })
return highlightedText
},
formatValue (value) {
return value.toString().replaceAll(',', '')
return value.toString().replaceAll(',', '').trim()
},
btnClear () {
this.clear()
Expand Down Expand Up @@ -121,8 +129,8 @@ export default {
this.selectResult(0)
const value = event.target.value
this.value = value
this.emit(event, type, value)
this.emit(event, 'change', value)
this.emit(event, type, value.trim())
this.emit(event, 'change', value.trim())
},
emit (event, type, value) {
type = type || event.type
Expand Down Expand Up @@ -230,3 +238,12 @@ export default {
}
}
</script>
<style>
.highlight {
background-color: #ffef60;
color: #000;
border-radius: 4px;
font-weight: bold;
}
</style>
8 changes: 6 additions & 2 deletions src/store/modules/search/payloads.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ export const createPayloads = (payloads) => {
}

const getAddressName = data => {
const { address, name } = data
return `${name} ${address}`
const { address, symbol, name } = data
const validSymbol = typeof symbol === 'string' && symbol !== ''

if (validSymbol) return `(${symbol}) ${name}: ${address}`

return `${name}: ${address}`
}

const getAddressTime = data => {
Expand Down

0 comments on commit 9407af4

Please sign in to comment.