Merge pull request 'More personal timelines' (#1069) from timeline-order into main
Reviewed-on: https://git.joinplu.me/Plume/Plume/pulls/1069
This commit is contained in:
commit
b9ea83a602
@ -507,6 +507,7 @@ figure {
|
|||||||
margin: auto $horizontal-margin 2em;
|
margin: auto $horizontal-margin 2em;
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
display: flex;
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
|
||||||
a {
|
a {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
|
@ -6,6 +6,7 @@ use crate::{
|
|||||||
Connection, Error, Result,
|
Connection, Error, Result,
|
||||||
};
|
};
|
||||||
use diesel::{self, BoolExpressionMethods, ExpressionMethods, QueryDsl, RunQueryDsl};
|
use diesel::{self, BoolExpressionMethods, ExpressionMethods, QueryDsl, RunQueryDsl};
|
||||||
|
use std::cmp::Ordering;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
|
||||||
pub(crate) mod query;
|
pub(crate) mod query;
|
||||||
@ -85,6 +86,16 @@ impl Timeline {
|
|||||||
.or(timeline_definition::user_id.is_null()),
|
.or(timeline_definition::user_id.is_null()),
|
||||||
)
|
)
|
||||||
.load::<Self>(conn)
|
.load::<Self>(conn)
|
||||||
|
.map(|mut timelines| {
|
||||||
|
timelines.sort_by(|t1, t2| {
|
||||||
|
if t1.user_id.is_some() && t2.user_id.is_none() {
|
||||||
|
Ordering::Less
|
||||||
|
} else {
|
||||||
|
Ordering::Equal
|
||||||
|
}
|
||||||
|
});
|
||||||
|
timelines
|
||||||
|
})
|
||||||
.map_err(Error::from)
|
.map_err(Error::from)
|
||||||
} else {
|
} else {
|
||||||
timeline_definition::table
|
timeline_definition::table
|
||||||
|
@ -28,25 +28,26 @@ use plume_models::{
|
|||||||
|
|
||||||
#[get("/")]
|
#[get("/")]
|
||||||
pub fn index(conn: DbConn, rockets: PlumeRocket) -> Result<Ructe, ErrorPage> {
|
pub fn index(conn: DbConn, rockets: PlumeRocket) -> Result<Ructe, ErrorPage> {
|
||||||
let inst = Instance::get_local()?;
|
let all_tl = Timeline::list_all_for_user(&conn, rockets.user.clone().map(|u| u.id))?;
|
||||||
let timelines = Timeline::list_all_for_user(&conn, rockets.user.clone().map(|u| u.id))?
|
if all_tl.is_empty() {
|
||||||
.into_iter()
|
Err(Error::NotFound.into())
|
||||||
.filter_map(|t| {
|
} else {
|
||||||
if let Ok(latest) = t.get_latest(&conn, 12) {
|
let inst = Instance::get_local()?;
|
||||||
Some((t, latest))
|
let page = Page::default();
|
||||||
} else {
|
let tl = &all_tl[0];
|
||||||
None
|
let posts = tl.get_page(&conn, page.limits())?;
|
||||||
}
|
let total_posts = tl.count_posts(&conn)?;
|
||||||
})
|
Ok(render!(instance::index(
|
||||||
.collect();
|
&(&conn, &rockets).to_context(),
|
||||||
|
inst,
|
||||||
Ok(render!(instance::index(
|
User::count_local(&conn)?,
|
||||||
&(&conn, &rockets).to_context(),
|
Post::count_local(&conn)?,
|
||||||
inst,
|
tl.id,
|
||||||
User::count_local(&conn)?,
|
posts,
|
||||||
Post::count_local(&conn)?,
|
all_tl,
|
||||||
timelines
|
Page::total(total_posts as i32)
|
||||||
)))
|
)))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/admin")]
|
#[get("/admin")]
|
||||||
|
6
src/routes/mod.rs
Executable file → Normal file
6
src/routes/mod.rs
Executable file → Normal file
@ -59,6 +59,12 @@ impl From<Flash<Redirect>> for RespondOrRedirect {
|
|||||||
#[derive(Shrinkwrap, Copy, Clone, UriDisplayQuery)]
|
#[derive(Shrinkwrap, Copy, Clone, UriDisplayQuery)]
|
||||||
pub struct Page(i32);
|
pub struct Page(i32);
|
||||||
|
|
||||||
|
impl From<i32> for Page {
|
||||||
|
fn from(page: i32) -> Self {
|
||||||
|
Self(page)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'v> FromFormValue<'v> for Page {
|
impl<'v> FromFormValue<'v> for Page {
|
||||||
type Error = &'v RawStr;
|
type Error = &'v RawStr;
|
||||||
fn from_form_value(form_value: &'v RawStr) -> Result<Page, &'v RawStr> {
|
fn from_form_value(form_value: &'v RawStr) -> Result<Page, &'v RawStr> {
|
||||||
|
@ -4,37 +4,37 @@
|
|||||||
@use crate::templates::{base, partials::*};
|
@use crate::templates::{base, partials::*};
|
||||||
@use crate::template_utils::*;
|
@use crate::template_utils::*;
|
||||||
@use crate::routes::*;
|
@use crate::routes::*;
|
||||||
|
@use rocket::uri;
|
||||||
|
|
||||||
@(ctx: BaseContext, instance: Instance, n_users: i64, n_articles: i64, all_tl: Vec<(Timeline, Vec<Post>)>)
|
@(ctx: BaseContext, instance: Instance, n_users: i64, n_articles: i64, tl_id: i32, articles: Vec<Post>, all_tl: Vec<Timeline>, n_pages: i32)
|
||||||
|
|
||||||
@:base(ctx, instance.name.clone(), {}, {}, {
|
@:base(ctx, instance.name.clone(), {}, {}, {
|
||||||
<h1>@i18n!(ctx.1, "Welcome to {}"; instance.name.as_str())</h1>
|
<section class="flex wrap" dir="auto">
|
||||||
|
<h1 class="grow">@i18n!(ctx.1, "Welcome to {}"; instance.name.as_str())</h1>
|
||||||
|
</section>
|
||||||
|
|
||||||
@tabs(&vec![(format!("{}", uri!(instance::index)), i18n!(ctx.1, "Latest articles"), true)]
|
@tabs(&all_tl
|
||||||
.into_iter().chain(all_tl.clone()
|
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|(tl, _)| {
|
.map(|t| {
|
||||||
let url = format!("{}", uri!(timelines::details: id = tl.id, page = _));
|
let url = format!("{}", uri!(timelines::details: id = t.id, page = _));
|
||||||
(url, i18n_timeline_name(ctx.1, &tl.name), false)
|
(url, i18n_timeline_name(ctx.1, &t.name), t.id == tl_id)
|
||||||
})
|
})
|
||||||
).collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
)
|
)
|
||||||
|
|
||||||
@for (tl, articles) in all_tl {
|
@if !articles.is_empty() {
|
||||||
@if !articles.is_empty() {
|
<div class="cards">
|
||||||
<div class="h-feed">
|
@for article in articles {
|
||||||
<h2 dir="auto">
|
@:post_card(ctx, article)
|
||||||
<span class="p-name">@i18n_timeline_name(ctx.1, &tl.name)</span>
|
}
|
||||||
—
|
</div>
|
||||||
<a href="@uri!(timelines::details: id = tl.id, page = _)">@i18n!(ctx.1, "View all")</a>
|
} else {
|
||||||
</h2>
|
<p class="center">@i18n!(ctx.1, "Nothing to see here yet.")</p>
|
||||||
<div class="cards">
|
}
|
||||||
@for article in articles {
|
@if n_pages > 1 {
|
||||||
@:post_card(ctx, article)
|
<div class="pagination" dir="auto">
|
||||||
}
|
<a href="@uri!(timelines::details: id = tl_id, page = Some(2.into()))">@i18n!(ctx.1, "Next page")</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@:instance_description(ctx, instance, n_users, n_articles)
|
@:instance_description(ctx, instance, n_users, n_articles)
|
||||||
|
@ -8,21 +8,20 @@
|
|||||||
@(ctx: BaseContext, tl: Timeline, articles: Vec<Post>, all_tl: Vec<Timeline>, page: i32, n_pages: i32)
|
@(ctx: BaseContext, tl: Timeline, articles: Vec<Post>, all_tl: Vec<Timeline>, page: i32, n_pages: i32)
|
||||||
|
|
||||||
@:base(ctx, tl.name.clone(), {}, {}, {
|
@:base(ctx, tl.name.clone(), {}, {}, {
|
||||||
<section class="flex wrap" dir="auto">
|
<section class="flex wrap" dir="auto">
|
||||||
<h1 class="grow">@i18n_timeline_name(ctx.1, &tl.name)</h1>
|
<h1 class="grow">@i18n_timeline_name(ctx.1, &tl.name)</h1>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
@tabs(&vec![(format!("{}", uri!(instance::index)), i18n!(ctx.1, "Latest articles"), false)]
|
@tabs(&all_tl
|
||||||
.into_iter().chain(all_tl
|
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|t| {
|
.map(|t| {
|
||||||
let url = format!("{}", uri!(timelines::details: id = t.id, page = _));
|
let url = format!("{}", uri!(timelines::details: id = t.id, page = _));
|
||||||
(url, i18n_timeline_name(ctx.1, &t.name), t.id == tl.id)
|
(url, i18n_timeline_name(ctx.1, &t.name), t.id == tl.id)
|
||||||
})
|
})
|
||||||
).collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
)
|
)
|
||||||
|
|
||||||
@if !articles.is_empty() {
|
@if !articles.is_empty() {
|
||||||
<div class="cards">
|
<div class="cards">
|
||||||
@for article in articles {
|
@for article in articles {
|
||||||
@:post_card(ctx, article)
|
@:post_card(ctx, article)
|
||||||
|
Loading…
Reference in New Issue
Block a user