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

@@ -45,24 +45,29 @@
"Content-type": "application/json; charset=UTF-8"
}
})
.then((response) => {
if (response.ok) {
const clanToRemove = clanList.children[clanList.selectedIndex];
const clanIndex = clanToRemove.index;
clanList.removeChild(clanToRemove);
clanList.selectedIndex = 0;
clanList.dispatchEvent(new Event('change'));
.then(() => {
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 lastOtherIndex = otherClanList.selectedIndex;
otherClanList.children.item(clanIndex).remove();
if (lastOtherIndex === clanIndex) {
otherClanList.selectedIndex = 0;
clanList.dispatchEvent(new Event('change'));
otherClanList.dispatchEvent(new Event('change'));
}
})
.catch(error => {
console.error('There has been a problem with your fetch operation:', error);
});
deleteClanModalBS.hide();
} else
throw new Error(response.error)
deleteClanModalBS.hide();
})
.catch((error) => {
throw new Error(error)
});
})
});