2023-04-13 12:51:25 -05:00
|
|
|
use crate::components::void_buttons::*;
|
|
|
|
use crate::components::void_title::*;
|
2023-04-18 19:33:44 -05:00
|
|
|
use crate::utils::prop_structs::VoidProps;
|
|
|
|
use crate::utils::{prop_structs::PoemChildren, user_prefs::ThemedComponent};
|
2023-04-16 21:46:10 -05:00
|
|
|
use dioxus::prelude::*;
|
2023-04-13 12:51:25 -05:00
|
|
|
|
2023-04-18 19:33:44 -05:00
|
|
|
pub fn PoemList(cx: Scope<VoidProps>) -> Element {
|
|
|
|
let poem_list = cx.props.poem_database.get_poem_list();
|
2023-04-13 12:51:25 -05:00
|
|
|
cx.render(rsx! {
|
|
|
|
ul { class: "flex flex-col space-y-4",
|
|
|
|
poem_list.into_iter().map(|p| {
|
2023-04-18 19:33:44 -05:00
|
|
|
let slug = format!("/poems/{}", p.0);
|
2023-04-13 12:51:25 -05:00
|
|
|
rsx!{
|
2023-04-18 19:33:44 -05:00
|
|
|
NavigationButton { title: p.1, slug: slug, user_prefs: cx.props.user_prefs.clone() }
|
2023-04-13 12:51:25 -05:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn MakePoem<'a>(cx: Scope<'a, PoemChildren<'a>>) -> Element {
|
|
|
|
cx.render(rsx! {
|
|
|
|
div { class: "flex-col space-y-4",
|
|
|
|
&cx.props.children
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-04-18 19:33:44 -05:00
|
|
|
pub fn GetPoem(cx: Scope<VoidProps>) -> Element {
|
|
|
|
let poem_database = &cx.props.poem_database;
|
|
|
|
let slug = String::from(&cx.props.slug.clone().expect("No slug specified."));
|
|
|
|
let poem_struct = poem_database.get_poem(slug.clone());
|
2023-04-13 12:51:25 -05:00
|
|
|
cx.render(rsx! {
|
2023-04-18 19:33:44 -05:00
|
|
|
Title { title: poem_struct.title.clone(), is_html: true, user_prefs: cx.props.user_prefs.clone() }
|
2023-04-13 12:51:25 -05:00
|
|
|
MakePoem{
|
2023-04-18 19:33:44 -05:00
|
|
|
PoemContent { slug: slug, poem_database: poem_database.clone(), user_prefs: cx.props.user_prefs.clone() }
|
2023-04-13 12:51:25 -05:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-04-18 19:33:44 -05:00
|
|
|
pub fn PoemContent(cx: Scope<VoidProps>) -> Element {
|
2023-04-17 18:04:18 -05:00
|
|
|
let (user_theme, user_font) = cx.props.user_prefs.get_pref_classes(ThemedComponent::Card);
|
2023-04-18 19:33:44 -05:00
|
|
|
let slug = cx
|
2023-04-13 12:51:25 -05:00
|
|
|
.props
|
2023-04-18 19:33:44 -05:00
|
|
|
.slug
|
|
|
|
.as_ref()
|
|
|
|
.expect("Received slug for poem selection.");
|
|
|
|
let content = &cx
|
|
|
|
.props
|
|
|
|
.poem_database
|
|
|
|
.poem_hashmap
|
|
|
|
.get(slug)
|
|
|
|
.expect("Grabbed poem stuct from databse.")
|
|
|
|
.content
|
|
|
|
.clone();
|
|
|
|
let creation_date = &cx
|
|
|
|
.props
|
|
|
|
.poem_database
|
|
|
|
.poem_hashmap
|
|
|
|
.get(slug)
|
|
|
|
.expect("Grabbed poem struct from database.")
|
2023-04-13 12:51:25 -05:00
|
|
|
.creation_date
|
2023-04-18 19:33:44 -05:00
|
|
|
.clone();
|
2023-04-13 12:51:25 -05:00
|
|
|
#[cfg(any(target_family = "unix", target_family = "windows"))]
|
|
|
|
return cx.render(rsx! {
|
|
|
|
div { class: "flex p-2 mx-auto max-w-full justify-center",
|
2023-04-17 18:04:18 -05:00
|
|
|
details { class: "group p-4 max-w-fit space-y-4 ring-4 {user_theme} {user_font}",
|
|
|
|
summary { class: "group-open:before:content-['Close'] before:content-['Open'] flex justify-center p-2 hover:animate-yip transition ring-2 {user_theme} {user_font}",
|
2023-04-13 12:51:25 -05:00
|
|
|
}
|
2023-06-14 15:46:55 -05:00
|
|
|
div { class: "flex flex-col space-y-4 py-4 ml-4 mr-4", "{content}\n\n\nPublished: {creation_date}"
|
2023-04-13 12:51:25 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
#[cfg(target_family = "wasm")]
|
2023-06-14 15:46:55 -05:00
|
|
|
let publish_string = "\u{003C}br\u{003E}\u{003C}br\u{003E}\u{003C}br\u{003E}Published: ";
|
|
|
|
#[cfg(target_family = "wasm")]
|
2023-04-13 12:51:25 -05:00
|
|
|
return cx.render(rsx! {
|
|
|
|
div { class: "flex p-2 mx-auto max-w-full justify-center",
|
2023-04-17 18:04:18 -05:00
|
|
|
details { class: "group p-4 max-w-fit space-y-4 ring-4 {user_theme} {user_font}",
|
|
|
|
summary { class: "group-open:before:content-['Close'] before:content-['Open'] flex justify-center p-2 hover:animate-yip transition ring-2 {user_theme} {user_font}",
|
2023-04-13 12:51:25 -05:00
|
|
|
}
|
2023-06-14 15:46:55 -05:00
|
|
|
div { class: "flex flex-col space-y-4 py-4 ml-4 mr-4",
|
|
|
|
dangerous_inner_html: "{content}{publish_string}{creation_date}",
|
2023-04-13 12:51:25 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2023-04-16 21:46:10 -05:00
|
|
|
}
|