Updated dependencies so dioxus will run again; Fixed some issues with the dioxus build.

This commit is contained in:
Ada Werefox 2023-06-13 21:44:53 -05:00
parent 06370ffa85
commit 95dec6138b
5 changed files with 53 additions and 14 deletions

File diff suppressed because one or more lines are too long

View File

@ -19,6 +19,10 @@ dioxus-helmet = "0.2.4"
dioxus-use-storage = "0.3.0"
rand = "0.8.5"
[dependencies.getrandom]
version = "0.2.9"
features = ["js"]
[dependencies.serde]
version = "1.0.160"
features = ["derive"]

View File

@ -14,7 +14,7 @@ pub fn RenderContent(cx: Scope<ContentProps>) -> Element {
});
#[cfg(target_family = "wasm")]
return cx.render(rsx!{
div { class: "flex p-4 ml-2 mr-2 ring-4",
div { class: "flex p-4 md:pl-8 md:pr-8 ml-2 mr-2 text-lg text-center ring-4 {user_theme} {user_font}",
dangerous_inner_html: "{content}",
}
});

View File

@ -33,21 +33,19 @@ pub mod void_app {
#[cfg(target_family = "wasm")]
pub fn DioxusApp(cx: Scope) -> Element {
// use dioxus_router::Redirect;
let mut poem_database = PoemDatabase::new();
poem_database.build_poem_database();
let user_prefs = UserPrefs::new(ThemePref::Auto, FontPref::OpenDyslexic);
cx.render(rsx! {
div { class: "bg-alice-werefox-grey-lightest ring-alice-werefox-red-dark text-alice-werefox-grey-dark dark:bg-alice-werefox-grey-dark dark:ring-alice-werefox-red dark:text-alice-werefox-grey-light let button_classes hover:text-alice-werefox-blue-dark hover:ring-alice-werefox-blue dark:hover:text-alice-werefox-blue-light dark:hover:ring-alice-werefox-blue hover:animate-yip transition" }
Router {
Route { to: "/",
self::HomePage { user_prefs }
}
Route { to: "/poems", PoemListPage { user_prefs } }
Route { to: "/poems/:slug", PoemPage { slug: "".to_string(), user_prefs } }
Route { to: "/settings", SettingsPage { user_prefs } }
Route { to: "/settings/dark", SettingsPage { user_prefs } }
Route { to: "/settings/font", SettingsPage { user_prefs } }
Route { to: "/", HomePage { slug: "/".to_string(), poem_database: poem_database.clone(), user_prefs: user_prefs.clone(), } }
Route { to: "/poems", PoemListPage { slug: "/poems".to_string(), poem_database: poem_database.clone(), user_prefs: user_prefs.clone(), } }
Route { to: "/poems/:slug", PoemPage { slug: "".to_string(), poem_database: poem_database.clone(), user_prefs: user_prefs.clone(), } }
Route { to: "/settings", SettingsPage { theme: user_prefs.clone().get_theme(), font: user_prefs.clone().get_font() } }
Route { to: "/settings/dark", SettingsPage { theme: user_prefs.clone().get_theme(), font: user_prefs.clone().get_font() } }
Route { to: "/settings/font", SettingsPage { theme: user_prefs.clone().get_theme(), font: user_prefs.clone().get_font() } }
Route { to: "", PageNotFound {} }
}
})
@ -107,7 +105,12 @@ pub mod void_app {
let user_prefs = cx.props.user_prefs.clone();
let (user_theme, user_font) = user_prefs.get_pref_classes(ThemedComponent::Page);
#[cfg(any(target_family = "unix", target_family = "windows"))]
let slug = &cx.props.slug.as_ref().expect("A slug was given in the pops.").clone();
let slug = &cx
.props
.slug
.as_ref()
.expect("A slug was given in the pops.")
.clone();
#[cfg(target_family = "wasm")]
let slug = String::from(
dioxus_router::use_route(cx)

View File

@ -21,6 +21,7 @@ impl PoemDatabase {
}
// There's no need to actually make a database yet, but maybe in the future...
#[cfg(any(target_family = "unix", target_family = "windows"))]
pub async fn build_poem_database(&mut self) {
for p in Poems::iter() {
let filename = p.to_string();
@ -48,6 +49,36 @@ impl PoemDatabase {
}
self.poem_list.sort_by_key(|k| k.0.clone())
}
#[cfg(any(target_family = "wasm"))]
pub fn build_poem_database(&mut self) {
for p in Poems::iter() {
let filename = p.to_string();
let poem_content = Poems::get(&filename).expect("Found poem {filename:?}");
let mut poem_to_str = std::str::from_utf8(poem_content.data.as_ref())
.expect("Poem is valid UT8.")
.lines();
let poem_title = poem_to_str.next().expect("No title specified.");
let poem_content = poem_to_str.into_iter().collect::<Vec<&str>>().join("\n");
let poem_title_to_html_string =
markdown::to_html_with_options(poem_title, &Options::gfm()).unwrap();
let poem_content_to_html_string =
markdown::to_html_with_options(poem_content.as_str(), &Options::gfm()).unwrap();
let mut split_filename = filename.trim_end_matches(".md").split("_");
let creation_date = split_filename.next().expect("Obtained creation date");
let slug = split_filename.next().expect("Obtained slug");
self.poem_list
.push((creation_date.to_string(), slug.to_string()));
let poem_struct = PoemStruct {
title: poem_title_to_html_string.to_string(),
content: poem_content_to_html_string,
creation_date: creation_date.to_string(),
};
self.poem_hashmap.insert(slug.to_string(), poem_struct);
}
self.poem_list.sort_by_key(|k| k.0.clone())
}
pub fn get_poem(&self, slug: String) -> PoemStruct {
self.poem_hashmap
.get(slug.as_str())
@ -133,7 +164,7 @@ impl PoemDatabase {
None => format!("/poems/{current}"),
}
}
// #[cfg(not(target_family = "wasm"))]
pub fn get_random_entry(&self) -> String {
let poem_list = self.poem_list.clone();
let mut rng = rand::thread_rng();
@ -142,6 +173,7 @@ impl PoemDatabase {
.expect("Got a valid entry")
.1
.clone();
// let random_entry = "introductions";
format!("/poems/{random_entry}")
}
}