diff options
-rw-r--r-- | common/src/user.rs | 2 | ||||
-rw-r--r-- | server/src/routes/ui/sort.rs | 24 |
2 files changed, 23 insertions, 3 deletions
diff --git a/common/src/user.rs b/common/src/user.rs index 8807772..1ae849c 100644 --- a/common/src/user.rs +++ b/common/src/user.rs @@ -19,7 +19,7 @@ pub struct NodeUserData { pub watched: WatchedState, } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] #[serde(rename_all = "snake_case")] pub enum WatchedState { None, diff --git a/server/src/routes/ui/sort.rs b/server/src/routes/ui/sort.rs index b140de8..9428694 100644 --- a/server/src/routes/ui/sort.rs +++ b/server/src/routes/ui/sort.rs @@ -1,4 +1,8 @@ -use jellycommon::{helpers::SortAnyway, user::NodeUserData, NodeKind, NodePublic, Rating}; +use jellycommon::{ + helpers::SortAnyway, + user::{NodeUserData, WatchedState}, + NodeKind, NodePublic, Rating, +}; use rocket::{ http::uri::fmt::{Query, UriDisplay}, FromForm, FromFormField, UriDisplayQuery, @@ -23,6 +27,9 @@ form_enum!( enum FilterProperty { FederationLocal = "fed_local", FederationRemote = "fed_remote", + Watched = "watched", + Unwatched = "unwatched", + WatchProgress = "watch_progress", KindMovie = "kind_movie", KindVideo = "kind_video", KindCollection = "kind_collection", @@ -92,6 +99,14 @@ impl FilterProperty { "By Federation", &[(FederationLocal, "Local"), (FederationRemote, "Remote")], ), + ( + "By Watched", + &[ + (Watched, "Watched"), + (Unwatched, "Unwatched"), + (WatchProgress, "Partially Watched"), + ], + ), ] }; } @@ -113,7 +128,7 @@ pub fn filter_and_sort_nodes( f: &NodeFilterSort, nodes: &mut Vec<(String, NodePublic, NodeUserData)>, ) { - nodes.retain(|(_id, node, _udata)| { + nodes.retain(|(_id, node, udata)| { let mut o = true; if let Some(prop) = &f.filter_kind { for p in FilterProperty::ALL { @@ -131,6 +146,11 @@ pub fn filter_and_sort_nodes( FilterProperty::KindSeries => node.kind == NodeKind::Series, FilterProperty::KindSeason => node.kind == NodeKind::Season, FilterProperty::KindEpisode => node.kind == NodeKind::Episode, + FilterProperty::Watched => udata.watched == WatchedState::Watched, + FilterProperty::Unwatched => udata.watched == WatchedState::None, + FilterProperty::WatchProgress => { + matches!(udata.watched, WatchedState::Progress(_)) + } } } } |