2023-04-07 17:16:43 -05:00
//! # Rust Letter Frontend
//!
//! Rendering functions for the site using [Dioxus](https://dioxuslabs.com/).
#![ allow(non_snake_case) ]
2023-04-13 12:51:25 -05:00
mod components ;
pub mod utils ;
2023-04-07 17:16:43 -05:00
/// 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 ::* ;
2023-04-09 11:27:28 -05:00
use rust_embed ::RustEmbed ;
2023-04-13 12:51:25 -05:00
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 ::* ;
2023-04-07 17:16:43 -05:00
2023-04-08 20:47:51 -05:00
#[ cfg(any(target_family = " wasm " )) ]
2023-04-09 11:27:28 -05:00
use dioxus_helmet ::Helmet ;
#[ cfg(any(target_family = " wasm " )) ]
2023-04-13 12:51:25 -05:00
use dioxus_router ::{ Link , Route , Router , Redirect } ;
2023-04-12 17:25:14 -05:00
#[ cfg(any(target_family = " wasm " )) ]
use dioxus_use_storage ::use_local_storage ;
2023-04-11 19:42:46 -05:00
2023-04-07 17:16:43 -05:00
#[ derive(RustEmbed) ]
#[ folder = " data/poems " ]
pub struct Poems ;
2023-04-13 12:51:25 -05:00
#[ cfg(target_family = " wasm " ) ]
2023-04-08 20:47:51 -05:00
pub fn DioxusApp ( cx : Scope ) -> Element {
2023-04-12 17:25:14 -05:00
// use dioxus_router::Redirect;
2023-04-09 11:27:28 -05:00
2023-04-08 20:47:51 -05:00
cx . render ( rsx! {
Router {
2023-04-13 12:51:25 -05:00
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 , }
}
2023-04-09 11:27:28 -05:00
Route { to : " " , PageNotFound { } }
2023-04-08 20:47:51 -05:00
}
} )
}
2023-04-09 11:27:28 -05:00
#[ cfg(target_family = " wasm " ) ]
fn PageNotFound ( cx : Scope ) -> Element {
cx . render ( rsx! {
p { " That page doesn't exist, sorry! " }
Redirect { to : " / " }
} )
}
2023-04-11 19:42:46 -05:00
2023-04-07 17:16:43 -05:00
/// Renders the app and returns the rendered Element.
2023-04-11 19:42:46 -05:00
pub fn HomePage ( cx : Scope < DarkModeProps > ) -> Element {
2023-04-12 17:25:14 -05:00
#[ cfg(any(target_family = " unix " , target_family = " windows " )) ]
2023-04-11 19:42:46 -05:00
let slug = cx . props . slug . clone ( ) . expect ( " Slug for dark mode redirect. " ) ;
2023-04-12 17:25:14 -05:00
#[ cfg(target_family = " wasm " ) ]
let slug = " " . to_string ( ) ;
let title = " A Letter to the Void " . to_string ( ) ;
2023-04-08 20:47:51 -05:00
cx . render ( rsx! {
2023-04-07 17:16:43 -05:00
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 " ,
2023-04-13 12:51:25 -05:00
Title { title : title , is_html : false }
2023-04-11 22:37:23 -05:00
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 " ,
2023-04-10 20:37:40 -05:00
p { class : " text-lg text-center " ,
" Welcome, and I hope you enjoy your stay! "
2023-04-11 22:37:23 -05:00
br { }
2023-04-10 20:37:40 -05:00
" \" 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. "
2023-04-11 22:37:23 -05:00
br { }
2023-04-10 20:37:40 -05:00
" 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 "
}
}
2023-04-13 12:51:25 -05:00
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 ( ) ) }
2023-04-11 19:42:46 -05:00
NavigationButton { title : " See All Entries " . to_string ( ) , slug : " /poems " . to_string ( ) }
2023-04-13 12:51:25 -05:00
Footer { }
2023-04-07 17:16:43 -05:00
}
}
2023-04-08 20:47:51 -05:00
} )
2023-04-07 17:16:43 -05:00
}
2023-04-10 20:37:40 -05:00
/// Renders the app and returns the rendered Element.
2023-04-11 19:42:46 -05:00
pub fn PoemListPage ( cx : Scope < DarkModeProps > ) -> Element {
2023-04-10 20:37:40 -05:00
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 " ,
2023-04-13 12:51:25 -05:00
Title { title : " A Letter to the Void " . to_string ( ) , is_html : false }
2023-04-11 19:42:46 -05:00
BackToHomePage { }
2023-04-10 20:37:40 -05:00
PoemList { }
2023-04-11 19:42:46 -05:00
BackToHomePage { }
2023-04-13 12:51:25 -05:00
Footer { }
2023-04-10 20:37:40 -05:00
}
}
} )
}
2023-04-08 20:47:51 -05:00
pub fn PoemPage ( cx : Scope < PoemRequest > ) -> Element {
2023-04-12 17:25:14 -05:00
#[ cfg(any(target_family = " unix " , target_family = " windows " )) ]
2023-04-11 19:42:46 -05:00
let slug = cx . props . slug . clone ( ) ;
2023-04-12 17:25:14 -05:00
#[ cfg(target_family = " wasm " ) ]
let slug = String ::from (
dioxus_router ::use_route ( cx )
. segment ( " slug " )
. expect ( " No slug specified. " ) ,
) ;
2023-04-11 19:42:46 -05:00
let dark_mode = cx
. props
. dark_mode
. clone ( )
. expect ( " Dark mode prop not passed. " ) ;
2023-04-08 20:47:51 -05:00
cx . render ( rsx! {
div { class : " min-h-screen font-nerd bg-alice-werefox-grey-light dark:bg-alice-werefox-grey " ,
2023-04-09 12:34:40 -05:00
div { class : " container space-y-4 mx-auto p-4 " ,
2023-04-11 19:42:46 -05:00
BackToHomePage { }
2023-04-13 12:51:25 -05:00
GetPoem { slug : slug . clone ( ) , dark_mode : dark_mode }
2023-04-11 19:42:46 -05:00
div { class : " grid md:grid-cols-4 md:grid-rows-1 grid-cols-1 grid-rows-4 gap-y-4 " ,
2023-04-13 12:51:25 -05:00
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 ( ) ) }
2023-04-10 20:37:40 -05:00
}
2023-04-11 19:42:46 -05:00
BackToHomePage { }
2023-04-13 12:51:25 -05:00
Footer { }
2023-04-11 19:42:46 -05:00
}
2023-04-10 18:19:02 -05:00
}
2023-04-08 20:47:51 -05:00
} )
2023-04-07 17:16:43 -05:00
}
}