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