fucking shitty race condition or something idek what to call that

This commit is contained in:
Elijah R 2024-04-07 17:36:08 -04:00
parent d62a5e7e80
commit bee19d5af9

View file

@ -101,9 +101,7 @@ elements.searchUsersForm.addEventListener('submit', async e => {
elements.usersTableBody.innerHTML = "";
elements.usersPageCount.innerText = data.totalPageCount!.toString(10);
elements.usersPage.max = data.totalPageCount!.toString(10);
for (var user of data.users!) {
(() => {
var _user = user;
data.users?.forEach(user => {
var row = elements.usersTableBody.insertRow();
var cell = row.insertCell();
cell.innerText = user.id.toString(10);
@ -116,16 +114,16 @@ elements.searchUsersForm.addEventListener('submit', async e => {
var rankSelect = document.createElement('select');
rankSelect.classList.add('form-select');
rankSelect.innerHTML = `<option value="1">User</option><option value="2">Administrator</option><option value="3">Moderator</option>`;
rankSelect.value = _user.rank.toString(10);
rankSelect.value = user.rank.toString(10);
rankSelect.addEventListener('change', async e => {
var newRank = parseInt(rankSelect.value);
// @ts-ignore
if (!window.confirm(`Are you sure you want to set ${_user.username}'s rank to ${RankString[newRank]}?`)) {
if (!window.confirm(`Are you sure you want to set ${user.username}'s rank to ${RankString[newRank]}?`)) {
e.preventDefault();
rankSelect.value = _user.rank.toString(10);
rankSelect.value = user.rank.toString(10);
return false;
}
var result = await auth.updateUser(_user.username, newRank);
var result = await auth.updateUser(user.username, newRank);
if (!result.success) {
alert("Failed to set rank: " + result.error);
}
@ -142,7 +140,7 @@ elements.searchUsersForm.addEventListener('submit', async e => {
cell = row.insertCell();
var developerCheckbox = document.createElement('input');
developerCheckbox.type = 'checkbox';
developerCheckbox.checked = _user.developer;
developerCheckbox.checked = user.developer;
developerCheckbox.addEventListener('change', async e => {
var developer = developerCheckbox.checked;
// @ts-ignore
@ -151,14 +149,13 @@ elements.searchUsersForm.addEventListener('submit', async e => {
developerCheckbox.checked = !developer;
return false;
}
var result = await auth.updateUser(_user.username, undefined, developer);
var result = await auth.updateUser(user.username, undefined, developer);
if (!result.success) {
alert("Failed to update developer status: " + result.error);
}
});
cell.appendChild(developerCheckbox);
})();
}
});
return false;
});
@ -171,8 +168,7 @@ elements.searchBotsForm.addEventListener('submit', async e => {
return false;
}
elements.botsTableBody.innerHTML = "";
for (const bot of data.bots!) {
(()=>{
data.bots?.forEach(bot => {
var row = elements.botsTableBody.insertRow();
var cell = row.insertCell();
cell.innerText = bot.id.toString(10);
@ -206,8 +202,7 @@ elements.searchBotsForm.addEventListener('submit', async e => {
cell.innerText = bot.owner;
cell = row.insertCell();
cell.innerText = bot.created;
})();
}
});
return false;
});