aboutsummaryrefslogtreecommitdiff
path: root/server/src/routes/ui/sort.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2024-01-24 14:32:56 +0100
committermetamuffin <metamuffin@disroot.org>2024-01-24 14:32:56 +0100
commitc7952122732e38e942dfc601ca9d29dc64939698 (patch)
tree0a8f6608a9cce7ad24df660979a659c474262a3e /server/src/routes/ui/sort.rs
parent620a6af0a247ed1675477b86f77c07c55d9feea3 (diff)
downloadjellything-c7952122732e38e942dfc601ca9d29dc64939698.tar
jellything-c7952122732e38e942dfc601ca9d29dc64939698.tar.bz2
jellything-c7952122732e38e942dfc601ca9d29dc64939698.tar.zst
show less details props in card and default sort for channels
Diffstat (limited to 'server/src/routes/ui/sort.rs')
-rw-r--r--server/src/routes/ui/sort.rs63
1 files changed, 32 insertions, 31 deletions
diff --git a/server/src/routes/ui/sort.rs b/server/src/routes/ui/sort.rs
index 143a101..23918be 100644
--- a/server/src/routes/ui/sort.rs
+++ b/server/src/routes/ui/sort.rs
@@ -18,8 +18,8 @@ pub struct NodeFilterSort {
macro_rules! form_enum {
(enum $i:ident { $($vi:ident = $vk:literal),*, }) => {
- #[derive(FromFormField, UriDisplayQuery, Clone, PartialEq, Eq)]
- enum $i { $(#[field(value = $vk)] $vi),* }
+ #[derive(FromFormField, UriDisplayQuery, Clone, Copy, PartialEq, Eq)]
+ pub enum $i { $(#[field(value = $vk)] $vi),* }
impl $i { #[allow(unused)] const ALL: &'static [$i] = &[$($i::$vi),*]; }
};
}
@@ -120,13 +120,14 @@ impl NodeFilterSort {
#[rustfmt::skip]
#[derive(FromFormField, UriDisplayQuery, Clone, Copy, PartialEq, Eq)]
-enum SortOrder {
+pub enum SortOrder {
#[field(value = "ascending")] Ascending,
#[field(value = "descending")] Descending,
}
pub fn filter_and_sort_nodes(
f: &NodeFilterSort,
+ default_sort: (SortProperty, SortOrder),
nodes: &mut Vec<(String, NodePublic, NodeUserData)>,
) {
nodes.retain(|(_id, node, udata)| {
@@ -160,36 +161,36 @@ pub fn filter_and_sort_nodes(
}
o
});
- if let Some(sort_prop) = &f.sort_by {
- match sort_prop {
- SortProperty::ReleaseDate => {
- nodes.sort_by_key(|(_, n, _)| n.release_date.expect("asserted above"))
- }
- SortProperty::Title => nodes.sort_by(|(_, a, _), (_, b, _)| a.title.cmp(&b.title)),
- SortProperty::RatingRottenTomatoes => nodes.sort_by_cached_key(|(_, n, _)| {
- SortAnyway(*n.ratings.get(&Rating::RottenTomatoes).unwrap_or(&0.))
- }),
- SortProperty::RatingMetacritic => nodes.sort_by_cached_key(|(_, n, _)| {
- SortAnyway(*n.ratings.get(&Rating::Metacritic).unwrap_or(&0.))
- }),
- SortProperty::RatingImdb => nodes.sort_by_cached_key(|(_, n, _)| {
- SortAnyway(*n.ratings.get(&Rating::Imdb).unwrap_or(&0.))
- }),
- SortProperty::RatingTmdb => nodes.sort_by_cached_key(|(_, n, _)| {
- SortAnyway(*n.ratings.get(&Rating::Tmdb).unwrap_or(&0.))
- }),
- SortProperty::RatingYoutubeViews => nodes.sort_by_cached_key(|(_, n, _)| {
- SortAnyway(*n.ratings.get(&Rating::YoutubeViews).unwrap_or(&0.))
- }),
- SortProperty::RatingYoutubeLikes => nodes.sort_by_cached_key(|(_, n, _)| {
- SortAnyway(*n.ratings.get(&Rating::YoutubeLikes).unwrap_or(&0.))
- }),
- SortProperty::RatingYoutubeFollowers => nodes.sort_by_cached_key(|(_, n, _)| {
- SortAnyway(*n.ratings.get(&Rating::YoutubeFollowers).unwrap_or(&0.))
- }),
+ let sort_prop = f.sort_by.unwrap_or(default_sort.0);
+ match sort_prop {
+ SortProperty::ReleaseDate => {
+ nodes.sort_by_key(|(_, n, _)| n.release_date.expect("asserted above"))
}
+ SortProperty::Title => nodes.sort_by(|(_, a, _), (_, b, _)| a.title.cmp(&b.title)),
+ SortProperty::RatingRottenTomatoes => nodes.sort_by_cached_key(|(_, n, _)| {
+ SortAnyway(*n.ratings.get(&Rating::RottenTomatoes).unwrap_or(&0.))
+ }),
+ SortProperty::RatingMetacritic => nodes.sort_by_cached_key(|(_, n, _)| {
+ SortAnyway(*n.ratings.get(&Rating::Metacritic).unwrap_or(&0.))
+ }),
+ SortProperty::RatingImdb => nodes.sort_by_cached_key(|(_, n, _)| {
+ SortAnyway(*n.ratings.get(&Rating::Imdb).unwrap_or(&0.))
+ }),
+ SortProperty::RatingTmdb => nodes.sort_by_cached_key(|(_, n, _)| {
+ SortAnyway(*n.ratings.get(&Rating::Tmdb).unwrap_or(&0.))
+ }),
+ SortProperty::RatingYoutubeViews => nodes.sort_by_cached_key(|(_, n, _)| {
+ SortAnyway(*n.ratings.get(&Rating::YoutubeViews).unwrap_or(&0.))
+ }),
+ SortProperty::RatingYoutubeLikes => nodes.sort_by_cached_key(|(_, n, _)| {
+ SortAnyway(*n.ratings.get(&Rating::YoutubeLikes).unwrap_or(&0.))
+ }),
+ SortProperty::RatingYoutubeFollowers => nodes.sort_by_cached_key(|(_, n, _)| {
+ SortAnyway(*n.ratings.get(&Rating::YoutubeFollowers).unwrap_or(&0.))
+ }),
}
- match f.sort_order.unwrap_or(SortOrder::Ascending) {
+
+ match f.sort_order.unwrap_or(default_sort.1) {
SortOrder::Ascending => (),
SortOrder::Descending => nodes.reverse(),
}