♻️ refactor

This commit is contained in:
JMARyA 2025-02-09 19:19:27 +01:00
parent 59dae90b4d
commit 5bee208995
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
4 changed files with 16 additions and 17 deletions

View file

@ -166,9 +166,10 @@ impl Library {
.unwrap()
}
pub async fn get_newly_added(&self, n: i64) -> Vec<Video> {
sqlx::query_as("SELECT * FROM videos ORDER BY date_added DESC LIMIT $1;")
pub async fn get_newly_added(&self, n: i64, offset: i64) -> Vec<Video> {
sqlx::query_as("SELECT * FROM videos ORDER BY date_added DESC LIMIT $1 OFFSET $2;")
.bind(n)
.bind(offset)
.fetch_all(&self.conn)
.await
.unwrap()

View file

@ -41,7 +41,8 @@ pub async fn render_page(
)
.use_htmx()]),
)
})),
}))
.no_dropdown(),
)
.render_page(content, title, ctx)
.await

View file

@ -66,7 +66,7 @@ pub async fn latest_api(
) -> FallibleApiResponse {
// todo : check_private!(conf, user, shell, ctx);
let videos = library.get_newly_added(20).await;
let videos = library.get_newly_added(24, 0).await;
let vid_api = vec_to_api(&videos).await;
return Ok(serde_json::json!(vid_api));
}
@ -94,12 +94,8 @@ pub async fn latest_page(
check_private!(conf, user, shell, ctx);
let mut videos: Vec<_> = library
.get_newly_added(offset.unwrap_or_default() as i64 + 20)
.await
.into_iter()
.skip(offset.unwrap_or_default() as usize)
.take(20)
.collect();
.get_newly_added(24, offset.unwrap_or_default() as i64)
.await;
let has_content = !videos.is_empty();
let video_elements = VerticalVideoGrid(&mut videos).await;
@ -113,7 +109,7 @@ pub async fn latest_page(
ScreenValue::fit,
Margin(InfinityScroll(
ColoredSpinner(Purple::_600),
&format!("/latest?offset={}", offset.unwrap_or_default() + 20),
&format!("/latest?offset={}", offset.unwrap_or_default() + 24),
))
.x(ScreenValue::auto),
)
@ -131,7 +127,7 @@ pub async fn latest_page(
ScreenValue::fit,
Margin(InfinityScroll(
ColoredSpinner(Purple::_600),
&format!("/latest?offset={}", offset.unwrap_or_default() + 20),
&format!("/latest?offset={}", offset.unwrap_or_default() + 24),
))
.x(ScreenValue::auto),
))
@ -194,7 +190,7 @@ pub async fn index_page(
};
};
let newly_added_elements = html! {
@for mut vid in library.get_newly_added(3).await {
@for mut vid in library.get_newly_added(3, 0).await {
( video_element(&mut vid).await );
};
};
@ -214,7 +210,8 @@ pub async fn index_page(
.vanish()
.push_for_each(&directories, |dir: &_| DirectoryBadge(dir)),
)
.wrap(Wrap::Wrap),
.wrap(Wrap::Wrap)
.justify(Justify::Evenly),
)
.all(ScreenValue::_10),
)

View file

@ -1,3 +1,4 @@
use based::format::format_number;
use based::ui::components::Shell;
use based::ui::primitives::space::Fraction;
use based::ui::{prelude::*, AttrExtendable};
@ -44,8 +45,7 @@ pub async fn watch_page(
let youtube_meta = video.youtube_meta().await;
let rec = build_rec(&library, &video).await;
let content =
Margin(
let content = Margin(
Screen::large(Flex(Nothing()).direction(Direction::Row)).on(
Flex(
Div().vanish()
@ -77,7 +77,7 @@ pub async fn watch_page(
Div().vanish().push(
Margin(Text(&meta.uploader_name).color(&Gray::_300).xl()).bottom(ScreenValue::_4)
).push(
Margin(Text(&format!("{} Views ﹣ {}", meta.views, format_date(&meta.upload_date))).color(&Gray::_300).xl()).bottom(ScreenValue::_4)
Margin(Text(&format!("{} Views ﹣ {}", format_number(meta.views), format_date(&meta.upload_date))).color(&Gray::_300).xl()).bottom(ScreenValue::_4)
)
).justify(Justify::Between).group()).top(ScreenValue::_2))
)