tag suggestions
This commit is contained in:
@ -113,9 +113,18 @@ const flash = ({ type, msg }) => {
|
||||
const input = document.createElement("input");
|
||||
input.size = "10";
|
||||
input.value = "";
|
||||
input.setAttribute("list", "testlist");
|
||||
|
||||
let tt;
|
||||
input.addEventListener("keydown", async e => {
|
||||
span.insertAdjacentElement("afterbegin", input);
|
||||
insert.insertAdjacentElement("beforebegin", span);
|
||||
|
||||
input.focus();
|
||||
|
||||
let tt = null;
|
||||
let lastInput = '';
|
||||
const testList = document.querySelector('#testList');
|
||||
|
||||
input.addEventListener("keyup", async e => {
|
||||
if(e.key === "Enter") {
|
||||
const tmptag = input.value?.trim();
|
||||
if(tags.includes(tmptag))
|
||||
@ -130,18 +139,42 @@ const flash = ({ type, msg }) => {
|
||||
tags = res.tags.map(t => t.tag);
|
||||
renderTags(res.tags);
|
||||
addtagClick();
|
||||
testList.innerText = "";
|
||||
}
|
||||
else if(e.key === "Escape") {
|
||||
span.parentElement.removeChild(span);
|
||||
testList.innerText = "";
|
||||
}
|
||||
else {
|
||||
if(tt != null)
|
||||
clearTimeout(tt);
|
||||
|
||||
tt = setTimeout(async () => {
|
||||
globalTimeout = null;
|
||||
|
||||
const tmptag = input.value?.trim();
|
||||
|
||||
if(tmptag == lastInput || tmptag.length <= 1)
|
||||
return false;
|
||||
|
||||
testList.innerText = "";
|
||||
lastInput = tmptag;
|
||||
|
||||
const res = await (await post("/api/v2/admin/tags/suggest", {
|
||||
searchString: tmptag
|
||||
})).json();
|
||||
|
||||
for(const entry of res.suggestions) {
|
||||
const option = document.createElement('option');
|
||||
option.value = entry.tag;
|
||||
option.innerText = `tagged ${entry.tagged} times`;
|
||||
testList.insertAdjacentElement('beforeEnd', option);
|
||||
};
|
||||
}, 500);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
span.insertAdjacentElement("afterbegin", input);
|
||||
insert.insertAdjacentElement("beforebegin", span);
|
||||
|
||||
input.focus();
|
||||
|
||||
input.addEventListener("focusout", ie => {
|
||||
if(input.value.length === 0)
|
||||
input.parentElement.parentElement.removeChild(input.parentElement);
|
||||
|
Reference in New Issue
Block a user