diff options
Diffstat (limited to 'ui/src/components/props.rs')
| -rw-r--r-- | ui/src/components/props.rs | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/ui/src/components/props.rs b/ui/src/components/props.rs new file mode 100644 index 0000000..f23d72e --- /dev/null +++ b/ui/src/components/props.rs @@ -0,0 +1,66 @@ +/* + This file is part of jellything (https://codeberg.org/metamuffin/jellything) + which is licensed under the GNU Affero General Public License (version 3); see /COPYING. + Copyright (C) 2026 metamuffin <metamuffin.org> +*/ + +use crate::{ + RenderInfo, + format::{format_count, format_duration}, + locale::tr, +}; +use chrono::DateTime; +use jellycommon::{ + jellyobject::{Object, TypedTag}, + *, +}; +use std::marker::PhantomData; + +markup::define! { + Props<'a>(ri: &'a RenderInfo<'a>, nku: Object<'a>, full: bool) { + @let node = nku.get(NKU_NODE).unwrap_or_default(); + .props { + @if let Some(dur) = node.get(NO_DURATION) { + p { @format_duration(dur) } + } + // @if let Some(res) = node.get(NO_TRACK) { + // p { @m.resolution_name() } + // } + @if let Some(d) = node.get(NO_RELEASEDATE) { + p { @if *full { + @DateTime::from_timestamp_millis(d).unwrap().naive_utc().to_string() + } else { + @DateTime::from_timestamp_millis(d).unwrap().date_naive().to_string() + }} + } + @match node.get(NO_VISIBILITY).unwrap_or(VISI_VISIBLE) { + VISI_REDUCED => {p.visibility{@tr(ri.lang, "prop.vis.reduced")}} + VISI_HIDDEN => {p.visibility{@tr(ri.lang, "prop.vis.hidden")}} + VISI_VISIBLE | _ => {} + } + // TODO + // @if !node.children.is_empty() { + // p { @format!("{} items", node.children.len()) } + // } + @for (kind, value) in node.get(NO_RATINGS).unwrap_or_default().entries::<f64>() { + @match TypedTag(kind, PhantomData) { + RTYP_YOUTUBE_LIKES => {p.likes{ @format_count(value as usize) " Likes" }} + RTYP_YOUTUBE_VIEWS => {p{ @format_count(value as usize) " Views" }} + RTYP_YOUTUBE_FOLLOWERS => {p{ @format_count(value as usize) " Subscribers" }} + RTYP_ROTTEN_TOMATOES => {p.rating{ @value " Tomatoes" }} + RTYP_METACRITIC if *full => {p{ "Metacritic Score: " @value }} + RTYP_IMDB => {p.rating{ "IMDb " @value }} + RTYP_TMDB => {p.rating{ "TMDB " @format!("{:.01}", value) }} + RTYP_TRAKT => {p.rating{ "Trakt " @format!("{:.01}", value) }} + _ => {} + } + } + // @match nodeu.udata.watched { + // WatchedState::None => {} + // WatchedState::Pending => { p.pending { @tr(ri.lang, "prop.watched.pending") } } + // WatchedState::Progress(x) => { p.progress { @tr(ri.lang, "prop.watched.progress").replace("{time}", &format_duration(x)) } } + // WatchedState::Watched => { p.watched { @tr(ri.lang, "prop.watched.watched") } } + // } + } + } +} |