♻️ refactor
This commit is contained in:
parent
59dae90b4d
commit
5bee208995
4 changed files with 16 additions and 17 deletions
|
@ -166,9 +166,10 @@ impl Library {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_newly_added(&self, n: i64) -> Vec<Video> {
|
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;")
|
sqlx::query_as("SELECT * FROM videos ORDER BY date_added DESC LIMIT $1 OFFSET $2;")
|
||||||
.bind(n)
|
.bind(n)
|
||||||
|
.bind(offset)
|
||||||
.fetch_all(&self.conn)
|
.fetch_all(&self.conn)
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
|
@ -41,7 +41,8 @@ pub async fn render_page(
|
||||||
)
|
)
|
||||||
.use_htmx()]),
|
.use_htmx()]),
|
||||||
)
|
)
|
||||||
})),
|
}))
|
||||||
|
.no_dropdown(),
|
||||||
)
|
)
|
||||||
.render_page(content, title, ctx)
|
.render_page(content, title, ctx)
|
||||||
.await
|
.await
|
||||||
|
|
|
@ -66,7 +66,7 @@ pub async fn latest_api(
|
||||||
) -> FallibleApiResponse {
|
) -> FallibleApiResponse {
|
||||||
// todo : check_private!(conf, user, shell, ctx);
|
// 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;
|
let vid_api = vec_to_api(&videos).await;
|
||||||
return Ok(serde_json::json!(vid_api));
|
return Ok(serde_json::json!(vid_api));
|
||||||
}
|
}
|
||||||
|
@ -94,12 +94,8 @@ pub async fn latest_page(
|
||||||
check_private!(conf, user, shell, ctx);
|
check_private!(conf, user, shell, ctx);
|
||||||
|
|
||||||
let mut videos: Vec<_> = library
|
let mut videos: Vec<_> = library
|
||||||
.get_newly_added(offset.unwrap_or_default() as i64 + 20)
|
.get_newly_added(24, offset.unwrap_or_default() as i64)
|
||||||
.await
|
.await;
|
||||||
.into_iter()
|
|
||||||
.skip(offset.unwrap_or_default() as usize)
|
|
||||||
.take(20)
|
|
||||||
.collect();
|
|
||||||
let has_content = !videos.is_empty();
|
let has_content = !videos.is_empty();
|
||||||
let video_elements = VerticalVideoGrid(&mut videos).await;
|
let video_elements = VerticalVideoGrid(&mut videos).await;
|
||||||
|
|
||||||
|
@ -113,7 +109,7 @@ pub async fn latest_page(
|
||||||
ScreenValue::fit,
|
ScreenValue::fit,
|
||||||
Margin(InfinityScroll(
|
Margin(InfinityScroll(
|
||||||
ColoredSpinner(Purple::_600),
|
ColoredSpinner(Purple::_600),
|
||||||
&format!("/latest?offset={}", offset.unwrap_or_default() + 20),
|
&format!("/latest?offset={}", offset.unwrap_or_default() + 24),
|
||||||
))
|
))
|
||||||
.x(ScreenValue::auto),
|
.x(ScreenValue::auto),
|
||||||
)
|
)
|
||||||
|
@ -131,7 +127,7 @@ pub async fn latest_page(
|
||||||
ScreenValue::fit,
|
ScreenValue::fit,
|
||||||
Margin(InfinityScroll(
|
Margin(InfinityScroll(
|
||||||
ColoredSpinner(Purple::_600),
|
ColoredSpinner(Purple::_600),
|
||||||
&format!("/latest?offset={}", offset.unwrap_or_default() + 20),
|
&format!("/latest?offset={}", offset.unwrap_or_default() + 24),
|
||||||
))
|
))
|
||||||
.x(ScreenValue::auto),
|
.x(ScreenValue::auto),
|
||||||
))
|
))
|
||||||
|
@ -194,7 +190,7 @@ pub async fn index_page(
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
let newly_added_elements = html! {
|
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 );
|
( video_element(&mut vid).await );
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -214,7 +210,8 @@ pub async fn index_page(
|
||||||
.vanish()
|
.vanish()
|
||||||
.push_for_each(&directories, |dir: &_| DirectoryBadge(dir)),
|
.push_for_each(&directories, |dir: &_| DirectoryBadge(dir)),
|
||||||
)
|
)
|
||||||
.wrap(Wrap::Wrap),
|
.wrap(Wrap::Wrap)
|
||||||
|
.justify(Justify::Evenly),
|
||||||
)
|
)
|
||||||
.all(ScreenValue::_10),
|
.all(ScreenValue::_10),
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use based::format::format_number;
|
||||||
use based::ui::components::Shell;
|
use based::ui::components::Shell;
|
||||||
use based::ui::primitives::space::Fraction;
|
use based::ui::primitives::space::Fraction;
|
||||||
use based::ui::{prelude::*, AttrExtendable};
|
use based::ui::{prelude::*, AttrExtendable};
|
||||||
|
@ -44,8 +45,7 @@ pub async fn watch_page(
|
||||||
let youtube_meta = video.youtube_meta().await;
|
let youtube_meta = video.youtube_meta().await;
|
||||||
let rec = build_rec(&library, &video).await;
|
let rec = build_rec(&library, &video).await;
|
||||||
|
|
||||||
let content =
|
let content = Margin(
|
||||||
Margin(
|
|
||||||
Screen::large(Flex(Nothing()).direction(Direction::Row)).on(
|
Screen::large(Flex(Nothing()).direction(Direction::Row)).on(
|
||||||
Flex(
|
Flex(
|
||||||
Div().vanish()
|
Div().vanish()
|
||||||
|
@ -77,7 +77,7 @@ pub async fn watch_page(
|
||||||
Div().vanish().push(
|
Div().vanish().push(
|
||||||
Margin(Text(&meta.uploader_name).color(&Gray::_300).xl()).bottom(ScreenValue::_4)
|
Margin(Text(&meta.uploader_name).color(&Gray::_300).xl()).bottom(ScreenValue::_4)
|
||||||
).push(
|
).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))
|
).justify(Justify::Between).group()).top(ScreenValue::_2))
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Reference in a new issue