aboutsummaryrefslogtreecommitdiff
path: root/server/src/routes/ui/sort.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2023-12-17 14:54:48 +0100
committermetamuffin <metamuffin@disroot.org>2023-12-17 14:54:48 +0100
commit67608be88bc9d88f96babd5f075c708194f71062 (patch)
tree2a2d51fc1d69f9c8fb6f600f87ad51ab18f4509e /server/src/routes/ui/sort.rs
parent61dc9b1069c2763fbe075d70750ade9e2482131a (diff)
downloadjellything-67608be88bc9d88f96babd5f075c708194f71062.tar
jellything-67608be88bc9d88f96babd5f075c708194f71062.tar.bz2
jellything-67608be88bc9d88f96babd5f075c708194f71062.tar.zst
filter by watched
Diffstat (limited to 'server/src/routes/ui/sort.rs')
-rw-r--r--server/src/routes/ui/sort.rs24
1 files changed, 22 insertions, 2 deletions
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(_))
+ }
}
}
}