aboutsummaryrefslogtreecommitdiff
path: root/server/src/routes/ui/account
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/routes/ui/account')
-rw-r--r--server/src/routes/ui/account/settings.rs31
1 files changed, 25 insertions, 6 deletions
diff --git a/server/src/routes/ui/account/settings.rs b/server/src/routes/ui/account/settings.rs
index d61d9f1..6a9a50e 100644
--- a/server/src/routes/ui/account/settings.rs
+++ b/server/src/routes/ui/account/settings.rs
@@ -13,9 +13,12 @@ use crate::{
},
uri,
};
+use jellycommon::user::Theme;
use rocket::{
form::{self, validate::len, Contextual, Form},
- get, post, FromForm, State,
+ get,
+ http::uri::fmt::{Query, UriDisplay},
+ post, FromForm, State,
};
use std::ops::Range;
@@ -25,6 +28,7 @@ pub struct SettingsForm {
password: Option<String>,
#[field(validate = option_len(4..32))]
display_name: Option<String>,
+ theme: Option<Theme>,
}
fn option_len<'v>(value: &Option<String>, range: Range<usize>) -> form::Result<'v, ()> {
@@ -59,16 +63,27 @@ fn settings_page(session: Session, flash: Option<MyResult<String>>) -> DynLayout
input[type="submit", value="Update"];
}
h2 { "Appearance" }
- fieldset {
- legend { "Theme" }
- // label { input[type="radio", name="theme", value=t, checked=session.user.theme==t]; @label } br;
- // label { input[type="radio", name="theme", value=t, checked=session.user.theme==t]; @label } br;
+ form[method="POST", action=uri!(r_account_settings_post())] {
+ fieldset {
+ legend { "Theme" }
+ @for (t, tlabel) in [(Theme::Dark, "Dark theme"), (Theme::Light, "Light theme")] {
+ label { input[type="radio", name="theme", value=A(t), checked=session.user.theme==t]; @tlabel } br;
+ }
+ }
+ input[type="submit", value="Apply"];
}
},
..Default::default()
}
}
+struct A(pub Theme);
+impl markup::Render for A {
+ fn render(&self, writer: &mut impl std::fmt::Write) -> std::fmt::Result {
+ writer.write_fmt(format_args!("{}", &self.0 as &dyn UriDisplay<Query>))
+ }
+}
+
#[get("/account/settings")]
pub fn r_account_settings(session: Session) -> DynLayoutPage<'static> {
settings_page(session, None)
@@ -96,12 +111,16 @@ pub fn r_account_settings_post(
k.display_name = display_name.clone();
out += "Display name updated\n";
}
+ if let Some(theme) = form.theme {
+ k.theme = theme;
+ out += "Theme updated\n";
+ }
k
})
})?;
Ok(settings_page(
- session,
+ session, // using the old session here, results in outdated theme being displayed
Some(Ok(if out.is_empty() {
"Nothing changed :)".to_string()
} else {