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,64 +101,61 @@ 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;
var row = elements.usersTableBody.insertRow();
var cell = row.insertCell();
cell.innerText = user.id.toString(10);
cell = row.insertCell();
cell.innerText = user.username;
cell = row.insertCell();
cell.innerText = user.email;
cell = row.insertCell();
// Rank dropdown
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.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]}?`)) {
e.preventDefault();
rankSelect.value = _user.rank.toString(10);
return false;
}
var result = await auth.updateUser(_user.username, newRank);
if (!result.success) {
alert("Failed to set rank: " + result.error);
}
});
cell.appendChild(rankSelect);
cell = row.insertCell();
cell.innerText = user.banned ? "Yes" : "No";
cell = row.insertCell();
cell.innerText = user.dateOfBirth;
cell = row.insertCell();
cell.innerText = user.dateJoined;
cell = row.insertCell();
cell.innerText = user.registrationIp;
cell = row.insertCell();
var developerCheckbox = document.createElement('input');
developerCheckbox.type = 'checkbox';
developerCheckbox.checked = _user.developer;
developerCheckbox.addEventListener('change', async e => {
var developer = developerCheckbox.checked;
// @ts-ignore
if (!window.confirm(`Are you sure you want to ${developer ? "grant" : "revoke"} developer status ${developer ? "to" : "from"} ${_user.username}?`)) {
e.preventDefault();
developerCheckbox.checked = !developer;
return false;
}
var result = await auth.updateUser(_user.username, undefined, developer);
if (!result.success) {
alert("Failed to update developer status: " + result.error);
}
});
cell.appendChild(developerCheckbox);
})();
}
data.users?.forEach(user => {
var row = elements.usersTableBody.insertRow();
var cell = row.insertCell();
cell.innerText = user.id.toString(10);
cell = row.insertCell();
cell.innerText = user.username;
cell = row.insertCell();
cell.innerText = user.email;
cell = row.insertCell();
// Rank dropdown
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.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]}?`)) {
e.preventDefault();
rankSelect.value = user.rank.toString(10);
return false;
}
var result = await auth.updateUser(user.username, newRank);
if (!result.success) {
alert("Failed to set rank: " + result.error);
}
});
cell.appendChild(rankSelect);
cell = row.insertCell();
cell.innerText = user.banned ? "Yes" : "No";
cell = row.insertCell();
cell.innerText = user.dateOfBirth;
cell = row.insertCell();
cell.innerText = user.dateJoined;
cell = row.insertCell();
cell.innerText = user.registrationIp;
cell = row.insertCell();
var developerCheckbox = document.createElement('input');
developerCheckbox.type = 'checkbox';
developerCheckbox.checked = user.developer;
developerCheckbox.addEventListener('change', async e => {
var developer = developerCheckbox.checked;
// @ts-ignore
if (!window.confirm(`Are you sure you want to ${developer ? "grant" : "revoke"} developer status ${developer ? "to" : "from"} ${_user.username}?`)) {
e.preventDefault();
developerCheckbox.checked = !developer;
return false;
}
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,43 +168,41 @@ elements.searchBotsForm.addEventListener('submit', async e => {
return false;
}
elements.botsTableBody.innerHTML = "";
for (const bot of data.bots!) {
(()=>{
var row = elements.botsTableBody.insertRow();
var cell = row.insertCell();
cell.innerText = bot.id.toString(10);
cell = row.insertCell();
cell.innerText = bot.username;
cell = row.insertCell();
if (auth!.account!.rank === 2) {
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 = bot.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 ${bot.username}'s rank to ${RankString[newRank]}?`)) {
e.preventDefault();
rankSelect.value = bot.rank.toString(10);
return false;
}
var result = await auth.adminUpdateBot(bot.username, newRank);
if (!result.success) {
alert("Failed to set rank: " + result.error);
}
});
cell.appendChild(rankSelect);
} else {
data.bots?.forEach(bot => {
var row = elements.botsTableBody.insertRow();
var cell = row.insertCell();
cell.innerText = bot.id.toString(10);
cell = row.insertCell();
cell.innerText = bot.username;
cell = row.insertCell();
if (auth!.account!.rank === 2) {
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 = bot.rank.toString(10);
rankSelect.addEventListener('change', async e => {
var newRank = parseInt(rankSelect.value);
// @ts-ignore
cell.innerText = RankString[bot.rank];
}
cell = row.insertCell();
cell.innerText = bot.owner;
cell = row.insertCell();
cell.innerText = bot.created;
})();
}
if (!window.confirm(`Are you sure you want to set ${bot.username}'s rank to ${RankString[newRank]}?`)) {
e.preventDefault();
rankSelect.value = bot.rank.toString(10);
return false;
}
var result = await auth.adminUpdateBot(bot.username, newRank);
if (!result.success) {
alert("Failed to set rank: " + result.error);
}
});
cell.appendChild(rankSelect);
} else {
// @ts-ignore
cell.innerText = RankString[bot.rank];
}
cell = row.insertCell();
cell.innerText = bot.owner;
cell = row.insertCell();
cell.innerText = bot.created;
});
return false;
});