Add debounce timer to search, GH-370

This commit is contained in:
krateng 2025-01-16 06:22:35 +01:00
parent 1462883ab5
commit 26f26f36cb

View File

@ -1,17 +1,23 @@
var searches = [] var searches = []
var debounceTimer;
function search(searchfield) { function search(searchfield) {
txt = searchfield.value; clearTimeout(debounceTimer);
debounceTimer = setTimeout(() => {
const txt = searchfield.value;
if (txt == "") { if (txt == "") {
reallyclear() reallyclear();
} }
else { else {
xhttp = new XMLHttpRequest(); const xhttp = new XMLHttpRequest();
searches.push(xhttp) searches.push(xhttp);
xhttp.onreadystatechange = searchresult xhttp.onreadystatechange = searchresult
xhttp.open("GET","/api/search?max=5&query=" + encodeURIComponent(txt), true); xhttp.open("GET","/api/search?max=5&query=" + encodeURIComponent(txt), true);
xhttp.send(); xhttp.send();
} }
}, 1000);
} }