Skip to content

Commit

Permalink
Add debounce timer to search, GH-370
Browse files Browse the repository at this point in the history
  • Loading branch information
krateng committed Jan 16, 2025
1 parent 1462883 commit 26f26f3
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions maloja/web/static/js/search.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
var searches = []
var debounceTimer;

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


}


Expand Down

0 comments on commit 26f26f3

Please sign in to comment.