From abfe4921925bb467a9fbc5e2bda9bde12f796fea Mon Sep 17 00:00:00 2001 From: jude Date: Thu, 24 Mar 2022 21:36:22 +0000 Subject: [PATCH] put a plain background on images --- web/src/routes/dashboard/guild.rs | 18 +- web/static/img/bg.webp | Bin 0 -> 762 bytes web/static/js/main.js | 177 ++++++++++++------ web/templates/dashboard.html.tera | 2 +- .../guild_reminder.html.tera | 12 +- 5 files changed, 136 insertions(+), 73 deletions(-) create mode 100644 web/static/img/bg.webp diff --git a/web/src/routes/dashboard/guild.rs b/web/src/routes/dashboard/guild.rs index a610172..fb5c712 100644 --- a/web/src/routes/dashboard/guild.rs +++ b/web/src/routes/dashboard/guild.rs @@ -41,14 +41,15 @@ pub async fn get_guild_channels( ) -> JsonValue { check_authorization!(cookies, ctx.inner(), id); - let channels_res = GuildId(id).channels(ctx.inner()).await; - - match channels_res { - Ok(channels) => { + match GuildId(id).to_guild_cached(ctx.inner()) { + Some(guild) => { let mut channel_info = vec![]; - for (channel_id, channel) in - channels.iter().filter(|(_, channel)| channel.is_text_based()) + for (channel_id, channel) in guild + .channels + .iter() + .filter_map(|(id, channel)| channel.to_owned().guild().map(|c| (id, c))) + .filter(|(_, channel)| channel.is_text_based()) { let mut ch = ChannelInfo { name: channel.name.to_string(), @@ -85,10 +86,9 @@ pub async fn get_guild_channels( json!(channel_info) } - Err(e) => { - warn!("Could not fetch channels from {}: {:?}", id, e); - json!({"error": "Could not get channels"}) + None => { + json!({"error": "Bot not in guild"}) } } } diff --git a/web/static/img/bg.webp b/web/static/img/bg.webp new file mode 100644 index 0000000000000000000000000000000000000000..e2e28fed57baaa9219fb9340125a8909d7af8f8e GIT binary patch literal 762 zcmaKqPe>GT6vsb1yJ5(hhqh3O7-8!m3aJsEB6mw!Fc>z=H9Isj>#oAixXi40@!&xa z^dfZV4@8?0T{=b7wL{m!2(+L)dg^3U2hr*MW~24s`h(y6K78N%zWKd3lg$hb?PxG| zEoIy?26D}SF1r^_Kqj3wsuBgQTCyEKb^#o>;$??ZdT#u--n31WHcrt_+_e4jpka)t z?8DdZ4I(P?xkuGHJg1@BlArW#i0G1W#V≷k&|@<|<{y4}=r;l$jTPDctSJ1%m7xpn_c6$XBZzFOCkPoQ-X-n_4C z)_r)p1Z`i-re}uliON$e6kz8Cw2Z^ab!eWb%}rt|&a+Jzm068^fQOIZd{JuOY0&p^ zG5nv~kvae7Cx5QqEv9vi$C0i+TDjbNdO5w;*_nu;M`N!SIQvO%wZHxG`>VO<{9 literal 0 HcmV?d00001 diff --git a/web/static/js/main.js b/web/static/js/main.js index 2bb5778..8ed6166 100644 --- a/web/static/js/main.js +++ b/web/static/js/main.js @@ -7,6 +7,7 @@ const $deleteReminderBtn = document.querySelector("#delete-reminder-confirm"); let channels; let roles; +let guild_id; function colorToInt(r, g, b) { return (r << 16) + (g << 8) + b; @@ -75,6 +76,29 @@ function fetch_roles(guild_id) { }); } +async function fetch_channels(guild_id) { + const event = new Event("channelsLoading"); + document.dispatchEvent(event); + + await fetch(`/dashboard/api/guild/${guild_id}/channels`) + .then((response) => response.json()) + .then((data) => { + if (data.error) { + if (data.error === "Bot not in guild") { + switch_pane("guild-error"); + } else { + show_error(data.error); + } + } else { + channels = data; + } + }) + .then(() => { + const event = new Event("channelsLoaded"); + document.dispatchEvent(event); + }); +} + async function fetch_reminders(guild_id) { document.dispatchEvent(new Event("remindersLoading")); @@ -84,7 +108,7 @@ async function fetch_reminders(guild_id) { $reminderBox.innerHTML = ""; // fetch reminders - await fetch(`dashboard/api/guild/${guild_id}/reminders`) + await fetch(`/dashboard/api/guild/${guild_id}/reminders`) .then((response) => response.json()) .then((data) => { if (data.error) { @@ -140,6 +164,40 @@ async function fetch_reminders(guild_id) { }); } +document.addEventListener("guildSwitched", async (e) => { + $loader.classList.remove("is-hidden"); + + let $anchor = document.querySelector( + `.switch-pane[data-guild="${e.detail.guild_id}"]` + ); + + switch_pane($anchor.dataset["pane"]); + $anchor.classList.add("is-active"); + + reset_guild_pane(); + + fetch_roles(e.detail.guild_id); + await fetch_channels(e.detail.guild_id); + fetch_reminders(e.detail.guild_id); + + document.querySelectorAll("p.pageTitle").forEach((el) => { + el.textContent = `${e.detail.guild_name} Reminders`; + }); + document.querySelectorAll("select.channel-selector").forEach((el) => { + el.addEventListener("change", (e) => { + update_select(e.target); + }); + }); + + resize_textareas(); + + $loader.classList.add("is-hidden"); +}); + +document.addEventListener("channelsLoaded", () => { + document.querySelectorAll("select.channel-selector").forEach(set_channels); +}); + document.addEventListener("remindersLoaded", (event) => { const guild = document.querySelector(".guildList a.is-active").dataset["guild"]; @@ -180,7 +238,13 @@ document.addEventListener("remindersLoaded", (event) => { $deleteReminderBtn.closest(".modal").classList.toggle("is-active"); }); - node.querySelector("button.save-btn").addEventListener("click", (event) => { + const $saveBtn = node.querySelector("button.save-btn"); + + $saveBtn.addEventListener("click", (event) => { + $saveBtn.querySelector("span.icon > i").classList = [ + "fas fa-spinner fa-spin", + ]; + let seconds = parseInt(node.querySelector('input[name="interval_seconds"]').value) || null; @@ -200,19 +264,27 @@ document.addEventListener("remindersLoaded", (event) => { let reminder = { uid: node.closest(".reminderContent").dataset["uid"], - avatar: node.querySelector("img.discord-avatar").src, + avatar: has_source(node.querySelector("img.discord-avatar").src), channel: node.querySelector("select.channel-selector").value, content: node.querySelector('textarea[name="content"]').value, - embed_author_url: node.querySelector("img.embed_author_url").src, + embed_author_url: has_source( + node.querySelector("img.embed_author_url").src + ), embed_author: node.querySelector('textarea[name="embed_author"]').value, embed_color: color, embed_description: node.querySelector( 'textarea[name="embed_description"]' ).value, embed_footer: node.querySelector('textarea[name="embed_footer"]').value, - embed_footer_url: node.querySelector("img.embed_footer_url").src, - embed_image_url: node.querySelector("img.embed_image_url").src, - embed_thumbnail_url: node.querySelector("img.embed_thumbnail_url").src, + embed_footer_url: has_source( + node.querySelector("img.embed_footer_url").src + ), + embed_image_url: has_source( + node.querySelector("img.embed_image_url").src + ), + embed_thumbnail_url: has_source( + node.querySelector("img.embed_thumbnail_url").src + ), embed_title: node.querySelector('textarea[name="embed_title"]').value, expires: null, interval_seconds: seconds, @@ -236,6 +308,12 @@ document.addEventListener("remindersLoaded", (event) => { }) .then((response) => response.json()) .then((data) => console.log(data)); + + $saveBtn.querySelector("span.icon > i").classList = ["fas fa-check"]; + + window.setTimeout(() => { + $saveBtn.querySelector("span.icon > i").classList = ["fas fa-save"]; + }, 1500); }); } }); @@ -314,7 +392,7 @@ document.addEventListener("DOMContentLoaded", () => { show_error(data.error); } else { document.querySelectorAll("a.switch-pane").forEach((element) => { - element.innerHTML = element.innerHTML.replace( + element.textContent = element.textContent.replace( "%username%", data.name ); @@ -353,59 +431,28 @@ document.addEventListener("DOMContentLoaded", () => { const $clone = $template.content.cloneNode(true); const $anchor = $clone.querySelector("a"); - $anchor.innerHTML = $clone - .querySelector("a") - .innerHTML.replace("%guildname%", guild.name); + let $span = $clone.querySelector("a > span.guild-name"); + + $span.textContent = $span.textContent.replace( + "%guildname%", + guild.name + ); $anchor.dataset["guild"] = guild.id; $anchor.dataset["name"] = guild.name; $anchor.addEventListener("click", async (e) => { e.preventDefault(); - $loader.classList.remove("is-hidden"); + guild_id = guild.id; - switch_pane($anchor.dataset["pane"]); - - reset_guild_pane(); - - fetch_roles($anchor.dataset["guild"]); - - await fetch( - `/dashboard/api/guild/${$anchor.dataset["guild"]}/channels` - ) - .then((response) => response.json()) - .then((data) => { - if (data.error) { - if (data.error === "Bot not in guild") { - switch_pane("guild-error"); - } else { - show_error(data.error); - } - } else { - channels = data; - - document - .querySelectorAll("select.channel-selector") - .forEach(set_channels); - } - }); - - fetch_reminders($anchor.dataset["guild"]); - - document.querySelectorAll("p.pageTitle").forEach((el) => { - el.textContent = $anchor.dataset["name"] + " Reminders"; + const event = new CustomEvent("guildSwitched", { + detail: { + guild_name: guild.name, + guild_id: guild.id, + }, }); - document - .querySelectorAll("select.channel-selector") - .forEach((el) => { - el.addEventListener("change", (e) => { - update_select(e.target); - }); - }); - $anchor.classList.add("is-active"); - resize_textareas(); - $loader.classList.add("is-hidden"); + document.dispatchEvent(event); }); element.append($clone); @@ -436,6 +483,14 @@ function set_channels(element) { update_select(element); } +function has_source(string) { + if (string.startsWith(`https://${window.location.hostname}`)) { + return null; + } else { + return string; + } +} + let $createReminder = document.querySelector("#reminderCreator"); $createReminder.querySelector("button#createReminder").addEventListener("click", () => { @@ -458,18 +513,26 @@ $createReminder.querySelector("button#createReminder").addEventListener("click", ).setZone("UTC"); let reminder = { - avatar: $createReminder.querySelector("img.discord-avatar").src, + avatar: has_source($createReminder.querySelector("img.discord-avatar").src), channel: $createReminder.querySelector("select.channel-selector").value, content: $createReminder.querySelector("textarea#messageContent").value, - embed_author_url: $createReminder.querySelector("img.embed_author_url").src, + embed_author_url: has_source( + $createReminder.querySelector("img.embed_author_url").src + ), embed_author: $createReminder.querySelector("textarea#embedAuthor").value, embed_color: color, embed_description: $createReminder.querySelector("textarea#embedDescription") .value, embed_footer: $createReminder.querySelector("textarea#embedFooter").value, - embed_footer_url: $createReminder.querySelector("img.embed_footer_url").src, - embed_image_url: $createReminder.querySelector("img.embed_image_url").src, - embed_thumbnail_url: $createReminder.querySelector("img.embed_thumbnail_url").src, + embed_footer_url: has_source( + $createReminder.querySelector("img.embed_footer_url").src + ), + embed_image_url: has_source( + $createReminder.querySelector("img.embed_image_url").src + ), + embed_thumbnail_url: has_source( + $createReminder.querySelector("img.embed_thumbnail_url").src + ), embed_title: $createReminder.querySelector("textarea#embedTitle").value, enabled: true, expires: null, diff --git a/web/templates/dashboard.html.tera b/web/templates/dashboard.html.tera index 65b7723..116b78f 100644 --- a/web/templates/dashboard.html.tera +++ b/web/templates/dashboard.html.tera @@ -308,7 +308,7 @@ diff --git a/web/templates/reminder_dashboard/guild_reminder.html.tera b/web/templates/reminder_dashboard/guild_reminder.html.tera index 56c27d1..644ab85 100644 --- a/web/templates/reminder_dashboard/guild_reminder.html.tera +++ b/web/templates/reminder_dashboard/guild_reminder.html.tera @@ -4,7 +4,7 @@

- +

@@ -30,7 +30,7 @@ @@ -79,7 +79,7 @@ @@ -87,14 +87,14 @@

- Large embedded image + Large embedded image