add: following timeline

This commit is contained in:
trisua 2025-04-09 22:00:45 -04:00
parent 6141910059
commit 1ee1f29cdf
15 changed files with 176 additions and 9 deletions

View file

@ -54,6 +54,7 @@ pub const COMMUNITIES_SETTINGS: &str = include_str!("./public/html/communities/s
pub const COMMUNITIES_MEMBERS: &str = include_str!("./public/html/communities/members.html");
pub const TIMELINES_HOME: &str = include_str!("./public/html/timelines/home.html");
pub const TIMELINES_FOLLOWING: &str = include_str!("./public/html/timelines/following.html");
pub const TIMELINES_POPULAR: &str = include_str!("./public/html/timelines/popular.html");
pub const MOD_AUDIT_LOG: &str = include_str!("./public/html/mod/audit_log.html");
@ -181,6 +182,7 @@ pub(crate) async fn write_assets(config: &Config) -> PathBufD {
write_template!(html_path->"communities/members.html"(crate::assets::COMMUNITIES_MEMBERS) --config=config);
write_template!(html_path->"timelines/home.html"(crate::assets::TIMELINES_HOME) -d "timelines" --config=config);
write_template!(html_path->"timelines/following.html"(crate::assets::TIMELINES_FOLLOWING) --config=config);
write_template!(html_path->"timelines/popular.html"(crate::assets::TIMELINES_POPULAR) --config=config);
write_template!(html_path->"mod/audit_log.html"(crate::assets::MOD_AUDIT_LOG) -d "mod" --config=config);

View file

@ -3,6 +3,7 @@ version = "1.0.0"
[data]
"general:link.home" = "Home"
"general:link.following" = "Following"
"general:link.popular" = "Popular"
"general:link.communities" = "Communities"
"general:link.next" = "Next"

View file

@ -163,6 +163,14 @@
<span>{{ text "general:link.home" }}</span>
</a>
<a
href="/following"
class="{% if selected == 'following' %}active{% endif %}"
>
{{ icon "earth" }}
<span>{{ text "general:link.following" }}</span>
</a>
<a href="/popular" class="{% if selected == 'popular' %}active{% endif %}">
{{ icon "trending-up" }}
<span>{{ text "general:link.popular" }}</span>

View file

@ -0,0 +1,16 @@
{% extends "root.html" %} {% block head %}
<title>Following - {{ config.name }}</title>
{% endblock %} {% block body %} {{ macros::nav() }}
<main class="flex flex-col gap-2">
{{ macros::timelines_nav(selected="following") }}
<!-- prettier-ignore -->
<div class="card w-full flex flex-col gap-2">
{% for post in list %}
{{ components::post(post=post[0], owner=post[1], secondary=true, community=post[2], show_community=true) }}
{% endfor %}
{{ components::pagination(page=page, items=list|length) }}
</div>
</main>
{% endblock %}

View file

@ -5,7 +5,7 @@
<!-- prettier-ignore -->
{{ macros::timelines_nav(selected="home") }}
{% if list|length == 0 %}
{% if list|length == 0 and page == 0 %}
<div class="card-nest">
<div class="card">
<b>✨ Welcome to <i>{{ config.name }}</i>!</b>
@ -21,6 +21,8 @@
{% for post in list %}
{{ components::post(post=post[0], owner=post[1], secondary=true, community=post[2], show_community=true) }}
{% endfor %}
{{ components::pagination(page=page, items=list|length) }}
</div>
{% endif %}
</main>

View file

@ -9,6 +9,8 @@
{% for post in list %}
{{ components::post(post=post[0], owner=post[1], secondary=true, community=post[2], show_community=true) }}
{% endfor %}
{{ components::pagination(page=page, items=list|length) }}
</div>
</main>
{% endblock %}

View file

@ -58,9 +58,48 @@ pub async fn index_request(
let mut context = initial_context(&data.0.0, lang, &Some(user)).await;
context.insert("list", &list);
context.insert("page", &req.page);
Html(data.1.render("timelines/home.html", &context).unwrap())
}
/// `/following`
pub async fn following_request(
jar: CookieJar,
Extension(data): Extension<State>,
Query(req): Query<PaginatedQuery>,
) -> impl IntoResponse {
let data = data.read().await;
let user = match get_user_from_token!(jar, data.0) {
Some(ua) => ua,
None => {
return Err(Html(
render_error(Error::NotAllowed, &jar, &data, &None).await,
));
}
};
let list = match data
.0
.get_posts_from_user_following(user.id, 12, req.page)
.await
{
Ok(l) => match data.0.fill_posts_with_community(l).await {
Ok(l) => l,
Err(e) => return Err(Html(render_error(e, &jar, &data, &Some(user)).await)),
},
Err(e) => return Err(Html(render_error(e, &jar, &data, &Some(user)).await)),
};
let lang = get_lang!(jar, data.0);
let mut context = initial_context(&data.0.0, lang, &Some(user)).await;
context.insert("list", &list);
context.insert("page", &req.page);
Ok(Html(
data.1.render("timelines/following.html", &context).unwrap(),
))
}
/// `/popular`
pub async fn popular_request(
jar: CookieJar,
@ -82,6 +121,7 @@ pub async fn popular_request(
let mut context = initial_context(&data.0.0, lang, &user).await;
context.insert("list", &list);
context.insert("page", &req.page);
Html(data.1.render("timelines/popular.html", &context).unwrap())
}

View file

@ -18,6 +18,7 @@ pub fn routes() -> Router {
Router::new()
// misc
.route("/", get(misc::index_request))
.route("/following", get(misc::following_request))
.route("/popular", get(misc::popular_request))
.route("/notifs", get(misc::notifications_request))
.route("/doc/{*file_name}", get(misc::markdown_document_request))