From 212a0f23bc894faf88e159560c113f504349cc05 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Tue, 29 Apr 2025 17:06:23 +0200 Subject: comiles again but still many logic holes --- ui/src/account/settings.rs | 92 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 ui/src/account/settings.rs (limited to 'ui/src/account/settings.rs') diff --git a/ui/src/account/settings.rs b/ui/src/account/settings.rs new file mode 100644 index 0000000..7c5a3b8 --- /dev/null +++ b/ui/src/account/settings.rs @@ -0,0 +1,92 @@ +/* + This file is part of jellything (https://codeberg.org/metamuffin/jellything) + which is licensed under the GNU Affero General Public License (version 3); see /COPYING. + Copyright (C) 2025 metamuffin +*/ +use crate::{ + Page, + locale::{Language, tr, trs}, + scaffold::SessionInfo, +}; +use jellycommon::{ + routes::{u_account_login, u_account_settings}, + user::{PlayerKind, Theme}, +}; +use markup::RenderAttributeValue; + +impl Page for SettingsPage<'_> { + fn title(&self) -> String { + format!("Settings") + } + fn to_render(&self) -> markup::DynRender { + markup::new!(@self) + } +} + +markup::define! { + SettingsPage<'a>(flash: Option>, session: &'a SessionInfo, lang: &'a Language) { + h1 { "Settings" } + @if let Some(flash) = &flash { + @match flash { + Ok(mesg) => { section.message { p.success { @mesg } } } + Err(err) => { section.message { p.error { @format!("{err}") } } } + } + } + h2 { @trs(&lang, "account") } + a.switch_account[href=u_account_login()] { "Switch Account" } + form[method="POST", action=u_account_settings()] { + label[for="username"] { @trs(&lang, "account.username") } + input[type="text", id="username", disabled, value=&session.user.name]; + input[type="submit", disabled, value=&*tr(**lang, "settings.immutable")]; + } + form[method="POST", action=u_account_settings()] { + label[for="display_name"] { @trs(lang, "account.display_name") } + input[type="text", id="display_name", name="display_name", value=&session.user.display_name]; + input[type="submit", value=&*tr(**lang, "settings.update")]; + } + form[method="POST", action=u_account_settings()] { + label[for="password"] { @trs(lang, "account.password") } + input[type="password", id="password", name="password"]; + input[type="submit", value=&*tr(**lang, "settings.update")]; + } + h2 { @trs(&lang, "settings.appearance") } + form[method="POST", action=u_account_settings()] { + fieldset { + legend { @trs(&lang, "settings.appearance.theme") } + @for theme in Theme::ALL { + label { input[type="radio", name="theme", value=A(*theme), checked=session.user.theme==*theme]; @trs(lang, &format!("theme.{theme}")) } br; + } + } + input[type="submit", value=&*tr(**lang, "settings.apply")]; + } + form[method="POST", action=u_account_settings()] { + fieldset { + legend { @trs(&lang, "settings.player_preference") } + @for kind in PlayerKind::ALL { + label { input[type="radio", name="player_preference", value=A(*kind), checked=session.user.player_preference==*kind]; @trs(lang, &format!("player_kind.{kind}")) } br; + } + } + input[type="submit", value=&*tr(**lang, "settings.apply")]; + } + form[method="POST", action=u_account_settings()] { + label[for="native_secret"] { "Native Secret" } + input[type="password", id="native_secret", name="native_secret"]; + input[type="submit", value=&*tr(**lang, "settings.update")]; + p { "The secret can be found in " code{"$XDG_CONFIG_HOME/jellynative_secret"} " or by clicking " a.button[href="jellynative://show-secret-v1"] { "Show Secret" } "." } + } + } +} + +struct A(pub T); +impl markup::Render for A { + fn render(&self, writer: &mut impl std::fmt::Write) -> std::fmt::Result { + writer.write_str(self.0.to_str()) + } +} +impl markup::Render for A { + fn render(&self, writer: &mut impl std::fmt::Write) -> std::fmt::Result { + writer.write_str(self.0.to_str()) + } +} +impl RenderAttributeValue for A {} +impl RenderAttributeValue for A {} -- cgit v1.2.3-70-g09d2