info-werefox-cafe/void-fe/src/lib.rs

146 lines
6.0 KiB
Rust
Raw Normal View History

//! # Rust Letter Frontend
//!
//! Rendering functions for the site using [Dioxus](https://dioxuslabs.com/).
#![allow(non_snake_case)]
mod components;
pub mod utils;
/// A module that handles the functions needed
/// to render the site.
pub mod void_app {
// import the prelude to get access to the `rsx!` macro and the `Scope` and `Element` types
pub use dioxus::prelude::*;
use rust_embed::RustEmbed;
use crate::components::void_buttons::*;
use crate::components::void_footer::*;
use crate::components::void_poem::*;
use crate::components::void_title::*;
use crate::utils::helpers;
use crate::utils::prop_structs::*;
#[cfg(any(target_family = "wasm"))]
use dioxus_helmet::Helmet;
#[cfg(any(target_family = "wasm"))]
use dioxus_router::{Link, Route, Router, Redirect};
#[cfg(any(target_family = "wasm"))]
use dioxus_use_storage::use_local_storage;
#[derive(RustEmbed)]
#[folder = "data/poems"]
pub struct Poems;
#[cfg(target_family = "wasm")]
pub fn DioxusApp(cx: Scope) -> Element {
// use dioxus_router::Redirect;
cx.render(rsx! {
Router {
Route { to: "/", self::HomePage { dark_mode: true, } }
Route { to: "/poems",
PoemListPage { slug: "".to_string(), dark_mode: true, }
}
Route { to: "/poems/:slug",
PoemPage { slug: "".to_string(), dark_mode: true, }
}
Route { to: "", PageNotFound {} }
}
})
}
#[cfg(target_family = "wasm")]
fn PageNotFound(cx: Scope) -> Element {
cx.render(rsx! {
p { "That page doesn't exist, sorry!" }
Redirect { to: "/" }
})
}
/// Renders the app and returns the rendered Element.
pub fn HomePage(cx: Scope<DarkModeProps>) -> Element {
#[cfg(any(target_family = "unix", target_family = "windows"))]
let slug = cx.props.slug.clone().expect("Slug for dark mode redirect.");
#[cfg(target_family = "wasm")]
let slug = "".to_string();
let title = "A Letter to the Void".to_string();
cx.render(rsx!{
div { class: "min-h-screen font-nerd bg-alice-werefox-grey-light dark:bg-alice-werefox-grey",
div { class: "container space-y-4 mx-auto p-4",
Title { title: title, is_html: false }
div { class: "flex p-4 ml-2 mr-2 ring-4 bg-alice-werefox-grey-lightest dark:bg-alice-werefox-grey-dark ring-alice-werefox-red-dark dark:ring-alice-werefox-red text-alice-werefox-grey-dark dark:text-alice-werefox-grey-light",
p { class: "text-lg text-center",
"Welcome, and I hope you enjoy your stay!"
br {}
"\"A Letter to the Void\" is a passion project of mine in which I wrote poems about my past life experiences, present, and hopes for the future throughout my transition."
br {}
"The topics range from my feelings through transitioning (of course), past abuse, mental health exploration, and an overall journey to grow and become a better creature."
br {}
"I hope you enjoy the time you spend here, and sincerely, thank you."
br {}
br {}
"🖤 Alice Icehart Werefox"
}
}
NavigationButton { title: "See Latest Entry".to_string(), slug: helpers::get_latest_entry(slug.clone()) }
NavigationButton { title: "See Oldest Entry".to_string(), slug: helpers::get_oldest_entry(slug.clone()) }
NavigationButton { title: "See All Entries".to_string(), slug: "/poems".to_string() }
Footer {}
}
}
})
}
/// Renders the app and returns the rendered Element.
pub fn PoemListPage(cx: Scope<DarkModeProps>) -> Element {
cx.render(rsx!{
div { class: "min-h-screen font-nerd bg-alice-werefox-grey-light dark:bg-alice-werefox-grey",
div { class: "container space-y-4 mx-auto p-4",
Title { title: "A Letter to the Void".to_string(), is_html: false }
BackToHomePage {}
PoemList {}
BackToHomePage {}
Footer {}
}
}
})
}
pub fn PoemPage(cx: Scope<PoemRequest>) -> Element {
#[cfg(any(target_family = "unix", target_family = "windows"))]
let slug = cx.props.slug.clone();
#[cfg(target_family = "wasm")]
let slug = String::from(
dioxus_router::use_route(cx)
.segment("slug")
.expect("No slug specified."),
);
let dark_mode = cx
.props
.dark_mode
.clone()
.expect("Dark mode prop not passed.");
cx.render(rsx!{
div { class: "min-h-screen font-nerd bg-alice-werefox-grey-light dark:bg-alice-werefox-grey",
div { class: "container space-y-4 mx-auto p-4",
BackToHomePage {}
GetPoem { slug: slug.clone(), dark_mode: dark_mode }
div { class: "grid md:grid-cols-4 md:grid-rows-1 grid-cols-1 grid-rows-4 gap-y-4",
NavigationButton { title: "Oldest".to_string(), slug: helpers::get_oldest_entry(slug.clone()) }
NavigationButton { title: "Previous".to_string(), slug: helpers::get_previous_entry(slug.clone()) }
NavigationButton { title: "Next".to_string(), slug: helpers::get_next_entry(slug.clone()) }
NavigationButton { title: "Latest".to_string(), slug: helpers::get_latest_entry(slug.clone()) }
}
BackToHomePage {}
Footer {}
}
}
})
}
}