aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-02-03 18:24:57 +0100
committermetamuffin <metamuffin@disroot.org>2025-02-03 18:24:57 +0100
commit11c5be29987912b89fd6d351938d08fe6a561ad2 (patch)
tree8c7361cdb243bc61a0c417111f2333e8f80b92e9
parent8d22e7fa56cfbceb3c829c6f22dc99234fd20b8d (diff)
downloadjellything-11c5be29987912b89fd6d351938d08fe6a561ad2.tar
jellything-11c5be29987912b89fd6d351938d08fe6a561ad2.tar.bz2
jellything-11c5be29987912b89fd6d351938d08fe6a561ad2.tar.zst
new home page categories
-rw-r--r--server/src/routes/ui/home.rs150
1 files changed, 94 insertions, 56 deletions
diff --git a/server/src/routes/ui/home.rs b/server/src/routes/ui/home.rs
index 1a4f20a..a8aac1a 100644
--- a/server/src/routes/ui/home.rs
+++ b/server/src/routes/ui/home.rs
@@ -30,28 +30,56 @@ pub fn r_home(sess: Session, db: &State<Database>) -> MyResult<DynLayoutPage> {
.map(|n| db.get_node_with_userdata(n, &sess))
.collect::<anyhow::Result<Vec<_>>>()?;
- let continue_watching = items
- .iter()
- .filter(|(_, u)| matches!(u.watched, WatchedState::Progress(_)))
- .map(|k| k.to_owned())
- .collect::<Vec<_>>();
+ let mut categories = Vec::<(&'static str, Vec<_>)>::new();
- let watchlist = items
- .iter()
- .filter(|(_, u)| matches!(u.watched, WatchedState::Pending))
- .map(|k| k.to_owned())
- .collect::<Vec<_>>();
+ categories.push((
+ "Continue Watching",
+ items
+ .iter()
+ .filter(|(_, u)| matches!(u.watched, WatchedState::Progress(_)))
+ .cloned()
+ .collect(),
+ ));
+ categories.push((
+ "Your Watchlist",
+ items
+ .iter()
+ .filter(|(_, u)| matches!(u.watched, WatchedState::Pending))
+ .cloned()
+ .collect(),
+ ));
- items.retain(|(n, _)| {
- matches!(
- n.kind,
- NodeKind::Video | NodeKind::Movie | NodeKind::Episode | NodeKind::Music
- ) && matches!(n.visibility, Visibility::Visible)
- });
+ items.retain(|(n, _)| matches!(n.visibility, Visibility::Visible));
- let random = (0..16)
- .flat_map(|i| Some(items[cheap_daily_random(i).checked_rem(items.len())?].clone()))
- .collect::<Vec<_>>();
+ items.sort_by_key(|(n, _)| n.release_date.map(|d| -d).unwrap_or(i64::MAX));
+
+ categories.push((
+ "Latest in Videos",
+ items
+ .iter()
+ .filter(|(n, _)| matches!(n.kind, NodeKind::Video))
+ .take(16)
+ .cloned()
+ .collect(),
+ ));
+ categories.push((
+ "Latest in Music",
+ items
+ .iter()
+ .filter(|(n, _)| matches!(n.kind, NodeKind::Music))
+ .take(16)
+ .cloned()
+ .collect(),
+ ));
+ categories.push((
+ "Latest in Short form",
+ items
+ .iter()
+ .filter(|(n, _)| matches!(n.kind, NodeKind::ShortFormVideo))
+ .take(16)
+ .cloned()
+ .collect(),
+ ));
items.sort_by_key(|(n, _)| {
n.ratings
@@ -60,20 +88,48 @@ pub fn r_home(sess: Session, db: &State<Database>) -> MyResult<DynLayoutPage> {
.unwrap_or(0)
});
- let top_rated = items
- .iter()
- .take(16)
- .filter(|(n, _)| n.ratings.contains_key(&Rating::Tmdb))
- .map(|k| k.to_owned())
- .collect::<Vec<_>>();
+ categories.push((
+ "Top Rated",
+ items
+ .iter()
+ .take(16)
+ .filter(|(n, _)| n.ratings.contains_key(&Rating::Tmdb))
+ .cloned()
+ .collect(),
+ ));
- items.sort_by_key(|(n, _)| n.release_date.map(|d| -d).unwrap_or(i64::MAX));
+ items.retain(|(n, _)| {
+ matches!(
+ n.kind,
+ NodeKind::Video | NodeKind::Movie | NodeKind::Episode | NodeKind::Music
+ )
+ });
+
+ categories.push((
+ "Today's Picks",
+ (0..16)
+ .flat_map(|i| Some(items[cheap_daily_random(i).checked_rem(items.len())?].clone()))
+ .collect(),
+ ));
- let latest = items
- .iter()
- .take(16)
- .map(|k| k.to_owned())
- .collect::<Vec<_>>();
+ {
+ let mut items = items.clone();
+ items.retain(|(_, u)| matches!(u.watched, WatchedState::Watched));
+ categories.push((
+ "Watch again",
+ (0..16)
+ .flat_map(|i| Some(items[cheap_daily_random(i).checked_rem(items.len())?].clone()))
+ .collect(),
+ ));
+ }
+
+ items.retain(|(n, _)| matches!(n.kind, NodeKind::Music));
+ categories.push((
+ "Discover Music",
+ (0..16)
+ .flat_map(|i| Some(items[cheap_daily_random(i).checked_rem(items.len())?].clone()))
+ .collect(),
+ ));
Ok(LayoutPage {
title: "Home".to_string(),
@@ -82,31 +138,13 @@ pub fn r_home(sess: Session, db: &State<Database>) -> MyResult<DynLayoutPage> {
ul.children.hlist {@for (node, udata) in &toplevel {
li { @NodeCard { node, udata } }
}}
- @if !continue_watching.is_empty() {
- h2 { "Continue Watching" }
- ul.children.hlist {@for (node, udata) in &continue_watching {
- li { @NodeCard { node, udata } }
- }}
- }
- @if !watchlist.is_empty() {
- h2 { "Watchlist" }
- ul.children.hlist {@for (node, udata) in &watchlist {
- li { @NodeCard { node, udata } }
- }}
- }
- h2 { "Today's Picks" }
- ul.children.hlist {@for (node, udata) in &random {
- li { @NodeCard { node, udata } }
- }}
- h2 { "Latest Releases" }
- ul.children.hlist {@for (node, udata) in &latest {
- li { @NodeCard { node, udata } }
- }}
- @if !top_rated.is_empty() {
- h2 { "Top Rated" }
- ul.children.hlist {@for (node, udata) in &top_rated {
- li { @NodeCard { node, udata } }
- }}
+ @for (name, nodes) in &categories {
+ @if !nodes.is_empty() {
+ h2 { @name }
+ ul.children.hlist {@for (node, udata) in nodes {
+ li { @NodeCard { node, udata } }
+ }}
+ }
}
},
..Default::default()