diff options
Diffstat (limited to 'server/src/routes/ui/home.rs')
-rw-r--r-- | server/src/routes/ui/home.rs | 40 |
1 files changed, 24 insertions, 16 deletions
diff --git a/server/src/routes/ui/home.rs b/server/src/routes/ui/home.rs index 6c6fdbc..321d184 100644 --- a/server/src/routes/ui/home.rs +++ b/server/src/routes/ui/home.rs @@ -15,16 +15,13 @@ use crate::{ use anyhow::Context; use chrono::{Datelike, Utc}; use jellybase::CONF; -use jellycommon::{user::WatchedState, NodeID, Rating}; +use jellycommon::{user::WatchedState, NodeID, NodeKind, Rating}; use rocket::{get, State}; use tokio::fs::read_to_string; #[get("/")] pub fn r_home(sess: Session, db: &State<Database>) -> MyResult<DynLayoutPage> { let mut items = db.list_nodes_with_udata(&sess.user.name)?; - let random = (0..16) - .flat_map(|i| Some(items[cheap_daily_random(i).checked_rem(items.len())?].clone())) - .collect::<Vec<_>>(); let toplevel = db .get_node_children(NodeID::from_slug("library")) @@ -33,6 +30,29 @@ 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 watchlist = items + .iter() + .filter(|(_, u)| matches!(u.watched, WatchedState::Pending)) + .map(|k| k.to_owned()) + .collect::<Vec<_>>(); + + items.retain(|(n, _)| { + matches!( + n.kind, + Some(NodeKind::Video | NodeKind::Movie | NodeKind::Episode | NodeKind::Music) + ) + }); + + 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.ratings .get(&Rating::Tmdb) @@ -55,18 +75,6 @@ pub fn r_home(sess: Session, db: &State<Database>) -> MyResult<DynLayoutPage> { .map(|k| k.to_owned()) .collect::<Vec<_>>(); - let continue_watching = items - .iter() - .filter(|(_, u)| matches!(u.watched, WatchedState::Progress(_))) - .map(|k| k.to_owned()) - .collect::<Vec<_>>(); - - let watchlist = items - .iter() - .filter(|(_, u)| matches!(u.watched, WatchedState::Pending)) - .map(|k| k.to_owned()) - .collect::<Vec<_>>(); - Ok(LayoutPage { title: "Home".to_string(), content: markup::new! { |