fetch items from server before locally checking available IDs

This commit is contained in:
jomo 2022-08-11 02:52:00 +02:00
parent ade2219469
commit 6b7c741658

View file

@ -3,12 +3,16 @@ const id = new URLSearchParams(window.location.search).get('id');
document.onreadystatechange = function() {
if (document.readyState === 'interactive') {
fetchItems(fillForm);
}
}
function fetchItems(cb) {
fetch('/api/items').then(r => r.json()).then((data) => {
items = data;
fillForm();
cb();
});
}
}
function fillForm() {
const item = items[id];
@ -77,6 +81,7 @@ function save() {
hidden: document.getElementById('hidden').checked,
}
fetchItems(() => {
if (item.id.includes('?')) {
let n = 1;
while (true) {
@ -111,6 +116,7 @@ function save() {
}).catch(error => {
alert(`Error:\n${error}`);
});
});
}
function del() {