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);
if (txt == "") { debounceTimer = setTimeout(() => {
reallyclear() const txt = searchfield.value;
} if (txt == "") {
else { reallyclear();
xhttp = new XMLHttpRequest(); }
searches.push(xhttp) else {
xhttp.onreadystatechange = searchresult const xhttp = new XMLHttpRequest();
xhttp.open("GET","/api/search?max=5&query=" + encodeURIComponent(txt), true); searches.push(xhttp);
xhttp.send(); xhttp.onreadystatechange = searchresult
} xhttp.open("GET","/api/search?max=5&query=" + encodeURIComponent(txt), true);
xhttp.send();
}
}, 1000);
} }