2025-01-25 14:30:08 +01:00
|
|
|
use dioxus::prelude::*;
|
|
|
|
|
|
|
|
use crate::domain::entities::site::{Block, PageContent, Post};
|
|
|
|
|
2025-01-25 15:21:38 +01:00
|
|
|
use super::{meta, server::get_posts};
|
2025-01-25 14:30:08 +01:00
|
|
|
|
|
|
|
#[component]
|
|
|
|
pub fn Page() -> Element {
|
|
|
|
let page = meta::page();
|
|
|
|
let info = page.data.info;
|
|
|
|
|
|
|
|
rsx! {
|
|
|
|
h2 { "Page {info.title}" }
|
|
|
|
match page.data.content {
|
|
|
|
PageContent::Single { content } => rsx! {
|
|
|
|
PostElement { post: content }
|
|
|
|
},
|
|
|
|
PageContent::Collection { kind: _, collection_id } => {
|
|
|
|
rsx! {
|
|
|
|
SuspenseBoundary { fallback: |_context: SuspenseContext| rsx! { "..." },
|
2025-01-25 15:21:38 +01:00
|
|
|
Collection { collection_id }
|
2025-01-25 14:30:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[component]
|
|
|
|
pub fn Collection(collection_id: String) -> Element {
|
|
|
|
let site = meta::site();
|
|
|
|
let posts =
|
|
|
|
use_server_future(move || get_posts(site.info.domain.clone(), collection_id.clone()))?
|
|
|
|
.suspend()?;
|
|
|
|
|
|
|
|
let result = match &*posts.read() {
|
|
|
|
Ok(posts) => rsx! {
|
|
|
|
for post in posts.data.clone() {
|
|
|
|
PostElement { post }
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Err(err) => {
|
|
|
|
rsx! {
|
|
|
|
h1 { "FATAL ERROR: {err}" }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
result
|
2025-01-25 15:21:38 +01:00
|
|
|
}
|
2025-01-25 14:30:08 +01:00
|
|
|
|
|
|
|
#[component]
|
|
|
|
pub fn PostElement(post: Post) -> Element {
|
|
|
|
rsx! {
|
|
|
|
for block in post.blocks {
|
|
|
|
BlockElement { block }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[component]
|
|
|
|
pub fn BlockElement(block: Block) -> Element {
|
|
|
|
match block {
|
|
|
|
Block::Text { text } => rsx! {
|
|
|
|
p { "{text}" }
|
|
|
|
},
|
|
|
|
Block::Gallery { images } => rsx! {
|
|
|
|
for image in images {
|
|
|
|
img { src: "{image.src}", alt: "{image.caption}" }
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|