Optimize all modals (fetching). Implement add-player modal.

This commit is contained in:
MaxJa4
2024-01-16 20:19:40 +01:00
parent 8c4ed63359
commit fc084108ac
13 changed files with 134 additions and 91 deletions

View File

@@ -57,26 +57,37 @@
"Content-type": "application/json; charset=UTF-8"
}
})
.then((response) => {
if (response.ok) {
const opt = document.createElement('option');
opt.innerText = "[" + clanTag.value + "]" + " " + clanName.value;
opt.value = response.json()['ID'];
.then(() => {
const lastIndex = otherClanList.selectedIndex;
clanList.appendChild(opt.cloneNode(true));
clanList.selectedIndex = clanList.children.length - 1;
clanList.dispatchEvent(new Event('change'));
fetch('/clans_html')
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.text();
})
.then(data => {
clanList.innerHTML = data;
otherClanList.innerHTML = data;
const lastIndex = otherClanList.selectedIndex;
otherClanList.appendChild(opt);
otherClanList.selectedIndex = lastIndex;
clanList.selectedIndex = clanList.children.length - 1;
otherClanList.selectedIndex = lastIndex;
addClanModalBS.hide();
clanName.value = "";
clanTag.value = "";
keepUpdated.checked = false;
} else
throw new Error(response.error)
clanList.dispatchEvent(new Event('change'));
})
.catch(error => {
console.error('There has been a problem with your fetch operation:', error);
});
addClanModalBS.hide();
clanName.value = "";
clanTag.value = "";
keepUpdated.checked = false;
})
.catch((error) => {
throw new Error(error)
});
})
});