diff options
| author | metamuffin <metamuffin@disroot.org> | 2026-01-23 04:19:24 +0100 |
|---|---|---|
| committer | metamuffin <metamuffin@disroot.org> | 2026-01-23 04:19:24 +0100 |
| commit | 3671a4e07565c86f8071fb2309f463aeaf684ba3 (patch) | |
| tree | 9a9057c7dcc174ada17a45a195502ff94b2f2946 /ui/src/lib.rs | |
| parent | 10cdaaa30a6b4a187797434dc8d959780f0e8fbf (diff) | |
| download | jellything-3671a4e07565c86f8071fb2309f463aeaf684ba3.tar jellything-3671a4e07565c86f8071fb2309f463aeaf684ba3.tar.bz2 jellything-3671a4e07565c86f8071fb2309f463aeaf684ba3.tar.zst | |
move ui code around
Diffstat (limited to 'ui/src/lib.rs')
| -rw-r--r-- | ui/src/lib.rs | 88 |
1 files changed, 20 insertions, 68 deletions
diff --git a/ui/src/lib.rs b/ui/src/lib.rs index 6dbc837..72109d4 100644 --- a/ui/src/lib.rs +++ b/ui/src/lib.rs @@ -3,28 +3,17 @@ which is licensed under the GNU Affero General Public License (version 3); see /COPYING. Copyright (C) 2026 metamuffin <metamuffin.org> */ -pub mod account; -pub mod admin; -pub mod error; -pub mod filter_sort; -pub mod format; -pub mod home; -pub mod items; -pub mod locale; -pub mod node_card; -pub mod node_page; -pub mod props; -pub mod scaffold; -pub mod search; -pub mod stats; +mod components; +pub(crate) mod format; +pub(crate) mod locale; +mod scaffold; -use markup::DynRender; -use scaffold::{RenderInfo, Scaffold}; -use serde::{Deserialize, Serialize}; -use std::{ - path::PathBuf, - sync::{LazyLock, Mutex}, +use crate::{components::View, scaffold::Scaffold}; +use jellycommon::{ + jellyobject::{Object, Tag}, + *, }; +use serde::{Deserialize, Serialize}; pub type FlashM = Option<(String, String)>; @@ -33,59 +22,22 @@ pub type FlashM = Option<(String, String)>; pub struct Config { brand: String, slogan: String, - asset_path: PathBuf, -} - -static CONF: LazyLock<Config> = LazyLock::new(|| { - CONF_PRELOAD - .lock() - .unwrap() - .take() - .expect("cache config not preloaded. logic error") -}); -pub static CONF_PRELOAD: Mutex<Option<Config>> = Mutex::new(None); - -pub fn get_brand() -> String { - CONF.brand.clone() -} -pub fn get_slogan() -> String { - CONF.slogan.clone() + logo: bool, } -/// render as supertrait would be possible but is not -/// dyn compatible and I really dont want to expose generics -/// that generate rendering code because of compile speed. -pub trait Page { - fn title(&self) -> String; - fn to_render(&self) -> DynRender<'_>; - fn class(&self) -> Option<&'static str> { - None - } +pub struct RenderInfo<'a> { + pub user: Option<Object<'a>>, + pub lang: Tag, + pub status_message: Option<&'a str>, + pub config: &'a Config, } -pub fn render_page(renderinfo: &RenderInfo<'_>, page: &dyn Page) -> String { +pub fn render_view(ri: RenderInfo<'_>, view: Object<'_>) -> String { Scaffold { - class: &format!( - "{} theme-{}", - page.class().unwrap_or("custom-page"), - "dark", // todo - ), - ri: renderinfo, - title: page.title(), - main: page.to_render(), + ri: &ri, + main: View { ri: &ri, view }, + title: view.get(VIEW_TITLE).unwrap_or_default(), + class: "", } .to_string() } - -pub struct CustomPage { - pub title: String, - pub body: String, -} -impl Page for CustomPage { - fn title(&self) -> String { - self.title.clone() - } - fn to_render(&self) -> DynRender<'_> { - markup::new!(@markup::raw(&self.body)) - } -} |