feat: #8410 added new feature to module searchbar #1272

Merged
provira merged 18 commits from 8410-improveModuleSearchbar into dev 2025-01-31 10:02:50 +00:00
1 changed files with 7 additions and 17 deletions
Showing only changes of commit 860f92cb42 - Show all commits

View File

@ -25,7 +25,6 @@ const props = defineProps({
});
const initialized = ref(false);
const items = ref([]);
const searchingValue = false;
const expansionItemElements = reactive({});
const pinnedModules = computed(() => {
const map = new Map();
@ -177,17 +176,9 @@ function normalize(text) {
.toLowerCase();
}
const searchModule = () => {
provira marked this conversation as resolved Outdated

Estás haciendo 2 bucles, pasar a 1. Respuesta de copilot:

const searchModule = () => {
    const searching = ref(false);
    items.value.some((item) => {
        const title = getLocale(item.title).normalize('NFD').replace(/[\u0300-\u036f]/g, '').toLowerCase();
        if (title.includes(search.value.toLowerCase()) && !searching.value) {
            searching.value = true;
            router.push({ name: item.name });
            return true; // Termina el bucle al encontrar el primer resultado
        }
        return false;
    });
}
Estás haciendo 2 bucles, pasar a 1. Respuesta de copilot: ``` const searchModule = () => { const searching = ref(false); items.value.some((item) => { const title = getLocale(item.title).normalize('NFD').replace(/[\u0300-\u036f]/g, '').toLowerCase(); if (title.includes(search.value.toLowerCase()) && !searching.value) { searching.value = true; router.push({ name: item.name }); return true; // Termina el bucle al encontrar el primer resultado } return false; }); } ```
const searching = ref(false);
items.value.some((item) => {
const title = normalize(t(item.title));
if (title.includes(search.value.toLowerCase()) && !searching.value) {
searching.value = true;
router.push({ name: item.name });
return true;
}
return false;
});
}
const [item] = filteredItems.value;
if (item) router.push({ name: item.name });
jorgep marked this conversation as resolved Outdated

No es necesario que sea ref, usar variable normal.

No es necesario que sea ref, usar variable normal.

arreglado

arreglado
};
</script>
<template>
@ -203,12 +194,11 @@ const searchModule = () => {
filled
dense
autofocus
provira marked this conversation as resolved Outdated

Solo gastas esta función en 1 sitio, es innecesaria.

Solo gastas esta función en 1 sitio, es innecesaria.
@keyup.enter.stop="searchingValue ? searchModule(search) : ''"
@update:model-value="searchingValue = !!$event"
@keyup.enter.stop="search ? searchModule(search) : ''"
jorgep marked this conversation as resolved Outdated

llamar solo a la fn searchModule() @keyup.enter.stop="searchModule()"

llamar solo a la fn **searchModule()** `@keyup.enter.stop="searchModule()"`
/>
</QItem>
<QSeparator />
jorgep marked this conversation as resolved Outdated

Las variables ponlas juntas y las funciones lo mismo.

Las variables ponlas juntas y las funciones lo mismo.
<template v-if="filteredPinnedModules.size && !searchingValue">
<template v-if="filteredPinnedModules.size && !search">
provira marked this conversation as resolved Outdated

Solo gastas esta función en 1 sitio, es innecesaria.

Solo gastas esta función en 1 sitio, es innecesaria.
<LeftMenuItem
v-for="[key, pinnedModule] of filteredPinnedModules"
:key="key"
@ -234,9 +224,9 @@ const searchModule = () => {
</template>
<template v-for="(item, index) in filteredItems" :key="item.name">
<template
v-if="searchingValue ||item.children && !filteredPinnedModules.has(item.name)"
v-if="search ||item.children && !filteredPinnedModules.has(item.name)"
>
<LeftMenuItem :item="item" group="modules" :class="searchingValue && index === 0 ? 'searched' : ''">
<LeftMenuItem :item="item" group="modules" :class="search && index === 0 ? 'searched' : ''">
<template #side>
<QBtn
v-if="item.isPinned === true"