forked from tsoding/seroost
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
27 lines (25 loc) · 839 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// TODO: live update results as you type
async function search(prompt) {
const results = document.getElementById("results")
results.innerHTML = "";
const response = await fetch("/api/search", {
method: 'POST',
headers: {'Content-Type': 'text/plain'},
body: prompt,
});
const json = await response.json();
results.innerHTML = "";
for ([path, rank] of json) {
let item = document.createElement("span");
item.appendChild(document.createTextNode(path));
item.appendChild(document.createElement("br"));
results.appendChild(item);
}
}
let query = document.getElementById("query");
let currentSearch = Promise.resolve()
query.addEventListener("keypress", (e) => {
if (e.key == "Enter") {
currentSearch.then(() => search(query.value));
}
})