aboutsummaryrefslogtreecommitdiff
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
parent620a6af0a247ed1675477b86f77c07c55d9feea3 (diff)
downloadjellything-c7952122732e38e942dfc601ca9d29dc64939698.tar
jellything-c7952122732e38e942dfc601ca9d29dc64939698.tar.bz2
jellything-c7952122732e38e942dfc601ca9d29dc64939698.tar.zst
show less details props in card and default sort for channels
-rw-r--r--server/src/routes/ui/browser.rs8
-rw-r--r--server/src/routes/ui/node.rs17
-rw-r--r--server/src/routes/ui/sort.rs63
3 files changed, 52 insertions, 36 deletions
diff --git a/server/src/routes/ui/browser.rs b/server/src/routes/ui/browser.rs
index e811516..6c18442 100644
--- a/server/src/routes/ui/browser.rs
+++ b/server/src/routes/ui/browser.rs
@@ -8,7 +8,7 @@ use super::{
error::MyError,
layout::DynLayoutPage,
node::NodeCard,
- sort::{filter_and_sort_nodes, NodeFilterSort, NodeFilterSortForm},
+ sort::{filter_and_sort_nodes, NodeFilterSort, NodeFilterSortForm, SortOrder, SortProperty},
};
use crate::{database::DataAcid, uri};
use jellybase::database::{ReadableTable, T_NODE, T_USER_NODE};
@@ -47,7 +47,11 @@ pub fn r_all_items_filter(
i
};
- filter_and_sort_nodes(&filter, &mut items);
+ filter_and_sort_nodes(
+ &filter,
+ (SortProperty::Title, SortOrder::Ascending),
+ &mut items,
+ );
let page_size = 100;
let page = page.unwrap_or(0);
diff --git a/server/src/routes/ui/node.rs b/server/src/routes/ui/node.rs
index 59697ba..f613bd1 100644
--- a/server/src/routes/ui/node.rs
+++ b/server/src/routes/ui/node.rs
@@ -6,7 +6,7 @@
use super::{
assets::{rocket_uri_macro_r_item_assets, rocket_uri_macro_r_node_thumbnail},
error::MyResult,
- sort::{filter_and_sort_nodes, NodeFilterSort, NodeFilterSortForm},
+ sort::{filter_and_sort_nodes, NodeFilterSort, NodeFilterSortForm, SortOrder, SortProperty},
};
use crate::{
database::DataAcid,
@@ -101,7 +101,14 @@ pub async fn r_library_node_filter<'a>(
.into_iter()
.collect::<Vec<_>>();
- filter_and_sort_nodes(&filter, &mut children);
+ filter_and_sort_nodes(
+ &filter,
+ match node.kind.unwrap_or(NodeKind::Collection) {
+ NodeKind::Channel => (SortProperty::ReleaseDate, SortOrder::Descending),
+ _ => (SortProperty::Title, SortOrder::Ascending),
+ },
+ &mut children,
+ );
Ok(Either::Left(LayoutPage {
title: node.title.clone().unwrap_or_default(),
@@ -253,7 +260,11 @@ markup::define! {
p { @m.resolution_name() }
}
@if let Some(d) = &node.release_date {
- p { @NaiveDateTime::from_timestamp_millis(*d).unwrap().and_utc().to_string() }
+ p { @if *full {
+ @NaiveDateTime::from_timestamp_millis(*d).unwrap().and_utc().to_string()
+ } else {
+ @NaiveDateTime::from_timestamp_millis(*d).unwrap().date().to_string()
+ }}
}
@if !node.children.is_empty() {
p { @format!("{} items", node.children.len()) }
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(),
}