modified: static/js/game.js
This commit is contained in:
@@ -76,6 +76,7 @@
|
|||||||
|
|
||||||
// ---------- Suche / Autocomplete ----------
|
// ---------- Suche / Autocomplete ----------
|
||||||
let searchTimer = null;
|
let searchTimer = null;
|
||||||
|
let searchSeq = 0;
|
||||||
let suggestions = [];
|
let suggestions = [];
|
||||||
let selectedIndex = -1;
|
let selectedIndex = -1;
|
||||||
|
|
||||||
@@ -84,7 +85,10 @@
|
|||||||
const q = searchInput.value.trim();
|
const q = searchInput.value.trim();
|
||||||
if (!q) { closeAutocomplete(); return; }
|
if (!q) { closeAutocomplete(); return; }
|
||||||
searchTimer = setTimeout(async () => {
|
searchTimer = setTimeout(async () => {
|
||||||
|
const mySeq = ++searchSeq;
|
||||||
const res = await fetch(`/api/search?q=${encodeURIComponent(q)}`);
|
const res = await fetch(`/api/search?q=${encodeURIComponent(q)}`);
|
||||||
|
// Nur die aktuellste Anfrage uebernehmen (Race vermeiden)
|
||||||
|
if (mySeq !== searchSeq) return;
|
||||||
suggestions = await res.json();
|
suggestions = await res.json();
|
||||||
renderAutocomplete();
|
renderAutocomplete();
|
||||||
}, 200);
|
}, 200);
|
||||||
|
|||||||
Reference in New Issue
Block a user