From 79e6498245228c0c0cce2f5237ef8feb5de2df3c Mon Sep 17 00:00:00 2001 From: jude Date: Sat, 24 Feb 2024 17:23:31 +0000 Subject: [PATCH] Add overlay when data fetching --- .gitignore | 3 +- Cargo.lock | 2 +- Cargo.toml | 2 +- reminder-dashboard/README.md | 14 +- .../src/components/Guild/GuildReminders.tsx | 4 +- web/src/macros.rs | 12 + web/src/routes/dashboard/mod.rs | 53 +++-- web/static/assets | 2 +- web/static/css/style.css | 11 +- web/static/index.html | 1 - web/templates/base.html.tera | 206 +++++++++--------- web/templates/errors/403.html.tera | 2 +- web/templates/errors/404.html.tera | 2 +- 13 files changed, 168 insertions(+), 146 deletions(-) delete mode 120000 web/static/index.html diff --git a/.gitignore b/.gitignore index 5e707fe..489c7e2 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,7 @@ target .env /venv .cargo -/.idea +.idea web/static/index.html web/static/assets # Logs @@ -22,7 +22,6 @@ dist-ssr # Editor directories and files .vscode/* !.vscode/extensions.json -.idea .DS_Store *.suo *.ntvs* diff --git a/Cargo.lock b/Cargo.lock index 2968dff..efeadd9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2358,7 +2358,7 @@ checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" [[package]] name = "reminder-rs" -version = "1.7.0-rc1" +version = "1.7.0-rc2" dependencies = [ "base64 0.21.7", "chrono", diff --git a/Cargo.toml b/Cargo.toml index 5ff7214..964682c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "reminder-rs" -version = "1.7.0-rc1" +version = "1.7.0-rc2" authors = ["Jude Southworth "] edition = "2021" license = "AGPL-3.0 only" diff --git a/reminder-dashboard/README.md b/reminder-dashboard/README.md index e6dc91e..c90785f 100644 --- a/reminder-dashboard/README.md +++ b/reminder-dashboard/README.md @@ -4,16 +4,16 @@ The re-re-rewrite of the dashboard. ## Why -The existing beta variant of the dashboard is written using vanilla JavaScript. This is fine, -but annoying to update. This would've been okay if I was more dedicated to updating the vanilla +The existing beta variant of the dashboard is written using vanilla JavaScript. This is fine, +but annoying to update. This would've been okay if I was more dedicated to updating the vanilla JavaScript too, but I want to experiment with "new" things. This also allows me to expand my frontend skills, which is relevant to part of my job. ## Developing -1. Download the parent repo: https://gitea.jellypro.xyz/jude/reminder-bot -2. Initialise the submodules: `git pull --recurse-submodules` -3. Run both `npm run dev` and `cargo run` -4. Symlink assets: assuming cloned into `$HOME`, `ln -s $HOME/reminder-bot/reminder-dashboard/dist/index.html $HOME/reminder-bot/web/static/index.html` and -`ln -s $HOME/reminder-bot/reminder-dashboard/dist/static/assets $HOME/reminder-bot/web/static/assets` \ No newline at end of file +1. Run both `npm run dev` and `cargo run` +2. Symlink assets: assuming cloned + into `$HOME`, `ln -s $HOME/reminder-bot/reminder-dashboard/dist/index.html $HOME/reminder-bot/web/static/index.html` + and + `ln -s $HOME/reminder-bot/reminder-dashboard/dist/static/assets $HOME/reminder-bot/web/static/assets` diff --git a/reminder-dashboard/src/components/Guild/GuildReminders.tsx b/reminder-dashboard/src/components/Guild/GuildReminders.tsx index ba0e9b6..f67dfe6 100644 --- a/reminder-dashboard/src/components/Guild/GuildReminders.tsx +++ b/reminder-dashboard/src/components/Guild/GuildReminders.tsx @@ -14,7 +14,7 @@ enum Sort { export const GuildReminders = () => { const { guild } = useParams(); - const { isSuccess, data: guildReminders } = useQuery(fetchGuildReminders(guild)); + const { isSuccess, isFetching, data: guildReminders } = useQuery(fetchGuildReminders(guild)); const { data: channels } = useQuery(fetchGuildChannels(guild)); const [collapsed, setCollapsed] = useState(false); @@ -85,7 +85,7 @@ export const GuildReminders = () => { -
+
{isSuccess && guildReminders .sort((r1, r2) => { diff --git a/web/src/macros.rs b/web/src/macros.rs index 8c91f30..eff787f 100644 --- a/web/src/macros.rs +++ b/web/src/macros.rs @@ -97,3 +97,15 @@ macro_rules! json_err { Err(json!({ "error": $message })) }; } + +macro_rules! path { + ($path:expr) => {{ + use rocket::fs::relative; + + if Path::new(concat!("/lib/reminder-rs/", $path)).exists() { + concat!("/lib/reminder-rs/", $path) + } else { + relative!($path) + } + }}; +} diff --git a/web/src/routes/dashboard/mod.rs b/web/src/routes/dashboard/mod.rs index 40e474a..e9c1055 100644 --- a/web/src/routes/dashboard/mod.rs +++ b/web/src/routes/dashboard/mod.rs @@ -2,12 +2,8 @@ use std::path::Path; use chrono::{naive::NaiveDateTime, Utc}; use rand::{rngs::OsRng, seq::IteratorRandom}; -use rocket::{ - fs::{relative, NamedFile}, - http::CookieJar, - response::Redirect, - serde::json::json, -}; +use rocket::{fs::NamedFile, http::CookieJar, response::Redirect, serde::json::json}; +use rocket_dyn_templates::Template; use secrecy::ExposeSecret; use serde::{de, Deserialize, Deserializer, Serialize, Serializer}; use serenity::{ @@ -19,6 +15,7 @@ use serenity::{ use sqlx::types::Json; use crate::{ + catchers::internal_server_error, check_guild_subscription, check_subscription, consts::{ CHARACTERS, DAY, DEFAULT_AVATAR, MAX_CONTENT_LENGTH, MAX_EMBED_AUTHOR_LENGTH, @@ -672,28 +669,44 @@ async fn create_database_channel( Ok(row.id) } -#[get("/")] -pub async fn dashboard_home(cookies: &CookieJar<'_>) -> Result { - if cookies.get_private("userid").is_some() { - NamedFile::open(Path::new(relative!("static/index.html"))).await.map_err(|e| { - warn!("Couldn't render dashboard: {:?}", e); +#[derive(Responder)] +pub enum DashboardPage { + #[response(status = 200)] + Ok(NamedFile), + #[response(status = 200)] + Unauthorised(Redirect), + #[response(status = 500)] + NotConfigured(Template), +} - Redirect::to("/login/discord") - }) +#[get("/")] +pub async fn dashboard_home(cookies: &CookieJar<'_>) -> DashboardPage { + if cookies.get_private("userid").is_some() { + match NamedFile::open(Path::new(path!("static/index.html"))).await { + Ok(f) => DashboardPage::Ok(f), + Err(e) => { + warn!("Couldn't render dashboard: {:?}", e); + + DashboardPage::NotConfigured(internal_server_error().await) + } + } } else { - Err(Redirect::to("/login/discord")) + DashboardPage::Unauthorised(Redirect::to("/login/discord")) } } #[get("/<_..>")] -pub async fn dashboard(cookies: &CookieJar<'_>) -> Result { +pub async fn dashboard(cookies: &CookieJar<'_>) -> DashboardPage { if cookies.get_private("userid").is_some() { - NamedFile::open(Path::new(relative!("static/index.html"))).await.map_err(|e| { - warn!("Couldn't render dashboard: {:?}", e); + match NamedFile::open(Path::new(path!("static/index.html"))).await { + Ok(f) => DashboardPage::Ok(f), + Err(e) => { + warn!("Couldn't render dashboard: {:?}", e); - Redirect::to("/login/discord") - }) + DashboardPage::NotConfigured(internal_server_error().await) + } + } } else { - Err(Redirect::to("/login/discord")) + DashboardPage::Unauthorised(Redirect::to("/login/discord")) } } diff --git a/web/static/assets b/web/static/assets index 73e7fa6..28d98b0 120000 --- a/web/static/assets +++ b/web/static/assets @@ -1 +1 @@ -/home/jude/reminder-dashboard/dist/static/assets \ No newline at end of file +/home/jude/reminder-bot/reminder-dashboard/dist/static/assets \ No newline at end of file diff --git a/web/static/css/style.css b/web/static/css/style.css index ecaacfc..71d329d 100644 --- a/web/static/css/style.css +++ b/web/static/css/style.css @@ -55,6 +55,7 @@ div.reminderContent.is-collapsed .hide-box { div.reminderContent.is-collapsed .hide-box i { transform: rotate(90deg); } + /* END */ /* dashboard styles */ @@ -202,6 +203,7 @@ div.interval-group { flex-direction: row; justify-content: space-between; } + /* !Interval inputs */ .left-pad { @@ -239,7 +241,7 @@ span.spacer { } nav .dashboard-button { - background: white ; + background: white; } span.patreon-color { @@ -694,7 +696,7 @@ li.highlight { } } -/* loader */ +/* loaders */ #loader { position: fixed; top: 0; @@ -707,6 +709,11 @@ li.highlight { font-size: 6rem; } +.loading { + opacity: 0.2; + pointer-events: none; +} + /* END */ div.reminderError { diff --git a/web/static/index.html b/web/static/index.html deleted file mode 120000 index d8876b2..0000000 --- a/web/static/index.html +++ /dev/null @@ -1 +0,0 @@ -/home/jude/reminder-dashboard/dist/index.html \ No newline at end of file diff --git a/web/templates/base.html.tera b/web/templates/base.html.tera index 2ddb8d6..319ee07 100644 --- a/web/templates/base.html.tera +++ b/web/templates/base.html.tera @@ -32,27 +32,54 @@
{% endif %} - - - {% if not hide_title_block %} -
-
-
-

{{ page_title }}

-

{{ page_subtitle }} - {% if page_emoji %} - - {% endif %} -

+ {% if not hide_title_block %} +
+
+
+

{{ page_title }}

+

{{ page_subtitle }} + {% if page_emoji %} + + {% endif %} +

+
-
- {% if show_invite %} - - {% elif show_contact %} - - {% elif show_login %} - - {% endif %} -
+ {% if show_invite %} + + {% elif show_contact %} + + {% elif show_login %} + + {% endif %} + - - - - - - {% endif %} + + + + + + {% endif %} - {% block content %} - {% endblock %} + {% block content %} + {% endblock %} +