diff options
Diffstat (limited to 'server/src/routes/ui/home.rs')
-rw-r--r-- | server/src/routes/ui/home.rs | 60 |
1 files changed, 19 insertions, 41 deletions
diff --git a/server/src/routes/ui/home.rs b/server/src/routes/ui/home.rs index 8eacfde..ebed647 100644 --- a/server/src/routes/ui/home.rs +++ b/server/src/routes/ui/home.rs @@ -5,40 +5,18 @@ */ use super::{account::session::Session, layout::LayoutPage, node::NodeCard}; use crate::{ - database::DataAcid, + database::Database, routes::ui::{error::MyResult, layout::DynLayoutPage}, }; use chrono::{Datelike, Utc}; -use jellybase::{ - database::{redb::ReadableTable, T_NODE, T_USER_NODE}, - CONF, -}; +use jellybase::CONF; use jellycommon::{user::WatchedState, Rating}; use rocket::{get, State}; use tokio::fs::read_to_string; #[get("/")] -pub fn r_home(sess: Session, db: &State<DataAcid>) -> MyResult<DynLayoutPage> { - let mut items = { - let txn = db.begin_read()?; - let nodes = txn.open_table(T_NODE)?; - let node_users = txn.open_table(T_USER_NODE)?; - let i = nodes - .iter()? - .map(|a| { - let (x, y) = a.unwrap(); - let (x, y) = (x.value().to_owned(), y.value().0); - let z = node_users - .get(&(sess.user.name.as_str(), x.as_str())) - .unwrap() - .map(|z| z.value().0) - .unwrap_or_default(); - (x, y, z) - }) - .collect::<Vec<_>>(); - drop(nodes); - i - }; +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<_>>(); @@ -52,7 +30,7 @@ pub fn r_home(sess: Session, db: &State<DataAcid>) -> MyResult<DynLayoutPage> { // .into_iter() // .collect::<Vec<_>>(); - items.sort_by_key(|(_, n, _)| { + items.sort_by_key(|(n, _)| { n.ratings .get(&Rating::Tmdb) .map(|x| (*x * -1000.) as i32) @@ -62,11 +40,11 @@ pub fn r_home(sess: Session, db: &State<DataAcid>) -> MyResult<DynLayoutPage> { let top_rated = items .iter() .take(16) - .filter(|(_, n, _)| n.ratings.contains_key(&Rating::Tmdb)) + .filter(|(n, _)| n.ratings.contains_key(&Rating::Tmdb)) .map(|k| k.to_owned()) .collect::<Vec<_>>(); - items.sort_by_key(|(_, n, _)| n.release_date.map(|d| -d).unwrap_or(i64::MAX)); + items.sort_by_key(|(n, _)| n.release_date.map(|d| -d).unwrap_or(i64::MAX)); let latest = items .iter() @@ -76,13 +54,13 @@ pub fn r_home(sess: Session, db: &State<DataAcid>) -> MyResult<DynLayoutPage> { let continue_watching = items .iter() - .filter(|(_, _, u)| matches!(u.watched, WatchedState::Progress(_))) + .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)) + .filter(|(_, u)| matches!(u.watched, WatchedState::Pending)) .map(|k| k.to_owned()) .collect::<Vec<_>>(); @@ -95,28 +73,28 @@ pub fn r_home(sess: Session, db: &State<DataAcid>) -> MyResult<DynLayoutPage> { // }} @if !continue_watching.is_empty() { h2 { "Continue Watching" } - ul.children.hlist {@for (id, node, udata) in &continue_watching { - li { @NodeCard { id, node, udata } } + ul.children.hlist {@for (node, udata) in &continue_watching { + li { @NodeCard { node, udata } } }} } @if !watchlist.is_empty() { h2 { "Watchlist" } - ul.children.hlist {@for (id, node, udata) in &watchlist { - li { @NodeCard { id, node, udata } } + ul.children.hlist {@for (node, udata) in &watchlist { + li { @NodeCard { node, udata } } }} } h2 { "Today's Picks" } - ul.children.hlist {@for (id, node, udata) in &random { - li { @NodeCard { id, node, udata } } + ul.children.hlist {@for (node, udata) in &random { + li { @NodeCard { node, udata } } }} h2 { "Latest Releases" } - ul.children.hlist {@for (id, node, udata) in &latest { - li { @NodeCard { id, node, udata } } + ul.children.hlist {@for (node, udata) in &latest { + li { @NodeCard { node, udata } } }} @if !top_rated.is_empty() { h2 { "Top Rated" } - ul.children.hlist {@for (id, node, udata) in &top_rated { - li { @NodeCard { id, node, udata } } + ul.children.hlist {@for (node, udata) in &top_rated { + li { @NodeCard { node, udata } } }} } }, |