diff options
| author | metamuffin <metamuffin@disroot.org> | 2026-02-27 14:40:15 +0100 |
|---|---|---|
| committer | metamuffin <metamuffin@disroot.org> | 2026-02-27 14:40:15 +0100 |
| commit | c05bfcc2775f0e11db6e856bfcf06d0419c35d54 (patch) | |
| tree | ffd0e9fcf6b476a6198287085a514cfa7940c200 /ui/src/lib.rs | |
| parent | 4ba86694e393c61107e27c4127efc0455b329524 (diff) | |
| download | jellything-c05bfcc2775f0e11db6e856bfcf06d0419c35d54.tar jellything-c05bfcc2775f0e11db6e856bfcf06d0419c35d54.tar.bz2 jellything-c05bfcc2775f0e11db6e856bfcf06d0419c35d54.tar.zst | |
ui changed before object slices
Diffstat (limited to 'ui/src/lib.rs')
| -rw-r--r-- | ui/src/lib.rs | 54 |
1 files changed, 29 insertions, 25 deletions
diff --git a/ui/src/lib.rs b/ui/src/lib.rs index d74df51..93dd38a 100644 --- a/ui/src/lib.rs +++ b/ui/src/lib.rs @@ -3,20 +3,19 @@ which is licensed under the GNU Affero General Public License (version 3); see /COPYING. Copyright (C) 2026 metamuffin <metamuffin.org> */ -mod components; +pub mod components; pub(crate) mod format; mod scaffold; +use std::borrow::Cow; + pub use jellyui_client_scripts::*; pub use jellyui_client_style::*; - -pub use components::admin_log::ServerLogPage; -pub use components::admin_log::render_log_line; pub use jellyui_locale::tr; -pub use scaffold::Scaffold; -use crate::components::View; -use jellycommon::{jellyobject::Object, *}; +use jellycommon::jellyobject::Object; +use markup::DynRender; +pub use scaffold::Scaffold; use serde::{Deserialize, Serialize}; #[rustfmt::skip] @@ -27,29 +26,34 @@ pub struct Config { pub logo: bool, } +pub trait Page { + fn title(&self) -> Cow<'static, str>; + fn ri(&self) -> &RenderInfo<'_>; + fn render(&self) -> DynRender<'_>; +} + pub struct RenderInfo<'a> { pub user: Option<Object<'a>>, + pub message: Option<(&'a str, &'a str)>, pub lang: &'a str, pub status_message: Option<&'a str>, pub config: &'a Config, } -pub fn render_view(ri: RenderInfo<'_>, view: Object<'_>) -> String { - let theme = ri - .user - .and_then(|u| u.get(USER_THEME_PRESET)) - .unwrap_or(THEME_DARK); - Scaffold { - ri: &ri, - main: View { ri: &ri, view }, - title: view.get(VIEW_TITLE).unwrap_or_default(), - class: match (theme, view.has(VIEW_PLAYER.0)) { - (THEME_DARK, true) => "theme-dark player", - (THEME_DARK, false) => "theme-dark", - (THEME_LIGHT, true) => "theme-light player", - (THEME_LIGHT, false) => "theme-light", - _ => "theme-dark", - }, - } - .to_string() +#[macro_export] +macro_rules! page { + ($t:ty, $title:stmt) => { + impl $crate::Page for $t { + fn title(&self) -> std::borrow::Cow<'static, str> { + let x: fn(&$t) -> std::borrow::Cow<'static, str> = {$title}; + x(self) + } + fn ri(&self) -> &$crate::RenderInfo<'_> { + self.ri + } + fn render(&self) -> markup::DynRender<'_> { + markup::new!(@self) + } + } + }; } |