add: block list stacks

This commit is contained in:
trisua 2025-06-15 11:52:44 -04:00
parent 9bb5f38f76
commit b71ae1f5a4
28 changed files with 700 additions and 219 deletions

View file

@ -80,6 +80,19 @@ pub async fn settings_request(
Err(e) => return Err(Html(render_error(e, &jar, &data, &None).await)),
};
let stackblocks = {
let mut out = Vec::new();
for block in data.0.get_stackblocks_by_initiator(profile.id).await {
out.push(match data.0.get_stack_by_id(block.stack).await {
Ok(s) => s,
Err(_) => continue,
});
}
out
};
let uploads = match data.0.get_uploads_by_owner(profile.id, 12, req.page).await {
Ok(ua) => ua,
Err(e) => {
@ -98,6 +111,7 @@ pub async fn settings_request(
context.insert("stacks", &stacks);
context.insert("following", &following);
context.insert("blocks", &blocks);
context.insert("stackblocks", &stackblocks);
context.insert(
"user_tokens_serde",
&serde_json::to_string(&tokens)
@ -128,59 +142,37 @@ pub async fn settings_request(
)
.unwrap();
let light = serde_json::Value::from("Light");
let mut profile_theme = settings_map
.get("profile_theme")
.unwrap_or(&light)
.as_str()
.unwrap();
if let Some(color_surface) = settings_map.get("theme_color_surface") {
let color_surface = color_surface.as_str().unwrap();
for setting in &settings_map {
if !setting.0.starts_with("theme_color_text")
| (setting.0 == "theme_color_text_primary")
| (setting.0 == "theme_color_text_secondary")
{
continue;
}
if profile_theme.is_empty() | (profile_theme == "Auto") {
profile_theme = "Light";
}
let value = setting.1.as_str().unwrap();
let default_surface = serde_json::Value::from(if profile_theme == "Light" {
"#f3f2f1"
if !value.starts_with("#") {
// we can only parse hex right now
continue;
}
let c1 = Color::from(color_surface);
let c2 = Color::from(value);
let contrast = c1.contrast(&c2);
if contrast < MINIMUM_CONTRAST_THRESHOLD {
failing_color_keys.push((setting.0, contrast));
}
}
context.insert("failing_color_keys", &failing_color_keys);
} else {
"#19171c"
});
let mut color_surface = settings_map
.get("theme_color_surface")
.unwrap_or(&default_surface)
.as_str()
.unwrap();
if color_surface.is_empty() {
color_surface = default_surface.as_str().unwrap();
context.insert("failing_color_keys", &Vec::<&str>::new());
}
for setting in &settings_map {
if !setting.0.starts_with("theme_color_text")
| (setting.0 == "theme_color_text_primary")
| (setting.0 == "theme_color_text_secondary")
{
continue;
}
let value = setting.1.as_str().unwrap();
if !value.starts_with("#") {
// we can only parse hex right now
continue;
}
let c1 = Color::from(color_surface);
let c2 = Color::from(value);
let contrast = c1.contrast(&c2);
if contrast < MINIMUM_CONTRAST_THRESHOLD {
failing_color_keys.push((setting.0, contrast));
}
}
context.insert("failing_color_keys", &failing_color_keys);
// return
Ok(Html(
data.1.render("profile/settings.html", &context).unwrap(),