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