Browse Source

fix: implement debounce for user search input to improve performance

Manuel 1 năm trước cách đây
mục cha
commit
e37aa8aeec
1 tập tin đã thay đổi với 10 bổ sung và 1 xóa
  1. 10 1
      static/js/dashboard.js

+ 10 - 1
static/js/dashboard.js

@@ -295,7 +295,16 @@ document.addEventListener("DOMContentLoaded", function () {
     });
   }
 
-  if (searchInput) searchInput.addEventListener("input", filterUsers);
+  // Debounce for input search
+  let searchDebounceTimeout;
+  if (searchInput) {
+    searchInput.addEventListener("input", function () {
+      if (searchDebounceTimeout) clearTimeout(searchDebounceTimeout);
+      searchDebounceTimeout = setTimeout(() => {
+        filterUsers();
+      }, 2000); // 2 segundos
+    });
+  }
   if (prevBtn)
     prevBtn.addEventListener("click", () => {
       if (currentPage > 1) {