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",
&ua.permissions.check(FinePermission::SUPPORTER),
);
ctx.insert("home", ua.settings.default_timeline.relative_url());
ctx.insert("home", &ua.settings.default_timeline.relative_url());
} else {
ctx.insert("is_helper", &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);

View file

@ -76,7 +76,7 @@
<div class="card">
<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
value="MyCommunities"
@ -129,6 +129,14 @@
>
All (questions)
</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>
<span class="fade"

View file

@ -11,7 +11,7 @@ use axum::{
use axum_extra::extract::CookieJar;
use serde::Deserialize;
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 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 lang = get_lang!(jar, data.0);
let mut context = initial_context(&data.0.0, lang, &Some(user)).await;
context.insert("profile", &profile);
context.insert("stacks", &stacks);
context.insert("user_settings_serde", &clean_settings(&profile.settings));
context.insert(
"user_tokens_serde",

View file

@ -71,6 +71,7 @@ pub enum DefaultTimelineChoice {
FollowingQuestions,
AllPosts,
AllQuestions,
Stack(String),
}
impl Default for DefaultTimelineChoice {
@ -81,16 +82,17 @@ impl Default for DefaultTimelineChoice {
impl DefaultTimelineChoice {
/// 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 {
Self::MyCommunities => "/",
Self::MyCommunitiesQuestions => "/questions",
Self::PopularPosts => "/popular",
Self::PopularQuestions => "/popular/questions",
Self::FollowingPosts => "/following",
Self::FollowingQuestions => "/following/questions",
Self::AllPosts => "/all",
Self::AllQuestions => "/all/questions",
Self::MyCommunities => "/".to_string(),
Self::MyCommunitiesQuestions => "/questions".to_string(),
Self::PopularPosts => "/popular".to_string(),
Self::PopularQuestions => "/popular/questions".to_string(),
Self::FollowingPosts => "/following".to_string(),
Self::FollowingQuestions => "/following/questions".to_string(),
Self::AllPosts => "/all".to_string(),
Self::AllQuestions => "/all/questions".to_string(),
Self::Stack(id) => format!("/stacks/{id}"),
}
}
}