diff options
author | metamuffin <metamuffin@disroot.org> | 2023-10-25 12:20:58 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2023-10-25 12:20:58 +0200 |
commit | 5aa2a6fa5a6f8daf3ed4d86082658027a44f83c8 (patch) | |
tree | d6c3c9226dd533eb6a25de63790f78f3524acd00 /server/src/routes | |
parent | f4f3a16bca576c202887799066bd896863612e2b (diff) | |
download | jellything-5aa2a6fa5a6f8daf3ed4d86082658027a44f83c8.tar jellything-5aa2a6fa5a6f8daf3ed4d86082658027a44f83c8.tar.bz2 jellything-5aa2a6fa5a6f8daf3ed4d86082658027a44f83c8.tar.zst |
theme setting
Diffstat (limited to 'server/src/routes')
-rw-r--r-- | server/src/routes/ui/account/settings.rs | 31 |
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 { |