aboutsummaryrefslogtreecommitdiff
path: root/server/src/routes/ui/home.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2023-12-16 01:08:15 +0100
committermetamuffin <metamuffin@disroot.org>2023-12-16 01:08:15 +0100
commitaf99c406af8ee47bee38708cf23e86af826e41ba (patch)
tree23498a36f813454c2edea46906f812d929ba792e /server/src/routes/ui/home.rs
parent21b58037c69798e922c5512ea5380943781558ff (diff)
downloadjellything-af99c406af8ee47bee38708cf23e86af826e41ba.tar
jellything-af99c406af8ee47bee38708cf23e86af826e41ba.tar.bz2
jellything-af99c406af8ee47bee38708cf23e86af826e41ba.tar.zst
watch progress and some draft ui
Diffstat (limited to 'server/src/routes/ui/home.rs')
-rw-r--r--server/src/routes/ui/home.rs67
1 files changed, 33 insertions, 34 deletions
diff --git a/server/src/routes/ui/home.rs b/server/src/routes/ui/home.rs
index 3f1f0d0..bcbc847 100644
--- a/server/src/routes/ui/home.rs
+++ b/server/src/routes/ui/home.rs
@@ -3,7 +3,11 @@
which is licensed under the GNU Affero General Public License (version 3); see /COPYING.
Copyright (C) 2023 metamuffin <metamuffin.org>
*/
-use super::{account::session::Session, layout::LayoutPage, node::NodeCard};
+use super::{
+ account::session::Session,
+ layout::LayoutPage,
+ node::{DatabaseNodeUserDataExt, NodeCard},
+};
use crate::{
database::Database,
routes::ui::{error::MyResult, layout::DynLayoutPage},
@@ -11,7 +15,10 @@ use crate::{
use anyhow::Context;
use chrono::{Datelike, Utc};
use jellybase::CONF;
-use jellycommon::NodePublic;
+use jellycommon::{
+ user::{NodeUserData, WatchedState},
+ NodePublic,
+};
use rocket::{get, State};
use tokio::fs::read_to_string;
@@ -20,11 +27,18 @@ pub fn r_home(sess: Session, db: &State<Database>) -> MyResult<DynLayoutPage> {
let mut items = db
.node
.iter()
- .map(|e| e.context("listing"))
+ .map(|e| {
+ let (i, n) = e.context("listing")?;
+ let u = db
+ .user_node
+ .get(&(sess.user.name.clone(), i.clone()))?
+ .unwrap_or_default();
+ Ok((i, n, u))
+ })
.collect::<anyhow::Result<Vec<_>>>()?
.into_iter()
- .map(|(k, n)| (k, n.public))
- .collect::<Vec<(String, NodePublic)>>();
+ .map(|(k, n, u)| (k, n.public, u))
+ .collect::<Vec<(String, NodePublic, NodeUserData)>>();
let random = (0..16)
.flat_map(|i| Some(items[cheap_daily_random(i).checked_rem(items.len())?].clone()))
@@ -37,17 +51,12 @@ pub fn r_home(sess: Session, db: &State<Database>) -> MyResult<DynLayoutPage> {
.public
.children
.into_iter()
- .map(|n| {
- Ok((
- n.clone(),
- db.node.get(&n)?.context("child does not exist")?.public,
- ))
- })
+ .map(|n| db.get_node_with_userdata(&n, &sess))
.collect::<anyhow::Result<Vec<_>>>()?
.into_iter()
.collect::<Vec<_>>();
- items.sort_by_key(|(_, n)| {
+ items.sort_by_key(|(_, n, _)| {
n.release_date
.map(|d| -d.naive_utc().timestamp())
.unwrap_or(i64::MAX)
@@ -59,20 +68,10 @@ pub fn r_home(sess: Session, db: &State<Database>) -> MyResult<DynLayoutPage> {
.map(|k| k.to_owned())
.collect::<Vec<_>>();
- let continue_watching = db
- .user_progess
- .get(&sess.user.name)?
- .unwrap_or_default()
- .into_iter()
- .map(|(n, p)| {
- Ok((
- n.clone(),
- db.node.get(&n)?.context("child does not exist")?.public,
- p,
- ))
- })
- .collect::<anyhow::Result<Vec<_>>>()?
- .into_iter()
+ let continue_watching = items
+ .iter()
+ .filter(|(_, _, u)| matches!(u.watched, WatchedState::Progress(_)))
+ .map(|k| k.to_owned())
.collect::<Vec<_>>();
Ok(LayoutPage {
@@ -80,22 +79,22 @@ pub fn r_home(sess: Session, db: &State<Database>) -> MyResult<DynLayoutPage> {
content: markup::new! {
p { "Welcome back " @sess.user.display_name }
h2 { "Explore " @CONF.brand }
- .homelist { ul {@for (id, node) in &toplevel {
- li { @NodeCard { id, node } }
+ .homelist { ul {@for (id, node, udata) in &toplevel {
+ li { @NodeCard { id, node, udata } }
}}}
@if !continue_watching.is_empty() {
h2 { "Continue Watching" }
- .homelist { ul {@for (id, node, _p) in &continue_watching {
- li { @NodeCard { id, node } }
+ .homelist { ul {@for (id, node, udata) in &continue_watching {
+ li { @NodeCard { id, node, udata } }
}}}
}
h2 { "Latest Releases" }
- .homelist { ul {@for (id, node) in &latest {
- li { @NodeCard { id, node } }
+ .homelist { ul {@for (id, node, udata) in &latest {
+ li { @NodeCard { id, node, udata } }
}}}
h2 { "Today's Picks" }
- .homelist { ul {@for (id, node) in &random {
- li { @NodeCard { id, node } }
+ .homelist { ul {@for (id, node, udata) in &random {
+ li { @NodeCard { id, node, udata } }
}}}
p.error { "TODO: recently added" }
p.error { "TODO: best rating" }