Refactor invoice loading and search functionality for improved performance and user experience
This commit is contained in:
parent
810dbd7781
commit
aa8f049444
|
|
@ -183,16 +183,15 @@ export function renderFacturasPage() {
|
||||||
|
|
||||||
const searchInput = container.querySelector('.search-input');
|
const searchInput = container.querySelector('.search-input');
|
||||||
searchInput.addEventListener('input', (e) => {
|
searchInput.addEventListener('input', (e) => {
|
||||||
const inputValue = e.target.value;
|
const inputValue = e.target.value.trim();
|
||||||
// Debounce para no hacer muchas llamadas
|
// Debounce para no hacer muchas llamadas
|
||||||
clearTimeout(searchInput.debounceTimer);
|
clearTimeout(searchInput.debounceTimer);
|
||||||
searchInput.debounceTimer = setTimeout(() => {
|
searchInput.debounceTimer = setTimeout(() => {
|
||||||
// Solo aplicar búsqueda si contiene al menos un número
|
// Validación mínima: al menos 2 caracteres para activar búsqueda
|
||||||
const hasNumber = /\d/.test(inputValue);
|
if (inputValue.length >= 2) {
|
||||||
if (hasNumber && inputValue !== 'I' && inputValue !== 'IN' && inputValue !== 'N') {
|
|
||||||
searchTerm = inputValue;
|
searchTerm = inputValue;
|
||||||
} else {
|
} else {
|
||||||
searchTerm = ''; // Si no tiene número, mostrar todas
|
searchTerm = ''; // Si es muy corto, mostrar todas
|
||||||
}
|
}
|
||||||
applyFilters();
|
applyFilters();
|
||||||
}, 500); // Espera 500ms después de que el usuario deja de escribir
|
}, 500); // Espera 500ms después de que el usuario deja de escribir
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue