diff options
| author | metamuffin <metamuffin@disroot.org> | 2026-02-27 20:56:20 +0100 |
|---|---|---|
| committer | metamuffin <metamuffin@disroot.org> | 2026-02-27 20:56:20 +0100 |
| commit | 7930d543a2aa68d4ad2958605827d7eb1baa91f8 (patch) | |
| tree | fe59d1f549e303a96b78d3e925d75abb70b73af0 /ui/src | |
| parent | c05bfcc2775f0e11db6e856bfcf06d0419c35d54 (diff) | |
| download | jellything-7930d543a2aa68d4ad2958605827d7eb1baa91f8.tar jellything-7930d543a2aa68d4ad2958605827d7eb1baa91f8.tar.bz2 jellything-7930d543a2aa68d4ad2958605827d7eb1baa91f8.tar.zst | |
reimplement Object as slice type
Diffstat (limited to 'ui/src')
| -rw-r--r-- | ui/src/components/admin.rs | 4 | ||||
| -rw-r--r-- | ui/src/components/home.rs | 2 | ||||
| -rw-r--r-- | ui/src/components/node_card.rs | 14 | ||||
| -rw-r--r-- | ui/src/components/node_page.rs | 18 | ||||
| -rw-r--r-- | ui/src/components/props.rs | 23 | ||||
| -rw-r--r-- | ui/src/components/user.rs | 2 | ||||
| -rw-r--r-- | ui/src/lib.rs | 3 |
7 files changed, 34 insertions, 32 deletions
diff --git a/ui/src/components/admin.rs b/ui/src/components/admin.rs index 76dfe6a..ddf49ca 100644 --- a/ui/src/components/admin.rs +++ b/ui/src/components/admin.rs @@ -61,7 +61,7 @@ markup::define!( } } - AdminUserList<'a>(ri: &'a RenderInfo<'a>, users: &'a [User<'a>]) { + AdminUserList<'a>(ri: &'a RenderInfo<'a>, users: &'a [&'a User]) { h1 { @tr(ri.lang, "admin.users") } form[method="POST", action=u_admin_new_user()] { label[for="login"] { "Login: " } @@ -73,7 +73,7 @@ markup::define!( }} } - AdminUser<'a>(ri: &'a RenderInfo<'a>, user: User<'a>) { + AdminUser<'a>(ri: &'a RenderInfo<'a>, user: &'a User) { h2 { @user.get(USER_NAME).unwrap_or("nameless user") } p { @tr(ri.lang, "tag.Ulgn") ": " @user.get(USER_LOGIN) } form[method="POST", action=u_admin_user_remove(user.get(USER_LOGIN).unwrap())] { diff --git a/ui/src/components/home.rs b/ui/src/components/home.rs index 5ae6a66..f7444eb 100644 --- a/ui/src/components/home.rs +++ b/ui/src/components/home.rs @@ -12,7 +12,7 @@ use crate::{ use jellycommon::Nku; use jellyui_locale::tr; -pub enum HomeRow { +pub enum HomeRow<'a> { Inline(Vec<Nku<'a>>), Highlight(Nku<'a>), } diff --git a/ui/src/components/node_card.rs b/ui/src/components/node_card.rs index e1baec1..2f5bae7 100644 --- a/ui/src/components/node_card.rs +++ b/ui/src/components/node_card.rs @@ -9,16 +9,16 @@ use crate::{ components::{node_page::aspect_class, props::Props}, }; use jellycommon::{ - jellyobject::Object, + jellyobject::{EMPTY, Object}, routes::{u_image, u_image_fallback_person, u_node_slug, u_node_slug_player}, *, }; markup::define! { NodeCard<'a>(ri: &'a RenderInfo<'a>, nku: &'a Nku<'a>) { - @let node = nku.node; + @let node = &nku.node; @let slug = node.get(NO_SLUG).unwrap_or_default(); - div[class=&format!("card {}", aspect_class(node))] { + div[class=&format!("card {}", aspect_class(&node))] { .poster { a[href=u_node_slug(&slug)] { img[src=cover_image(&node, 512), loading="lazy"]; @@ -44,7 +44,7 @@ markup::define! { } NodeCardWide<'a>(ri: &'a RenderInfo<'a>, nku: Nku<'a>) { - @let node = nku.node; + @let node = &nku.node; @let slug = node.get(NO_SLUG).unwrap_or_default(); div[class="card wide"] { div[class=&format!("poster {}", aspect_class(node))] { @@ -66,9 +66,9 @@ markup::define! { } NodeCardHightlight<'a>(ri: &'a RenderInfo<'a>, nku: &'a Nku<'a>) { - @let node = nku.node; + @let node = &nku.node; @let slug = node.get(NO_SLUG).unwrap_or_default(); - @let backdrop = u_image(node.get(NO_PICTURES).unwrap_or_default().get(PICT_BACKDROP).unwrap_or_default(), 2048); + @let backdrop = u_image(node.get(NO_PICTURES).unwrap_or(EMPTY).get(PICT_BACKDROP).unwrap_or_default(), 2048); div[class="card highlight", style=format!("background-image: url(\"{backdrop}\")")] { .inner { div.overview { @@ -92,7 +92,7 @@ markup::define! { } fn cover_image(node: &Object, size: usize) -> String { - if let Some(cover) = node.get(NO_PICTURES).unwrap_or_default().get(PICT_COVER) { + if let Some(cover) = node.get(NO_PICTURES).unwrap_or(EMPTY).get(PICT_COVER) { return u_image(cover, size); } if let Some(title) = node.get(NO_TITLE) diff --git a/ui/src/components/node_page.rs b/ui/src/components/node_page.rs index 5cd71ce..2a5848b 100644 --- a/ui/src/components/node_page.rs +++ b/ui/src/components/node_page.rs @@ -6,7 +6,7 @@ use crate::{RenderInfo, components::props::Props, page}; use jellycommon::{ - jellyobject::{Object, Tag, TypedTag}, + jellyobject::{EMPTY, Object, Tag, TypedTag}, routes::{u_image, u_node_slug_player}, *, }; @@ -30,9 +30,9 @@ page!(Player<'_>, |x| x markup::define! { NodePage<'a>(ri: &'a RenderInfo<'a>, nku: Nku<'a>) { - @let node = nku.node; + @let node = &nku.node; @let slug = node.get(NO_SLUG).unwrap_or_default(); - @let pics = node.get(NO_PICTURES).unwrap_or_default(); + @let pics = node.get(NO_PICTURES).unwrap_or(EMPTY); @if let Some(path) = pics.get(PICT_BACKDROP) { img.backdrop[src=u_image(path, 2048)]; } @@ -106,7 +106,7 @@ markup::define! { details { summary { @tr(ri.lang, "tag.iden") } table { - @for (key, value) in idents.entries::<&str>() { tr { + @for (key, value) in idents.entries::<str>() { tr { td { @tr(ri.lang, &format!("tag.iden.{key}")) } @if let Some(url) = external_id_url(key, value) { td { a[href=url] { pre { @value } } } @@ -130,13 +130,13 @@ markup::define! { summary { @tr(ri.lang, "tag.msrc") } table { tr { th {"Attribute"} th {"Source"} } - @for (key, source) in node.get(NO_METASOURCE).unwrap_or_default().entries::<Tag>() { tr { + @for (key, source) in node.get(NO_METASOURCE).unwrap_or(EMPTY).entries::<Tag>() { tr { td { @tr(ri.lang, &format!("tag.{key}")) } td { @tr(ri.lang, &format!("tag.msrc.{source}")) } }} @for nkey in [NO_PICTURES, NO_IDENTIFIERS, NO_RATINGS] { - @let nob = node.get(nkey).unwrap_or_default(); - @for (key, source) in nob.get(NO_METASOURCE).unwrap_or_default().entries::<Tag>() { tr { + @let nob = node.get(nkey).unwrap_or(EMPTY); + @for (key, source) in nob.get(NO_METASOURCE).unwrap_or(EMPTY).entries::<Tag>() { tr { td { @tr(ri.lang, &format!("tag.{nkey}")) ": " @tr(ri.lang, &format!("tag.{nkey}.{key}")) } td { @tr(ri.lang, &format!("tag.msrc.{source}")) } }} @@ -158,7 +158,7 @@ markup::define! { Player<'a>(ri: &'a RenderInfo<'a>, nku: Nku<'a>) { @let _ = ri; - @let pics = nku.node.get(NO_PICTURES).unwrap_or_default(); + @let pics = nku.node.get(NO_PICTURES).unwrap_or(EMPTY); video[id="player", poster=pics.get(PICT_COVER).map(|p| u_image(p, 2048))] {} } } @@ -169,7 +169,7 @@ markup::define! { // start * 0.8 + end * 0.2 // } -pub fn aspect_class(node: Object<'_>) -> &'static str { +pub fn aspect_class(node: &Object) -> &'static str { let kind = node.get(NO_KIND).unwrap_or(KIND_COLLECTION); match kind { KIND_VIDEO | KIND_EPISODE => "aspect-thumb", diff --git a/ui/src/components/props.rs b/ui/src/components/props.rs index e672919..db59019 100644 --- a/ui/src/components/props.rs +++ b/ui/src/components/props.rs @@ -9,38 +9,39 @@ use crate::{ format::{format_count, format_duration}, }; use chrono::DateTime; -use jellycommon::{jellyobject::TypedTag, *}; +use jellycommon::{ + jellyobject::{EMPTY, TypedTag}, + *, +}; use jellyui_locale::tr; -use std::marker::PhantomData; markup::define! { Props<'a>(ri: &'a RenderInfo<'a>, nku: &'a Nku<'a>, full: bool) { - @let node = nku.node; .props { - @if let Some(dur) = node.get(NO_DURATION) { + @if let Some(dur) = nku.node.get(NO_DURATION) { p { @format_duration(dur) } } - // @if let Some(res) = node.get(NO_TRACK) { + // @if let Some(res) = nku.node.get(NO_TRACK) { // p { @m.resolution_name() } // } - @if let Some(d) = node.get(NO_RELEASEDATE) { + @if let Some(d) = nku.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) { + @match nku.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()) } + // @if !nku.node.children.is_empty() { + // p { @format!("{} items", nku.node.children.len()) } // } - @for (kind, value) in node.get(NO_RATINGS).unwrap_or_default().entries::<f64>() { - @match TypedTag(kind, PhantomData) { + @for (kind, value) in nku.node.get(NO_RATINGS).unwrap_or(EMPTY).entries::<f64>() { + @match TypedTag::new(kind) { RTYP_YOUTUBE_LIKES => {p.likes{ @format_count(value as usize) " Likes" }} RTYP_YOUTUBE_VIEWS => {p{ @format_count(value as usize) " Views" }} RTYP_YOUTUBE_SUBSCRIBERS => {p{ @format_count(value as usize) " Subscribers" }} diff --git a/ui/src/components/user.rs b/ui/src/components/user.rs index 9dabffc..a964696 100644 --- a/ui/src/components/user.rs +++ b/ui/src/components/user.rs @@ -14,7 +14,7 @@ use jellyui_locale::tr; page!(UserSettings<'_>, |x| tr(x.ri.lang, "settings")); markup::define! { - UserSettings<'a>(ri: &'a RenderInfo<'a>, user: User<'a>) { + UserSettings<'a>(ri: &'a RenderInfo<'a>, user: &'a User) { h1 { @tr(ri.lang, "settings") } h2 { @tr(ri.lang, "settings.account") } diff --git a/ui/src/lib.rs b/ui/src/lib.rs index 93dd38a..76e2018 100644 --- a/ui/src/lib.rs +++ b/ui/src/lib.rs @@ -3,6 +3,7 @@ which is licensed under the GNU Affero General Public License (version 3); see /COPYING. Copyright (C) 2026 metamuffin <metamuffin.org> */ +#![feature(phantom_variance_markers)] pub mod components; pub(crate) mod format; mod scaffold; @@ -33,7 +34,7 @@ pub trait Page { } pub struct RenderInfo<'a> { - pub user: Option<Object<'a>>, + pub user: Option<&'a Object>, pub message: Option<(&'a str, &'a str)>, pub lang: &'a str, pub status_message: Option<&'a str>, |