Skip to content

Commit

Permalink
rewrite without async keyword
Browse files Browse the repository at this point in the history
seems htmlunit doesn't like it
  • Loading branch information
mawinter69 committed May 6, 2024
1 parent 3b02b44 commit 13ab90f
Showing 1 changed file with 23 additions and 22 deletions.
45 changes: 23 additions & 22 deletions war/src/main/js/components/search-box/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,6 @@ function init() {
ul.classList.add("jenkins-hidden");
comp.appendChild(ul);

async function dataSrc(val) {
const params = new URLSearchParams({ query: val });
let url = searchURL + "suggest?" + params;
const result = await fetch(url);
const data = await result.json();
const list = [];
data.suggestions.forEach((item, i) => {
if (i < maxResults) {
list.push(item.name);
}
});

return list;
}

function handleEvent(event) {
if (event.type === "focus") {
return;
Expand Down Expand Up @@ -119,17 +104,33 @@ function init() {
return false;
}

async function search() {
function search() {
if (!input.value) {
return;
}
suggestions = await dataSrc(input.value);
if (!suggestions.length) {
hide();
return;
}

showSuggestions();
const params = new URLSearchParams({ query: input.value });
let url = searchURL + "suggest?" + params;

fetch(url).then((rsp) => {
if (rsp.ok) {
rsp.json().then((data) => {
const list = [];
data.suggestions.forEach((item, i) => {
if (i < maxResults) {
list.push(item.name);
}
});
suggestions = list;
if (!suggestions.length) {
hide();
return;
}

showSuggestions();
});
}
});
}

function nav(direction, event) {
Expand Down

0 comments on commit 13ab90f

Please sign in to comment.