Added support for regexp

This commit is contained in:
Aleksandr Statciuk 2022-01-27 22:48:40 +03:00
parent aa41be0510
commit 2734ec7870
2 changed files with 12 additions and 5 deletions

View file

@ -28,7 +28,7 @@ const CountryItem = {
components: { components: {
ChannelItem ChannelItem
}, },
props: ['item', 'query'], props: ['item', 'normQuery', 'regQuery'],
data() { data() {
return { return {
count: 0 count: 0
@ -36,11 +36,16 @@ const CountryItem = {
}, },
computed: { computed: {
countryChannels() { countryChannels() {
if (!this.query) return this.item.channels if (!this.normQuery) return this.item.channels
return ( return (
this.item.channels.filter(c => { this.item.channels.filter(c => {
return c.key.includes(this.query) const normResult = c.key.includes(this.normQuery)
const regResult = this.regQuery
? this.regQuery.test(c.name) || this.regQuery.test(c.id)
: false
return normResult || regResult
}) || [] }) || []
) )
} }
@ -86,7 +91,7 @@ const CountryItem = {
</span> </span>
</button> </button>
</div> </div>
<div class="card-content" v-show="item.expanded || (count > 0 && query.length)"> <div class="card-content" v-show="item.expanded || (count > 0 && normQuery.length)">
<div class="table-container"> <div class="table-container">
<table class="table" style="min-width: 100%"> <table class="table" style="min-width: 100%">
<thead> <thead>
@ -116,12 +121,14 @@ const App = {
isLoading: true, isLoading: true,
query: '', query: '',
normQuery: '', normQuery: '',
regQuery: null,
items: [] items: []
} }
}, },
methods: { methods: {
search() { search() {
this.normQuery = this.query.replace(/\s/g, '').toLowerCase() this.normQuery = this.query.replace(/\s/g, '').toLowerCase()
this.regQuery = new RegExp(this.query)
} }
}, },
async mounted() { async mounted() {

View file

@ -62,7 +62,7 @@
<div class="level-item">Loading...</div> <div class="level-item">Loading...</div>
</div> </div>
<country-item v-for="item in items" :item="item" :query="normQuery"></country-item> <country-item v-for="item in items" :item="item" :norm-query="normQuery" :reg-query="regQuery"></country-item>
</div> </div>
</div> </div>
</div> </div>