diff --git a/apps/static/js/home/servers.js b/apps/static/js/home/servers.js index b07c850..c75f299 100644 --- a/apps/static/js/home/servers.js +++ b/apps/static/js/home/servers.js @@ -1,3 +1,6 @@ + +// #region Loaded Servers + var loadedServers = {}; // Returns the currently active server, or null if none are active. @@ -44,9 +47,21 @@ function removeFromLoadedServers(serverPrimaryKey) { delete loadedServers[serverPrimaryKey]; removeServerTemplate(serverPrimaryKey); + $("#backToSelectServer").click(); +} + +// #endregion + +// #region Server Back Btn + +$("#backToSelectServer").on("click", function() { $("#noSelectedServer").show(); $("#selectedServerContainer").hide(); -} +}); + +// #endregion + +// #region Server Modal $("#serverOptionsRefreshBtn").on("click", async function() { await loadServerOptions(); @@ -94,6 +109,10 @@ async function loadServerOptions() { } +// #endregion + +// #region Server Sidebar + // Load any existing 'saved guilds' from the database async function loadSavedGuilds() { try { @@ -144,6 +163,10 @@ function newServerModal() { $("#serverFormModal").modal("show"); } +// #endregion + +// #region New Server + // Submit 'Add Server' Form $("#serverForm").on("submit", async function(event) { event.preventDefault(); @@ -186,6 +209,10 @@ async function registerNewServer(serverName, serverGuildId, serverIconHash, serv return response.id; } +// #endregion + +// #region Select Server + function selectServer(primaryKey) { var server = loadedServers[primaryKey]; @@ -212,6 +239,10 @@ function selectServer(primaryKey) { $(document).trigger("selectedServerChange"); } +// #endregion + +// #region Delete Server Btn + $("#deleteSelectedServerBtn").on("click", async function() { var activeServer = getCurrentlyActiveServer(); @@ -231,4 +262,38 @@ $("#deleteSelectedServerBtn").on("click", async function() { alert(JSON.stringify(error, null, 4)) } -}); \ No newline at end of file +}); + +// #endregion + +$(document).on("selectedServerChange", function() { + resolveServerStrings(); + $("#serverJoinAlert").hide(); +}) + +// #region Resolve Strings + +function resolveServerStrings() { + const server = getCurrentlyActiveServer(); + + // Server names + $(".resolve-to-server-name").text(server.name); + + // Server Guild Ids + $(".resolve-to-server-id").text(server.guild_id) + + // Bot Invite links + $(".resolve-to-invite-link").attr("href", `https://discord.com/oauth2/authorize +?client_id=1129345991758336020 +&permissions=2147534848 +&scope=bot+applications.commands +&guild_id=${server.guild_id} +&disable_guild_select=true`); + +} + +$("#backToSelectServer").on("click", function() { + +}); + +// #endregion diff --git a/apps/static/js/home/subscriptions.js b/apps/static/js/home/subscriptions.js index 18ea333..7cf2f17 100644 --- a/apps/static/js/home/subscriptions.js +++ b/apps/static/js/home/subscriptions.js @@ -371,19 +371,14 @@ async function loadSubscriptions(guildId) { // #region Server Change Event Handler $(document).on("selectedServerChange", async function() { + let server = getCurrentlyActiveServer(); + guildId = server.guild_id; - // Hide alerts - $("#serverJoinAlert").attr("style", "display: none !important"); + $("#subEmbedColour .colour-reset").attr("data-defaultcolour", "#" + server.default_embed_colour); - updateBotInviteLink(); - - const activeServer = getCurrentlyActiveServer(); - - $("#subEmbedColour .colour-reset").attr("data-defaultcolour", "#" + activeServer.default_embed_colour); - - await loadSubscriptions(activeServer.guild_id); - await loadChannelOptions(activeServer.guild_id); - await loadFilterOptions(activeServer.guild_id); + await loadSubscriptions(guildId); + await loadChannelOptions(guildId); + await loadFilterOptions(guildId); await loadMutatorOptions(); }) @@ -479,7 +474,7 @@ async function loadChannelOptions(guildId) { // Also check that the user hasn't changed the currently active guild, otherwise // the alert will show under the wrong server. if (getCurrentlyActiveServer().guild_id === guildId) - showServerJoinAlert(); + $("#serverJoinAlert").show(); const guildName = getServerFromSnowflake(guildId).name; @@ -587,29 +582,3 @@ async function loadFilterOptions(guildId) { } // #endregion - - -// #region Bot Not in Server Alert -function showServerJoinAlert() { - const guildId = getCurrentlyActiveServer().guild_id; - const inviteUrl = `https://discord.com/oauth2/authorize -?client_id=1129345991758336020 -&permissions=2147534848&scope=bot+applications.commands -&guild_id=${guildId} -&disable_guild_select=true` - - $("#serverJoinAlert a.alert-link").attr("href", inviteUrl); - $("#serverJoinAlert").show(); -} -// #endregion - -function updateBotInviteLink() { - const guildId = getCurrentlyActiveServer().guild_id; - const inviteUrl = `https://discord.com/oauth2/authorize -?client_id=1129345991758336020 -&permissions=2147534848&scope=bot+applications.commands -&guild_id=${guildId} -&disable_guild_select=true` - - $("#invitePyrssToServerBtn").attr("href", inviteUrl); -} diff --git a/apps/templates/home/index.html b/apps/templates/home/index.html index b7c8772..7c6cc10 100644 --- a/apps/templates/home/index.html +++ b/apps/templates/home/index.html @@ -45,29 +45,29 @@
Selected Server Icon
-

-
+

+
- - - - +
-
-