1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
/*
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 <metamuffin.org>
*/
use crate::locale::{Language, tr, trs};
use jellycommon::user::{PlayerKind, Theme};
use markup::RenderAttributeValue;
markup::define! {
Settings<'a>(flash: Option<Result<String, String>>, 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=uri!(r_account_login())] { "Switch Account" }
form[method="POST", action=uri!(r_account_settings_post())] {
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=uri!(r_account_settings_post())] {
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=uri!(r_account_settings_post())] {
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=uri!(r_account_settings_post())] {
fieldset {
legend { @trs(&lang, "settings.appearance.theme") }
@for (t, tlabel) in Theme::LIST {
label { input[type="radio", name="theme", value=A(*t), checked=session.user.theme==*t]; @tlabel } br;
}
}
input[type="submit", value=&*tr(**lang, "settings.apply")];
}
form[method="POST", action=uri!(r_account_settings_post())] {
fieldset {
legend { @trs(&lang, "settings.player_preference") }
@for (t, tlabel) in PlayerKind::LIST {
label { input[type="radio", name="player_preference", value=A(*t), checked=session.user.player_preference==*t]; @tlabel } br;
}
}
input[type="submit", value=&*tr(**lang, "settings.apply")];
}
form[method="POST", action=uri!(r_account_settings_post())] {
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<T>(pub T);
impl markup::Render for A<Theme> {
fn render(&self, writer: &mut impl std::fmt::Write) -> std::fmt::Result {
writer.write_fmt(format_args!("{}", self as &dyn UriDisplay<Query>))
}
}
impl markup::Render for A<PlayerKind> {
fn render(&self, writer: &mut impl std::fmt::Write) -> std::fmt::Result {
writer.write_fmt(format_args!("{}", self as &dyn UriDisplay<Query>))
}
}
impl RenderAttributeValue for A<Theme> {}
impl RenderAttributeValue for A<PlayerKind> {}
|