Add tag filtering

This commit is contained in:
dragongoose 2023-03-25 12:53:10 -04:00
parent edcc3efe1d
commit 73ac63e91c

View File

@ -7,7 +7,8 @@ export default {
return { return {
data: await res.json(), data: await res.json(),
frontend_url frontend_url,
filterTags: ''
} }
}, },
methods: { methods: {
@ -17,6 +18,35 @@ export default {
notation: 'compact', notation: 'compact',
maximumFractionDigits: 1 maximumFractionDigits: 1
}).format(text) }).format(text)
},
filterSearches(toFilter: string) {
const categories = this.$refs.categoryItem
const wantedTags = toFilter.split(',').filter((v) => v.toLowerCase())
for (let category of categories as any) {
let tagElements = category.getElementsByTagName("span")
let tags = []
for (let tag of tagElements) {
tags.push(tag.innerText.toLowerCase())
}
// Create sets from the arrays
const [set1, set2] = [new Set(wantedTags), new Set(tags)]
const common = [...set1].filter(x => set2.has(x));
console.log(wantedTags)
if(common.length === wantedTags.length) {
category.style.display = ""
} else if (wantedTags[0] === "") {
category.style.display = ""
console.log('ok')
} else {
category.style.display = "none"
}
}
} }
} }
} }
@ -38,16 +68,19 @@ export default {
id="searchBar" id="searchBar"
name="searchBar" name="searchBar"
placeholder="Search" placeholder="Search"
v-model="filterTags"
@keyup="filterSearches(filterTags)"
class="rounded-md p-1 pl-8 text-black bg-neutral-500 placeholder:text-white" class="rounded-md p-1 pl-8 text-black bg-neutral-500 placeholder:text-white"
/> />
</form> </form>
</div> </div>
</div> </div>
<ul class=""> <ul ref="categoryList">
<li <li
v-for="category in data" v-for="category in data"
:key="category" :key="category"
ref="categoryItem"
class="inline-flex m-2 hover:scale-105 transition-transform" class="inline-flex m-2 hover:scale-105 transition-transform"
> >
<div class="bg-ctp-crust max-w-[13.5rem] rounded-lg"> <div class="bg-ctp-crust max-w-[13.5rem] rounded-lg">