Commit 58d17d33 authored by nanahira's avatar nanahira

fetchSuggestions add debounce

parent 69e8ab72
Pipeline #35937 passed with stages
in 2 minutes and 25 seconds
...@@ -196,7 +196,14 @@ ...@@ -196,7 +196,14 @@
{% endif %} {% endif %}
<script> <script>
async function fetchSuggestions() { function debounce(fn, delay) {
let timeout = null;
return function (...args) {
clearTimeout(timeout);
timeout = setTimeout(() => fn.apply(this, args), delay);
};
}
async function _fetchSuggestions() {
const input = document.getElementById("guess"); const input = document.getElementById("guess");
const hid = document.getElementById("guess_id"); const hid = document.getElementById("guess_id");
const sug = document.getElementById("suggestions"); const sug = document.getElementById("suggestions");
...@@ -219,6 +226,7 @@ ...@@ -219,6 +226,7 @@
} }
sug.hidden = false; sug.hidden = false;
} }
const fetchSuggestions = debounce(_fetchSuggestions, 300);
document.addEventListener('click', e => { document.addEventListener('click', e => {
if (!e.target.closest('#guess')) { if (!e.target.closest('#guess')) {
document.getElementById("suggestions").hidden = true; document.getElementById("suggestions").hidden = true;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment