Skip to content

Commit

Permalink
feat: create useSearch composable + custome filter on CategorySelector
Browse files Browse the repository at this point in the history
  • Loading branch information
wazolab committed Mar 5, 2024
1 parent faabf9a commit 36419e0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
9 changes: 9 additions & 0 deletions components/PoisList/CategorySelector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import { defineNuxtComponent } from '#app'
import TeritorioIcon from '~/components/UI/TeritorioIcon.vue'
import type { ApiMenuCategory, MenuItem } from '~/lib/apiMenu'
import useSearch from '~/composables/useSearch'
export default defineNuxtComponent({
components: {
Expand Down Expand Up @@ -79,6 +80,13 @@ export default defineNuxtComponent({
.sort((a, b) => a && b ? a.title.localeCompare(b.title, localeCompareOptions) : -1)
},
},
methods: {
customFilter(currentItem: string, queryText: string) {
const { searchText } = useSearch()
return searchText(currentItem, queryText)
},
},
})
</script>

Expand All @@ -93,6 +101,7 @@ export default defineNuxtComponent({
variant="solo"
rounded
hide-details="auto"
:custom-filter="customFilter"
@update:model-value="$emit('categoryChange', $event)"
>
<template #prepend-inner>
Expand Down
17 changes: 17 additions & 0 deletions composables/useSearch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export default function () {
function removeDiacritics(str: string) {
return str
.normalize('NFD')
.replace(/[\u0300-\u036F]/g, '')
}

function searchText(currentItem: string, queryText: string) {
const item = removeDiacritics(currentItem.toLowerCase())
const query = removeDiacritics(queryText.toLowerCase())
return item.includes(query)
}

return {
searchText,
}
}

0 comments on commit 36419e0

Please sign in to comment.