add: ability to set home to stack

This commit is contained in:
trisua 2025-05-09 16:23:40 -04:00
parent 870289a5bb
commit 5df0ea6152
4 changed files with 31 additions and 13 deletions

View file

@ -362,11 +362,11 @@ pub(crate) async fn initial_context(
"is_supporter", "is_supporter",
&ua.permissions.check(FinePermission::SUPPORTER), &ua.permissions.check(FinePermission::SUPPORTER),
); );
ctx.insert("home", ua.settings.default_timeline.relative_url()); ctx.insert("home", &ua.settings.default_timeline.relative_url());
} else { } else {
ctx.insert("is_helper", &false); ctx.insert("is_helper", &false);
ctx.insert("is_manager", &false); ctx.insert("is_manager", &false);
ctx.insert("home", DefaultTimelineChoice::default().relative_url()); ctx.insert("home", &DefaultTimelineChoice::default().relative_url());
} }
ctx.insert("lang", &lang.data); ctx.insert("lang", &lang.data);

View file

@ -76,7 +76,7 @@
<div class="card"> <div class="card">
<select <select
onchange="set_setting_field('default_timeline', event.target.selectedOptions[0].value)" onchange="set_setting_field('default_timeline', event.target.selectedOptions[0].value.startsWith('{') ? JSON.parse(event.target.selectedOptions[0].value) : event.target.selectedOptions[0].value)"
> >
<option <option
value="MyCommunities" value="MyCommunities"
@ -129,6 +129,14 @@
> >
All (questions) All (questions)
</option> </option>
{% for stack in stacks %}
<option
value='{"Stack":"{{ stack.id }}"}'
selected="{% if home is ending_with(stack.id|as_str) %}true{% else %}false{% endif %}"
>
{{ stack.name }} (stack)
</option>
{% endfor %}
</select> </select>
<span class="fade" <span class="fade"

View file

@ -11,7 +11,7 @@ use axum::{
use axum_extra::extract::CookieJar; use axum_extra::extract::CookieJar;
use serde::Deserialize; use serde::Deserialize;
use tera::Context; use tera::Context;
use tetratto_core::model::{Error, auth::User, communities::Community, permissions::FinePermission}; use tetratto_core::model::{auth::User, communities::Community, permissions::FinePermission, Error};
use tetratto_shared::hash::hash; use tetratto_shared::hash::hash;
use contrasted::{Color, MINIMUM_CONTRAST_THRESHOLD}; use contrasted::{Color, MINIMUM_CONTRAST_THRESHOLD};
@ -49,12 +49,20 @@ pub async fn settings_request(
} }
}; };
let stacks = match data.0.get_stacks_by_owner(profile.id).await {
Ok(ua) => ua,
Err(e) => {
return Err(Html(render_error(e, &jar, &data, &None).await));
}
};
let tokens = profile.tokens.clone(); let tokens = profile.tokens.clone();
let lang = get_lang!(jar, data.0); let lang = get_lang!(jar, data.0);
let mut context = initial_context(&data.0.0, lang, &Some(user)).await; let mut context = initial_context(&data.0.0, lang, &Some(user)).await;
context.insert("profile", &profile); context.insert("profile", &profile);
context.insert("stacks", &stacks);
context.insert("user_settings_serde", &clean_settings(&profile.settings)); context.insert("user_settings_serde", &clean_settings(&profile.settings));
context.insert( context.insert(
"user_tokens_serde", "user_tokens_serde",

View file

@ -71,6 +71,7 @@ pub enum DefaultTimelineChoice {
FollowingQuestions, FollowingQuestions,
AllPosts, AllPosts,
AllQuestions, AllQuestions,
Stack(String),
} }
impl Default for DefaultTimelineChoice { impl Default for DefaultTimelineChoice {
@ -81,16 +82,17 @@ impl Default for DefaultTimelineChoice {
impl DefaultTimelineChoice { impl DefaultTimelineChoice {
/// Get the relative URL that the timeline should bring you to. /// Get the relative URL that the timeline should bring you to.
pub fn relative_url(&self) -> &str { pub fn relative_url(&self) -> String {
match &self { match &self {
Self::MyCommunities => "/", Self::MyCommunities => "/".to_string(),
Self::MyCommunitiesQuestions => "/questions", Self::MyCommunitiesQuestions => "/questions".to_string(),
Self::PopularPosts => "/popular", Self::PopularPosts => "/popular".to_string(),
Self::PopularQuestions => "/popular/questions", Self::PopularQuestions => "/popular/questions".to_string(),
Self::FollowingPosts => "/following", Self::FollowingPosts => "/following".to_string(),
Self::FollowingQuestions => "/following/questions", Self::FollowingQuestions => "/following/questions".to_string(),
Self::AllPosts => "/all", Self::AllPosts => "/all".to_string(),
Self::AllQuestions => "/all/questions", Self::AllQuestions => "/all/questions".to_string(),
Self::Stack(id) => format!("/stacks/{id}"),
} }
} }
} }