feat: refs #6839 normalize search #936

Merged
jorgep merged 1 commits from 6839-normalizeSearch into dev 2024-11-14 14:06:04 +00:00
1 changed files with 19 additions and 4 deletions

View File

@ -34,18 +34,26 @@ const search = ref(null);
const filteredItems = computed(() => { const filteredItems = computed(() => {
if (!search.value) return items.value; if (!search.value) return items.value;
const normalizedSearch = normalize(search.value);
return items.value.filter((item) => { return items.value.filter((item) => {
const locale = t(item.title).toLowerCase(); const locale = normalize(t(item.title));
return locale.includes(search.value.toLowerCase()); return locale.includes(normalizedSearch);
}); });
}); });
const filteredPinnedModules = computed(() => { const filteredPinnedModules = computed(() => {
if (!search.value) return pinnedModules.value; if (!search.value) return pinnedModules.value;
const normalizedSearch = search.value
.normalize('NFD')
.replace(/[\u0300-\u036f]/g, '')
.toLowerCase();
const map = new Map(); const map = new Map();
for (const [key, pinnedModule] of pinnedModules.value) { for (const [key, pinnedModule] of pinnedModules.value) {
const locale = t(pinnedModule.title).toLowerCase(); const locale = t(pinnedModule.title)
if (locale.includes(search.value.toLowerCase())) map.set(key, pinnedModule); .normalize('NFD')
.replace(/[\u0300-\u036f]/g, '')
.toLowerCase();
if (locale.includes(normalizedSearch)) map.set(key, pinnedModule);
} }
return map; return map;
}); });
@ -147,6 +155,13 @@ async function togglePinned(item, event) {
const handleItemExpansion = (itemName) => { const handleItemExpansion = (itemName) => {
expansionItemElements[itemName].scrollToLastElement(); expansionItemElements[itemName].scrollToLastElement();
}; };
function normalize(text) {
Review

Pasa los acentos o diéresis a letras normales, solicitado por J. Gallego.

Pasa los acentos o diéresis a letras normales, solicitado por J. Gallego.
return text
.normalize('NFD')
.replace(/[\u0300-\u036f]/g, '')
.toLowerCase();
}
</script> </script>
<template> <template>