aboutsummaryrefslogtreecommitdiff
path: root/server/src/routes
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-02-01 18:58:41 +0100
committermetamuffin <metamuffin@disroot.org>2025-02-01 18:58:41 +0100
commit4993f189870a96a328bdda5838d1d184c1bbdb67 (patch)
tree2d22c38d8bd028f6ab9b78e3ca36750bba5cc4d5 /server/src/routes
parent2f053d597e91585deb9efd1a098537b244c25f56 (diff)
downloadjellything-4993f189870a96a328bdda5838d1d184c1bbdb67.tar
jellything-4993f189870a96a328bdda5838d1d184c1bbdb67.tar.bz2
jellything-4993f189870a96a328bdda5838d1d184c1bbdb67.tar.zst
filter home screen latest, top and random
Diffstat (limited to 'server/src/routes')
-rw-r--r--server/src/routes/ui/home.rs40
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! {