functions for adding/removing spot classes to ".server-item"s

This commit is contained in:
Corban-Lee Jones 2024-10-15 12:07:44 +01:00
parent 004e7b8b11
commit 233968634b

View File

@ -67,12 +67,13 @@ const fetchChannels = async serverId => {
$(".sidebar .sidebar-item").prop("disabled", true);
try {
$(`.sidebar .sidebar-item[data-id="${serverId}"]`).removeClass("spot spot-danger");
channels = await ajaxRequest(`/generate-channels?guild=${serverId}`, "GET");
_loadedChannels[serverId] = channels;
unspotItem(serverId); // remove the spot because no errors occured
}
catch (error) {
logError(error);
unspotItem(serverId);
switch (error?.status) {
case 429:
@ -113,7 +114,7 @@ const rateLimitedLoadingChannels = retryAfterSeconds => {
const notAuthorisedLoadingChannels = serverId => {
// Mark the sidebar item as non-operational
$(`.sidebar .sidebar-item[data-id="${serverId}"]`).addClass("spot spot-danger");
spotItem(serverId, "danger");
const inviteBotToServer = () => {
window.open(
@ -297,3 +298,16 @@ async function loadServers() {
// Retry load servers button
$(".sidebar .sidebar-retry-btn").on("click", loadServers);
// region Spot Icons
const unspotItem = id => {
$(`.sidebar .sidebar-item[data-id="${id}"]`).removeClass(
"spot spot-primary spot-secondary spot-success spot-info spot-warning spot-danger"
);
}
const spotItem = (id, spotStyle) => {
$(`.sidebar .sidebar-item[data-id="${id}"]`).addClass(`spot spot-${spotStyle}`);
}