diff --git a/web/src/config.rs b/web/src/config.rs index 9153d38..c14ff59 100644 --- a/web/src/config.rs +++ b/web/src/config.rs @@ -10,6 +10,9 @@ pub struct Config { #[serde_inline_default(true)] pub loop_videos: bool, + + #[serde_inline_default("#BF616A".to_string())] + pub accent_color: String, } #[serde_inline_default::serde_inline_default] diff --git a/web/src/lib.rs b/web/src/lib.rs index b869bab..8ce2d30 100644 --- a/web/src/lib.rs +++ b/web/src/lib.rs @@ -15,6 +15,7 @@ pub const URL_PREFIX: &str = "/web"; pub const URL_SENSITIVE: &str = "https://cdn.alemi.dev/social/nsfw.png"; pub const DEFAULT_AVATAR_URL: &str = "https://cdn.alemi.dev/social/gradient.png"; pub const NAME: &str = "μ"; +pub const DEFAULT_COLOR: &str = "#BF616A"; use std::sync::Arc; use uriproxy::UriClass; diff --git a/web/src/page/config.rs b/web/src/page/config.rs index c7f92ba..4a06fa2 100644 --- a/web/src/page/config.rs +++ b/web/src/page/config.rs @@ -1,9 +1,15 @@ use leptos::*; -use crate::prelude::*; +use crate::{prelude::*, DEFAULT_COLOR}; #[component] pub fn ConfigPage(setter: WriteSignal) -> impl IntoView { let config = use_context::>().expect("missing config context"); + let (color, set_color) = leptos_use::use_css_var("--accent"); + let (_color_rgb, set_color_rgb) = leptos_use::use_css_var("--accent-rgb"); + + let previous_color = config.get().accent_color; + set_color_rgb.set(parse_hex(&previous_color)); + set_color.set(previous_color); macro_rules! get_cfg { (filter $field:ident) => { @@ -51,6 +57,22 @@ pub fn ConfigPage(setter: WriteSignal) -> impl IntoView { /> collapse content warnings

+

+ accent color + +


filters

    @@ -65,3 +87,11 @@ pub fn ConfigPage(setter: WriteSignal) -> impl IntoView { } } + +fn parse_hex(hex: &str) -> String { + if hex.len() < 7 { return "0, 0, 0".into(); } + let r = i64::from_str_radix(&hex[1..3], 16).unwrap_or_default(); + let g = i64::from_str_radix(&hex[3..5], 16).unwrap_or_default(); + let b = i64::from_str_radix(&hex[5..7], 16).unwrap_or_default(); + format!("{r}, {g}, {b}") +}