diff --git a/Cargo.toml b/Cargo.toml index 51dc85f..7cc5462 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,13 +11,17 @@ members = [ ] [workspace.dependencies] -rocket = "=0.5.0-rc.3" -dioxus = "0.3.2" -markdown = "1.0.0-alpha.7" -dioxus-ssr = "0.3.0" -rust-embed = { version = "6.6.1" } +rocket = "=0.5.0" +dioxus = "0.5.0-alpha.0" +markdown = "1.0.0-alpha.16" +dioxus-ssr = "0.5.0-alpha.0" +rust-embed = { version = "8.3.0" } once_cell = "1.17.1" [dependencies] void-be = { path = "./void-be" } rocket = { workspace = true } + +[dependencies.dioxus] +version = "0.5.0-alpha.0" +features = ["router"] diff --git a/public/styles/tailwind.min.css b/public/styles/tailwind.min.css index 8371a3d..12e5cd4 100644 --- a/public/styles/tailwind.min.css +++ b/public/styles/tailwind.min.css @@ -1 +1 @@ -/*! tailwindcss v3.3.0 | MIT License | https://tailwindcss.com*/*,:after,:before{box-sizing:border-box;border:0 solid #e5e7eb}:after,:before{--tw-content:""}html{line-height:1.5;-webkit-text-size-adjust:100%;-moz-tab-size:4;-o-tab-size:4;tab-size:4;font-family:ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji;font-feature-settings:normal;font-variation-settings:normal}body{margin:0;line-height:inherit}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,pre,samp{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace;font-size:1em}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:initial}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}button,input,optgroup,select,textarea{font-family:inherit;font-size:100%;font-weight:inherit;line-height:inherit;color:inherit;margin:0;padding:0}button,select{text-transform:none}[type=button],[type=reset],[type=submit],button{-webkit-appearance:button;background-color:initial;background-image:none}:-moz-focusring{outline:auto}:-moz-ui-invalid{box-shadow:none}progress{vertical-align:initial}::-webkit-inner-spin-button,::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item}blockquote,dd,dl,figure,h1,h2,h3,h4,h5,h6,hr,p,pre{margin:0}fieldset{margin:0}fieldset,legend{padding:0}menu,ol,ul{list-style:none;margin:0;padding:0}textarea{resize:vertical}input::-moz-placeholder,textarea::-moz-placeholder{opacity:1;color:#9ca3af}input::placeholder,textarea::placeholder{opacity:1;color:#9ca3af}[role=button],button{cursor:pointer}:disabled{cursor:default}audio,canvas,embed,iframe,img,object,svg,video{display:block;vertical-align:middle}img,video{max-width:100%;height:auto}[hidden]{display:none}*,::backdrop,:after,:before{--tw-border-spacing-x:0;--tw-border-spacing-y:0;--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness:proximity;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:#3b82f680;--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: }.container{width:100%;margin-right:auto;margin-left:auto;padding-right:1rem;padding-left:1rem}@media (min-width:640px){.container{max-width:640px}}@media (min-width:768px){.container{max-width:768px}}@media (min-width:1024px){.container{max-width:1024px}}@media (min-width:1280px){.container{max-width:1280px;padding-right:0;padding-left:0}}@media (min-width:1536px){.container{max-width:1536px}}.mx-auto{margin-left:auto;margin-right:auto}.ml-2{margin-left:.5rem}.ml-4{margin-left:1rem}.mr-2{margin-right:.5rem}.mr-4{margin-right:1rem}.flex{display:flex}.hidden{display:none}.min-h-screen{min-height:100vh}.max-w-3xl{max-width:48rem}.max-w-fit{max-width:-moz-fit-content;max-width:fit-content}.max-w-full{max-width:100%}.basis-full{flex-basis:100%}.flex-row{flex-direction:row}.flex-col{flex-direction:column}.justify-center{justify-content:center}.space-y-4>:not([hidden])~:not([hidden]){--tw-space-y-reverse:0;margin-top:calc(1rem*(1 - var(--tw-space-y-reverse)));margin-bottom:calc(1rem*var(--tw-space-y-reverse))}.bg-alice-werefox-grey{--tw-bg-opacity:1;background-color:rgb(36 36 36/var(--tw-bg-opacity))}.bg-alice-werefox-grey-dark{--tw-bg-opacity:1;background-color:rgb(18 18 18/var(--tw-bg-opacity))}.bg-alice-werefox-grey-light{--tw-bg-opacity:1;background-color:rgb(204 204 204/var(--tw-bg-opacity))}.bg-alice-werefox-grey-lightest{--tw-bg-opacity:1;background-color:rgb(238 238 238/var(--tw-bg-opacity))}.p-2{padding:.5rem}.p-4{padding:1rem}.py-4{padding-top:1rem}.pb-4,.py-4{padding-bottom:1rem}.pt-4{padding-top:1rem}.text-center{text-align:center}.align-middle{vertical-align:middle}.font-nerd{font-family:DejaVuSansMono}.font-open{font-family:OpenDyslexic}.text-xl{font-size:1.25rem;line-height:1.75rem}.text-alice-werefox-grey-dark{--tw-text-opacity:1;color:rgb(18 18 18/var(--tw-text-opacity))}.text-alice-werefox-grey-light{--tw-text-opacity:1;color:rgb(204 204 204/var(--tw-text-opacity))}.ring-2{--tw-ring-offset-shadow:var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow:var(--tw-ring-inset) 0 0 0 calc(2px + var(--tw-ring-offset-width)) var(--tw-ring-color)}.ring-2,.ring-4{box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow,0 0 #0000)}.ring-4{--tw-ring-offset-shadow:var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow:var(--tw-ring-inset) 0 0 0 calc(4px + var(--tw-ring-offset-width)) var(--tw-ring-color)}.ring-alice-werefox-red{--tw-ring-opacity:1;--tw-ring-color:rgb(201 52 57/var(--tw-ring-opacity))}.ring-alice-werefox-red-dark{--tw-ring-opacity:1;--tw-ring-color:rgb(128 0 8/var(--tw-ring-opacity))}.transition{transition-property:color,background-color,border-color,text-decoration-color,fill,stroke,opacity,box-shadow,transform,filter,-webkit-backdrop-filter;transition-property:color,background-color,border-color,text-decoration-color,fill,stroke,opacity,box-shadow,transform,filter,backdrop-filter;transition-property:color,background-color,border-color,text-decoration-color,fill,stroke,opacity,box-shadow,transform,filter,backdrop-filter,-webkit-backdrop-filter;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.15s}@font-face{font-family:OpenDyslexic;src:url(/fonts/OpenDyslexic-Regular.otf)}@font-face{font-family:DejaVuSansMono;src:url(/fonts/DejaVuSansMono.ttf)}.before\:content-\[\'Open\'\]:before{--tw-content:"Open";content:var(--tw-content)}@keyframes yip{0%,to{transform:scale(1)}50%{transform:scale(1.01)}}.hover\:animate-yip:hover{animation:yip .1s ease-in-out}.hover\:text-alice-werefox-blue-dark:hover{--tw-text-opacity:1;color:rgb(51 0 255/var(--tw-text-opacity))}.hover\:text-alice-werefox-blue-light:hover{--tw-text-opacity:1;color:rgb(145 151 243/var(--tw-text-opacity))}.hover\:ring-alice-werefox-blue:hover{--tw-ring-opacity:1;--tw-ring-color:rgb(27 41 224/var(--tw-ring-opacity))}.group[open] .group-open\:before\:content-\[\'Close\'\]:before{--tw-content:"Close";content:var(--tw-content)}@media (prefers-color-scheme:dark){.dark\:bg-alice-werefox-grey{--tw-bg-opacity:1;background-color:rgb(36 36 36/var(--tw-bg-opacity))}.dark\:bg-alice-werefox-grey-dark{--tw-bg-opacity:1;background-color:rgb(18 18 18/var(--tw-bg-opacity))}.dark\:text-alice-werefox-grey-light{--tw-text-opacity:1;color:rgb(204 204 204/var(--tw-text-opacity))}.dark\:ring-alice-werefox-red{--tw-ring-opacity:1;--tw-ring-color:rgb(201 52 57/var(--tw-ring-opacity))}.dark\:hover\:text-alice-werefox-blue-light:hover{--tw-text-opacity:1;color:rgb(145 151 243/var(--tw-text-opacity))}.dark\:hover\:ring-alice-werefox-blue:hover{--tw-ring-opacity:1;--tw-ring-color:rgb(27 41 224/var(--tw-ring-opacity))}}@media (min-width:768px){.md\:flex-row{flex-direction:row}.md\:space-y-0>:not([hidden])~:not([hidden]){--tw-space-y-reverse:0;margin-top:calc(0px*(1 - var(--tw-space-y-reverse)));margin-bottom:calc(0px*var(--tw-space-y-reverse))}.md\:pl-8{padding-left:2rem}.md\:pr-8{padding-right:2rem}} \ No newline at end of file +/*! tailwindcss v3.4.1 | MIT License | https://tailwindcss.com*/*,:after,:before{box-sizing:border-box;border:0 solid #e5e7eb}:after,:before{--tw-content:""}:host,html{line-height:1.5;-webkit-text-size-adjust:100%;-moz-tab-size:4;-o-tab-size:4;tab-size:4;font-family:ui-sans-serif,system-ui,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji;font-feature-settings:normal;font-variation-settings:normal;-webkit-tap-highlight-color:transparent}body{margin:0;line-height:inherit}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,pre,samp{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace;font-feature-settings:normal;font-variation-settings:normal;font-size:1em}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:initial}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}button,input,optgroup,select,textarea{font-family:inherit;font-feature-settings:inherit;font-variation-settings:inherit;font-size:100%;font-weight:inherit;line-height:inherit;color:inherit;margin:0;padding:0}button,select{text-transform:none}[type=button],[type=reset],[type=submit],button{-webkit-appearance:button;background-color:initial;background-image:none}:-moz-focusring{outline:auto}:-moz-ui-invalid{box-shadow:none}progress{vertical-align:initial}::-webkit-inner-spin-button,::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item}blockquote,dd,dl,figure,h1,h2,h3,h4,h5,h6,hr,p,pre{margin:0}fieldset{margin:0}fieldset,legend{padding:0}menu,ol,ul{list-style:none;margin:0;padding:0}dialog{padding:0}textarea{resize:vertical}input::-moz-placeholder,textarea::-moz-placeholder{opacity:1;color:#9ca3af}input::placeholder,textarea::placeholder{opacity:1;color:#9ca3af}[role=button],button{cursor:pointer}:disabled{cursor:default}audio,canvas,embed,iframe,img,object,svg,video{display:block;vertical-align:middle}img,video{max-width:100%;height:auto}[hidden]{display:none}*,::backdrop,:after,:before{--tw-border-spacing-x:0;--tw-border-spacing-y:0;--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness:proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:#3b82f680;--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: }.container{width:100%;margin-right:auto;margin-left:auto;padding-right:1rem;padding-left:1rem}@media (min-width:640px){.container{max-width:640px}}@media (min-width:768px){.container{max-width:768px}}@media (min-width:1024px){.container{max-width:1024px}}@media (min-width:1280px){.container{max-width:1280px;padding-right:0;padding-left:0}}@media (min-width:1536px){.container{max-width:1536px}}.static{position:static}.mx-auto{margin-left:auto;margin-right:auto}.ml-2{margin-left:.5rem}.ml-4{margin-left:1rem}.mr-2{margin-right:.5rem}.mr-4{margin-right:1rem}.flex{display:flex}.hidden{display:none}.min-h-screen{min-height:100vh}.max-w-3xl{max-width:48rem}.max-w-fit{max-width:-moz-fit-content;max-width:fit-content}.max-w-full{max-width:100%}.basis-full{flex-basis:100%}.flex-row{flex-direction:row}.flex-col{flex-direction:column}.justify-center{justify-content:center}.space-y-4>:not([hidden])~:not([hidden]){--tw-space-y-reverse:0;margin-top:calc(1rem*(1 - var(--tw-space-y-reverse)));margin-bottom:calc(1rem*var(--tw-space-y-reverse))}.bg-alice-werefox-grey{--tw-bg-opacity:1;background-color:rgb(36 36 36/var(--tw-bg-opacity))}.bg-alice-werefox-grey-dark{--tw-bg-opacity:1;background-color:rgb(18 18 18/var(--tw-bg-opacity))}.bg-alice-werefox-grey-light{--tw-bg-opacity:1;background-color:rgb(204 204 204/var(--tw-bg-opacity))}.bg-alice-werefox-grey-lightest{--tw-bg-opacity:1;background-color:rgb(238 238 238/var(--tw-bg-opacity))}.p-2{padding:.5rem}.p-4{padding:1rem}.py-4{padding-top:1rem}.pb-4,.py-4{padding-bottom:1rem}.pt-4{padding-top:1rem}.text-center{text-align:center}.align-middle{vertical-align:middle}.font-nerd{font-family:DejaVuSansMono}.font-open{font-family:OpenDyslexic}.text-xl{font-size:1.25rem;line-height:1.75rem}.text-alice-werefox-grey-dark{--tw-text-opacity:1;color:rgb(18 18 18/var(--tw-text-opacity))}.text-alice-werefox-grey-light{--tw-text-opacity:1;color:rgb(204 204 204/var(--tw-text-opacity))}.ring-2{--tw-ring-offset-shadow:var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow:var(--tw-ring-inset) 0 0 0 calc(2px + var(--tw-ring-offset-width)) var(--tw-ring-color)}.ring-2,.ring-4{box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow,0 0 #0000)}.ring-4{--tw-ring-offset-shadow:var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow:var(--tw-ring-inset) 0 0 0 calc(4px + var(--tw-ring-offset-width)) var(--tw-ring-color)}.ring-alice-werefox-red{--tw-ring-opacity:1;--tw-ring-color:rgb(201 52 57/var(--tw-ring-opacity))}.ring-alice-werefox-red-dark{--tw-ring-opacity:1;--tw-ring-color:rgb(128 0 8/var(--tw-ring-opacity))}.transition{transition-property:color,background-color,border-color,text-decoration-color,fill,stroke,opacity,box-shadow,transform,filter,-webkit-backdrop-filter;transition-property:color,background-color,border-color,text-decoration-color,fill,stroke,opacity,box-shadow,transform,filter,backdrop-filter;transition-property:color,background-color,border-color,text-decoration-color,fill,stroke,opacity,box-shadow,transform,filter,backdrop-filter,-webkit-backdrop-filter;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.15s}@font-face{font-family:OpenDyslexic;src:url(/fonts/OpenDyslexic-Regular.otf)}@font-face{font-family:DejaVuSansMono;src:url(/fonts/DejaVuSansMono.ttf)}.before\:content-\[\'Open\'\]:before{--tw-content:"Open";content:var(--tw-content)}@keyframes yip{0%,to{transform:scale(1)}50%{transform:scale(1.01)}}.hover\:animate-yip:hover{animation:yip .1s ease-in-out}.hover\:text-alice-werefox-blue-dark:hover{--tw-text-opacity:1;color:rgb(51 0 255/var(--tw-text-opacity))}.hover\:text-alice-werefox-blue-light:hover{--tw-text-opacity:1;color:rgb(145 151 243/var(--tw-text-opacity))}.hover\:ring-alice-werefox-blue:hover{--tw-ring-opacity:1;--tw-ring-color:rgb(27 41 224/var(--tw-ring-opacity))}.group[open] .group-open\:before\:content-\[\'Close\'\]:before{--tw-content:"Close";content:var(--tw-content)}@media (min-width:768px){.md\:flex-row{flex-direction:row}.md\:space-y-0>:not([hidden])~:not([hidden]){--tw-space-y-reverse:0;margin-top:calc(0px*(1 - var(--tw-space-y-reverse)));margin-bottom:calc(0px*var(--tw-space-y-reverse))}.md\:pl-8{padding-left:2rem}.md\:pr-8{padding-right:2rem}}@media (prefers-color-scheme:dark){.dark\:bg-alice-werefox-grey{--tw-bg-opacity:1;background-color:rgb(36 36 36/var(--tw-bg-opacity))}.dark\:bg-alice-werefox-grey-dark{--tw-bg-opacity:1;background-color:rgb(18 18 18/var(--tw-bg-opacity))}.dark\:text-alice-werefox-grey-light{--tw-text-opacity:1;color:rgb(204 204 204/var(--tw-text-opacity))}.dark\:ring-alice-werefox-red{--tw-ring-opacity:1;--tw-ring-color:rgb(201 52 57/var(--tw-ring-opacity))}.dark\:hover\:text-alice-werefox-blue-light:hover{--tw-text-opacity:1;color:rgb(145 151 243/var(--tw-text-opacity))}.dark\:hover\:ring-alice-werefox-blue:hover{--tw-ring-opacity:1;--tw-ring-color:rgb(27 41 224/var(--tw-ring-opacity))}} \ No newline at end of file diff --git a/void-be/Cargo.toml b/void-be/Cargo.toml index 04a94c5..175e7c3 100644 --- a/void-be/Cargo.toml +++ b/void-be/Cargo.toml @@ -16,5 +16,5 @@ rocket = { workspace = true } # Needed to enable handlebar template support [dependencies.rocket_dyn_templates] -version = "=0.1.0-rc.3" +version = "=0.1.0" features = ["handlebars"] diff --git a/void-be/src/lib.rs b/void-be/src/lib.rs index badca77..78aa105 100644 --- a/void-be/src/lib.rs +++ b/void-be/src/lib.rs @@ -14,9 +14,11 @@ pub mod web_app_backend { use rocket::response::Redirect; use rocket::{Build, Rocket}; use rocket_dyn_templates::{context, Template}; - use void_fe::utils::prop_structs::{PoemDatabase, VoidProps}; + use void_fe::utils::prop_structs::{PoemDatabase, VoidProps, ContentProps}; use void_fe::utils::user_prefs::*; use void_fe::void_app::{self, VirtualDom}; + pub use void_fe::components::void_content::RenderContent; + use void_fe::utils::helpers::get_homepage_paragraph; static POEM_DATABASE: OnceCell = OnceCell::new(); @@ -27,7 +29,7 @@ pub mod web_app_backend { "light" => ThemePref::Light, "dark" => ThemePref::Dark, _ => { - cookies.remove(Cookie::named("theme")); + cookies.remove("theme"); cookies.add(Cookie::new("theme", "auto")); ThemePref::Auto } @@ -42,7 +44,7 @@ pub mod web_app_backend { "nerd" => FontPref::NerdFont, "open" => FontPref::OpenDyslexic, _ => { - cookies.remove(Cookie::named("font")); + cookies.remove("font"); cookies.add(Cookie::new("font", "open")); FontPref::OpenDyslexic } @@ -57,7 +59,7 @@ pub mod web_app_backend { async fn set_user_theme(cookies: &CookieJar<'_>, theme: &str) { if theme == "light" || theme == "dark" || theme == "auto" { - cookies.remove(Cookie::named("theme")); + cookies.remove("theme"); cookies.add(Cookie::new("theme", format!("{theme}"))); } else { return; @@ -66,7 +68,7 @@ pub mod web_app_backend { async fn set_user_font(cookies: &CookieJar<'_>, font: &str) { if font == "nerd" || font == "open" { - cookies.remove(Cookie::named("font")); + cookies.remove("font"); cookies.add(Cookie::new("font", format!("{font}"))); } else { return; @@ -84,8 +86,13 @@ pub mod web_app_backend { .clone(), user_prefs: user_prefs, }; - let mut vdom = VirtualDom::new_with_props(void_app::HomePage, void_props); - let _ = vdom.rebuild(); + // let content_props = ContentProps { + // content: get_homepage_paragraph(), + // user_prefs: user_prefs + // }; + // let mut vdom = VirtualDom::new_with_props(void_app::HomePage, void_props); + let mut vdom = VirtualDom::new_with_props(void_app::HomePage, void_fe::void_app::HomePageProps { props: void_props }); + let _ = vdom.rebuild_in_place(); let output = dioxus_ssr::render(&vdom); Template::render( "index", @@ -102,7 +109,7 @@ pub mod web_app_backend { async fn settings(cookies: &CookieJar<'_>) -> Template { let user_prefs = get_user_prefs(cookies).await; let mut vdom = VirtualDom::new_with_props(void_app::SettingsPage, user_prefs); - let _ = vdom.rebuild(); + let _ = vdom.rebuild_in_place(); let output = dioxus_ssr::render(&vdom); Template::render( "index", @@ -139,7 +146,7 @@ pub mod web_app_backend { user_prefs: user_prefs, }; let mut vdom = VirtualDom::new_with_props(void_app::PoemListPage, void_props); - let _ = vdom.rebuild(); + let _ = vdom.rebuild_in_place(); let output = dioxus_ssr::render(&vdom); Template::render( "index", @@ -164,7 +171,7 @@ pub mod web_app_backend { user_prefs: user_prefs, }; let mut vdom = VirtualDom::new_with_props(void_app::PoemPage, void_props); - let _ = vdom.rebuild(); + let _ = vdom.rebuild_in_place(); let output = dioxus_ssr::render(&vdom); Template::render( "index", diff --git a/void-fe/.vscode/settings.json b/void-fe/.vscode/settings.json index b9d9ce2..c4e74fa 100644 --- a/void-fe/.vscode/settings.json +++ b/void-fe/.vscode/settings.json @@ -2,15 +2,18 @@ "rust-analyzer.cargo.extraArgs": ["--profile", "rust-analyzer"], // "rust-analyzer.cargo.buildScripts.invocationLocation": "root", "rust-analyzer.cargo.target": "wasm32-unknown-unknown", - // "rust-analyzer.cargo.buildScripts.overrideCommand": ["dioxus", "build"], - "rust-analyzer.check.overrideCommand": ["cargo", "check", "--quiet", "--message-format=json"], + "rust-analyzer.cargo.buildScripts.overrideCommand": ["dx", "build"], + "rust-analyzer.check.overrideCommand": ["dx", "check", "--quiet", "--message-format=json"], "rust-analyzer.check.invocationLocation": "root", - "rust-analyzer.check.targets": ["wasm32-unknown-unknown", "x86_64-unknown-linux-gnu"], - // "rust-analyzer.runnables.command": "dioxus serve", + "rust-analyzer.check.targets": ["wasm32-unknown-unknown"], + "rust-analyzer.runnables.command": "dx serve", "rust-analyzer.cargo.buildScripts.enable": false, "rust-analyzer.linkedProjects": [ "./Cargo.toml" ], + "rust-analyzer.diagnostics.disabled": ["unresolved-proc-macro"], + // "rust-analyzer.procMacro.enable": true, + // "rust-analyzer.procMacro.attributes.enable": true, "rust-analyzer.showUnlinkedFileNotification": false, "rust-analyzer.hover.actions.run.enable": true, "rust-analyzer.hover.actions.debug.enable": true, diff --git a/void-fe/Cargo.toml b/void-fe/Cargo.toml index 3942d91..d3b673b 100644 --- a/void-fe/Cargo.toml +++ b/void-fe/Cargo.toml @@ -7,30 +7,36 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -dioxus = { workspace = true } +# dioxus = { workspace = true } markdown = { workspace = true } -dioxus-web = "0.3.1" -dioxus-autofmt = "0.3.0" +once_cell = { workspace = true } +# dioxus-web = "0.5.0-alpha.0" +dioxus-autofmt = "0.5.0-alpha.0" # WebAssembly Debug wasm-logger = "0.2.0" console_error_panic_hook = "0.1.7" log = "0.4.17" dioxus-helmet = "0.2.4" -dioxus-use-storage = "0.3.0" +dioxus-use-storage = "0.3.1" rand = "0.8.5" +dioxus-html-macro = "0.3.0" [dependencies.getrandom] -version = "0.2.9" +version = "0.2.12" features = ["js"] [dependencies.serde] -version = "1.0.160" +version = "1.0.197" features = ["derive"] [dependencies.dioxus-router] -version = "0.3.0" -features = ["query", "web"] +version = "0.5.0-alpha.0" +features = ["web"] [dependencies.rust-embed] -version = "6.6.1" +version = "8.3.0" features = ["debug-embed"] + +[dependencies.dioxus] +version = "0.5.0-alpha.0" +features = ["web"] diff --git a/void-fe/src/components/void_buttons.rs b/void-fe/src/components/void_buttons.rs index 06a7406..215c136 100644 --- a/void-fe/src/components/void_buttons.rs +++ b/void-fe/src/components/void_buttons.rs @@ -1,72 +1,73 @@ +use crate::utils::prop_structs::PoemDatabase; + use super::super::utils::{ - prop_structs::{ButtonProps, ContentChildren}, + prop_structs::{ButtonProps, ContentChildren, VoidProps}, user_prefs::{ThemedComponent, UserPrefs}, }; use dioxus::prelude::*; +use dioxus_router::prelude::*; -#[cfg(target_family = "wasm")] -use dioxus_router::Link; - -pub fn BackToHomePage(cx: Scope) -> Element { - let (user_theme, user_font) = cx.props.clone().get_pref_classes(ThemedComponent::Button); +pub fn BackToHomePage(props: UserPrefs) -> Element { + let (user_theme, user_font) = props.clone().get_pref_classes(ThemedComponent::Button); #[cfg(any(target_family = "windows", target_family = "unix"))] - return cx.render(rsx!{ + return rsx! { a { class: "flex justify-center p-4 text-xl text-center ring-2 hover:animate-yip transition {user_theme} {user_font}", href: "/", p { "Back to the homepage" } } - }); + }; + let mut poem_database = PoemDatabase::new(); + poem_database.build_poem_database(); #[cfg(target_family = "wasm")] - return cx.render(rsx!{ + return render! { Link { class: "flex justify-center p-4 text-xl text-center ring-2 hover:animate-yip transition {user_theme} {user_font}", - to: "/", + to: crate::void_app::Route::HomePage { props:VoidProps{slug: Some("/".to_string()), poem_database: poem_database.clone(), user_prefs: props.clone(),}}, p { "Back to the homepage" } } - }); + }; } -pub fn NavigationButton(cx: Scope) -> Element { - let (user_theme, mut user_font) = cx - .props +pub fn NavigationButton(props: ButtonProps) -> Element { + let (user_theme, mut user_font) = props .user_prefs .clone() .get_pref_classes(ThemedComponent::Button); - let title = cx.props.title.clone(); + let title = props.title.clone(); let title_ref = title.as_str(); - let slug = cx.props.slug.clone(); + let slug = props.slug.clone(); let slug_ref = slug.as_str(); - match &cx.props.override_font { + match props.override_font { Some(font) => user_font = font.clone(), None => (), } #[cfg(any(target_family = "windows", target_family = "unix"))] - return cx.render(rsx!{ + return rsx! { a { class: "flex basis-full justify-center p-4 ml-2 mr-2 text-xl text-center ring-2 hover:animate-yip transition {user_theme} {user_font}", href: "{slug_ref}", - "{title_ref}" + dangerous_inner_html: "{title_ref}", } - }); + }; #[cfg(target_family = "wasm")] - return cx.render(rsx!{ + return rsx! { Link { class: "flex basis-full justify-center p-4 ml-2 mr-2 text-xl text-center ring-2 hover:animate-yip transition {user_theme} {user_font}", to: "{slug_ref}", div { dangerous_inner_html: "{title_ref}", } } - }); + }; } -pub fn ButtonGroup<'a>(cx: Scope<'a, ContentChildren<'a>>) -> Element { - cx.render(rsx! { +pub fn ButtonGroup(props: ContentChildren) -> Element { + rsx! { div { class: "flex md:flex-row md:space-y-0 flex-col space-y-4", - &cx.props.children + {props.children} } - }) + } } diff --git a/void-fe/src/components/void_content.rs b/void-fe/src/components/void_content.rs index 7159592..14b6e99 100644 --- a/void-fe/src/components/void_content.rs +++ b/void-fe/src/components/void_content.rs @@ -1,21 +1,14 @@ // Might wanna move stuff form `void_poem.rs` into here... -use crate::utils::prop_structs::{ContentProps}; use super::super::utils::user_prefs::ThemedComponent; +use crate::utils::prop_structs::ContentProps; use dioxus::prelude::*; -pub fn RenderContent(cx: Scope) -> Element { - let (user_theme, user_font) = cx.props.user_prefs.get_pref_classes(ThemedComponent::Card); - let content = &cx.props.content; - #[cfg(any(target_family = "windows", target_family = "unix"))] - return cx.render(rsx!{ - div { class: "flex p-4 md:pl-8 md:pr-8 ml-4 mr-4 text-md text-center ring-4 {user_theme} {user_font}", - "{content}", - } - }); - #[cfg(target_family = "wasm")] - return cx.render(rsx!{ +pub fn RenderContent(props: ContentProps) -> Element { + let (user_theme, user_font) = props.user_prefs.get_pref_classes(ThemedComponent::Card); + let content = props.content; + return rsx! { div { class: "flex p-4 md:pl-8 md:pr-8 ml-4 mr-4 text-md text-center ring-4 {user_theme} {user_font}", dangerous_inner_html: "{content}", } - }); + }; } diff --git a/void-fe/src/components/void_footer.rs b/void-fe/src/components/void_footer.rs index 977865e..7b7db6f 100644 --- a/void-fe/src/components/void_footer.rs +++ b/void-fe/src/components/void_footer.rs @@ -4,17 +4,17 @@ use crate::{ }; use dioxus::prelude::*; -pub fn Footer(cx: Scope) -> Element { - cx.render(rsx! { - MutantStandardFooter { theme: cx.props.clone().get_theme(), font: cx.props.clone().get_font() } - }) +pub fn Footer(props: UserPrefs) -> Element { + rsx! { + MutantStandardFooter { theme: props.clone().get_theme(), font: props.clone().get_font() } + } } -fn MutantStandardFooter(cx: Scope) -> Element { - let user_prefs = UserPrefs::new(cx.props.clone().get_theme(), cx.props.clone().get_font()); - let user_theme = cx.props.get_theme_classes(ThemedComponent::Card); - let user_font = cx.props.get_font_class(); - cx.render(rsx!{ +fn MutantStandardFooter(props: UserPrefs) -> Element { + let user_prefs = UserPrefs::new(props.clone().get_theme(), props.clone().get_font()); + let user_theme = props.get_theme_classes(ThemedComponent::Card); + let user_font = props.get_font_class(); + rsx! { div { class: "p-4 flex flex-col space-y-4 mx-auto max-w-full justify-center ring-4 {user_theme} {user_font}", ButtonGroup{ NavigationButton { title: "⚙️ Settings".to_string(), slug: "/settings".to_string(), user_prefs: user_prefs.clone() } @@ -24,5 +24,5 @@ fn MutantStandardFooter(cx: Scope) -> Element { "This site uses Mutant Standard emoji, which are licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License" } } - }) + } } diff --git a/void-fe/src/components/void_page.rs b/void-fe/src/components/void_page.rs index e2ba025..9389fe5 100644 --- a/void-fe/src/components/void_page.rs +++ b/void-fe/src/components/void_page.rs @@ -1,13 +1,13 @@ use crate::utils::prop_structs::PageChildren; use dioxus::prelude::*; -pub fn PageBase<'a>(cx: Scope<'a, PageChildren<'a>>) -> Element { - cx.render(rsx! { +pub fn PageBase(props: PageChildren) -> Element { + rsx! { span { hidden: true, a { rel: "me", href: "https://yiff.life/@werefox", "Mastodon" } } div { class: "min-h-screen", - div { class: "container space-y-4 pt-4 pb-4 max-w-3xl", &cx.props.children } + div { class: "container space-y-4 pt-4 pb-4 max-w-3xl", {props.children} } } - }) + } } diff --git a/void-fe/src/components/void_poem.rs b/void-fe/src/components/void_poem.rs index db9504a..ec59c6a 100644 --- a/void-fe/src/components/void_poem.rs +++ b/void-fe/src/components/void_poem.rs @@ -4,57 +4,54 @@ use crate::utils::prop_structs::VoidProps; use crate::utils::{prop_structs::PoemChildren, user_prefs::ThemedComponent}; use dioxus::prelude::*; -pub fn PoemList(cx: Scope) -> Element { - let poem_list = cx.props.poem_database.get_poem_list(); - cx.render(rsx! { +pub fn PoemList(props: VoidProps) -> Element { + let poem_list = props.poem_database.get_poem_list(); + rsx! { ul { class: "flex flex-col space-y-4", - poem_list.into_iter().map(|p| { + {poem_list.into_iter().map(|p| { let slug = format!("/poems/{}", p.0); rsx!{ - NavigationButton { title: p.1, slug: slug, user_prefs: cx.props.user_prefs.clone() } + NavigationButton { title: p.1, slug: slug, user_prefs: props.user_prefs.clone() } } - }) + })} } - }) + } } -pub fn MakePoem<'a>(cx: Scope<'a, PoemChildren<'a>>) -> Element { - cx.render(rsx! { +pub fn MakePoem(props: PoemChildren) -> Element { + rsx! { div { class: "flex-col space-y-4", - &cx.props.children + {props.children} } - }) + } } -pub fn GetPoem(cx: Scope) -> Element { - let poem_database = &cx.props.poem_database; - let slug = String::from(&cx.props.slug.clone().expect("No slug specified.")); +pub fn GetPoem(props: VoidProps) -> Element { + let poem_database = props.poem_database; + let slug = String::from(props.slug.clone().expect("No slug specified.")); let poem_struct = poem_database.get_poem(slug.clone()); - cx.render(rsx! { - Title { title: poem_struct.title.clone(), is_html: true, user_prefs: cx.props.user_prefs.clone() } + rsx! { + Title { title: poem_struct.title.clone(), is_html: true, user_prefs: props.user_prefs.clone() } MakePoem{ - PoemContent { slug: slug, poem_database: poem_database.clone(), user_prefs: cx.props.user_prefs.clone() } + PoemContent { slug: slug, poem_database: poem_database.clone(), user_prefs: props.user_prefs.clone() } } - }) + } } -pub fn PoemContent(cx: Scope) -> Element { - let (user_theme, user_font) = cx.props.user_prefs.get_pref_classes(ThemedComponent::Card); - let slug = cx - .props +pub fn PoemContent(props: VoidProps) -> Element { + let (user_theme, user_font) = props.user_prefs.get_pref_classes(ThemedComponent::Card); + let slug = props .slug .as_ref() .expect("Received slug for poem selection."); - let content = &cx - .props + let content = props .poem_database .poem_hashmap .get(slug) .expect("Grabbed poem stuct from databse.") .content .clone(); - let creation_date = &cx - .props + let creation_date = props .poem_database .poem_hashmap .get(slug) @@ -63,26 +60,26 @@ pub fn PoemContent(cx: Scope) -> Element { .clone(); let publish_string = "\u{003C}br\u{003E}\u{003C}br\u{003E}\u{003C}br\u{003E}Published: "; #[cfg(any(target_family = "unix", target_family = "windows"))] - return cx.render(rsx! { + return rsx! { div { class: "flex p-2 mx-auto max-w-full justify-center", 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}", } - div { class: "flex flex-col space-y-4 py-4 ml-4 mr-4", "{content}{publish_string}{creation_date}" + div { class: "flex flex-col space-y-4 py-4 ml-4 mr-4", dangerous_inner_html: "{content}{publish_string}{creation_date}" } } } - }); + }; #[cfg(target_family = "wasm")] - return cx.render(rsx! { + return rsx! { div { class: "flex p-2 mx-auto max-w-full justify-center", 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}", } - div { class: "flex flex-col space-y-4 py-4 ml-4 mr-4", + div { class: "flex flex-col space-y-4 py-4 ml-4 mr-4", dangerous_inner_html: "{content}{publish_string}{creation_date}", } } } - }); + }; } diff --git a/void-fe/src/components/void_title.rs b/void-fe/src/components/void_title.rs index 773e685..cd35880 100644 --- a/void-fe/src/components/void_title.rs +++ b/void-fe/src/components/void_title.rs @@ -2,40 +2,40 @@ use crate::utils::prop_structs::TitleProps; use super::super::utils::user_prefs::ThemedComponent; use dioxus::prelude::*; -pub fn Title(cx: Scope) -> Element { - let user_prefs = cx.props.user_prefs.clone(); +pub fn Title(props: TitleProps) -> Element { + let user_prefs = props.user_prefs.clone(); let title_classes = user_prefs.get_theme_classes(ThemedComponent::Card); - let title = cx.props.title.clone(); - let is_html = cx.props.is_html; - cx.render(rsx!{ + let title = props.title.clone(); + let is_html = props.is_html; + rsx!{ div { class: "p-4 ring-4 {title_classes}", span { class: "flex flex-row mx-auto max-w-full justify-center text-xl text-center", TitleHtml { title: title, is_html: is_html, user_prefs: user_prefs } } } - }) + } } -fn TitleHtml(cx: Scope) -> Element { - let title = cx.props.title.clone(); - if cx.props.is_html { +fn TitleHtml(props: TitleProps) -> Element { + let title = props.title.clone(); + if props.is_html { #[cfg(any(target_family = "unix", target_family = "windows"))] - return cx.render(rsx! { + return rsx! { span { class: "flex flex-row align-middle mx-auto max-w-full justify-center", - "{title} " + dangerous_inner_html: "{title} " } - }); + }; #[cfg(target_family = "wasm")] - return cx.render(rsx! { + return rsx! { span { class: "flex flex-row align-middle mx-auto max-w-full justify-center", div { dangerous_inner_html: "{title}", } } - }); + }; } else { - return cx.render(rsx! { + return rsx! { span { "{title}" } - }); + }; } } diff --git a/void-fe/src/lib.rs b/void-fe/src/lib.rs index 95e79f1..f054f6d 100644 --- a/void-fe/src/lib.rs +++ b/void-fe/src/lib.rs @@ -4,9 +4,10 @@ #![allow(non_snake_case)] -mod components; -pub mod utils; +use utils::{prop_structs::PoemDatabase, user_prefs::UserPrefs}; +pub mod components; +pub mod utils; /// A module that handles the functions needed /// to render the site. pub mod void_app { @@ -27,45 +28,80 @@ pub mod void_app { #[cfg(any(target_family = "wasm"))] use dioxus_helmet::Helmet; #[cfg(any(target_family = "wasm"))] - use dioxus_router::{Link, Redirect, Route, Router}; + use dioxus_router::prelude::*; #[cfg(any(target_family = "wasm"))] use dioxus_use_storage::use_local_storage; + #[cfg(any(target_family = "wasm"))] + use once_cell::sync::OnceCell; + #[cfg(any(target_family = "wasm"))] + static POEM_DATABASE: OnceCell = OnceCell::new(); #[cfg(target_family = "wasm")] - pub fn DioxusApp(cx: Scope) -> Element { + #[derive(Routable, PartialEq, Clone)] + pub enum Route { + #[route("/")] + // #[redirect("/")]//, || Route::HomePage {slug: "/".to_string(), poem_database: poem_database.clone(), user_prefs: user_prefs.clone(),})] + HomePage { props: VoidProps }, + #[route("/poems")] + PoemListPage { + slug: String, + poem_database: PoemDatabase, + user_prefs: UserPrefs, + }, + #[route("/poems/:slug")] + PoemPage { + slug: String, + poem_database: PoemDatabase, + user_prefs: UserPrefs, + }, + #[route("/settings")] + SettingsPage { theme: ThemePref, font: FontPref }, + // #[route("/settings/dark")] + // SettingsPage { theme: String, font: String }, + // #[route("/settings/font")] + // SettingsPage { theme: String, font: String }, + #[route("")] + PageNotFound {}, + } + #[cfg(target_family = "wasm")] + pub fn DioxusApp() -> Element { + // let mut poem_database = PoemDatabase::new(); + // poem_database.build_poem_database(); + + // let user_prefs = UserPrefs::new(ThemePref::Auto, FontPref::OpenDyslexic); let mut poem_database = PoemDatabase::new(); poem_database.build_poem_database(); + POEM_DATABASE + .set(poem_database) + .expect("Could not initialize poem database."); - let user_prefs = UserPrefs::new(ThemePref::Auto, FontPref::OpenDyslexic); - - cx.render(rsx! { - Router { - 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 {} } - } - }) + rsx! { + Router:: {} + } } #[cfg(target_family = "wasm")] - fn PageNotFound(cx: Scope) -> Element { - cx.render(rsx! { + fn PageNotFound() -> Element { + rsx! { p { "That page doesn't exist, sorry!" } - Redirect { to: "/" } - }) + } } + #[component] /// Renders the app and returns the rendered Element. - pub fn HomePage(cx: Scope) -> Element { - let poem_database = &cx.props.poem_database; - let user_prefs = cx.props.user_prefs.clone(); + pub fn HomePage(props: VoidProps) -> Element { + #[cfg(target_family = "wasm")] + let poem_database = POEM_DATABASE + .get() + .expect("Poem database is not initialized") + .clone(); + + #[cfg(any(target_family = "unix", target_family = "windows"))] + let poem_database = props.poem_database.clone(); + let user_prefs = props.user_prefs.clone(); let (user_theme, user_font) = user_prefs.get_pref_classes(ThemedComponent::Page); let page_title = "A Letter to the Void".to_string(); - cx.render(rsx!{ + rsx! { div { class: "{user_theme} {user_font}", PageBase { Title { title: page_title, is_html: false, user_prefs: user_prefs.clone() } @@ -79,15 +115,21 @@ pub mod void_app { Footer { theme: user_prefs.clone().get_theme(), font: user_prefs.get_font() } } } - }) + } } /// Renders the app and returns the rendered Element. - pub fn PoemListPage(cx: Scope) -> Element { - let poem_database = &cx.props.poem_database; - let user_prefs = cx.props.user_prefs.clone(); + pub fn PoemListPage(props: VoidProps) -> Element { + #[cfg(target_family = "wasm")] + let poem_database = POEM_DATABASE + .get() + .expect("Poem database is not initialized") + .clone(); + #[cfg(any(target_family = "unix", target_family = "windows"))] + let poem_database = props.poem_database.clone(); + let user_prefs = props.user_prefs.clone(); let (user_theme, user_font) = user_prefs.get_pref_classes(ThemedComponent::Page); - cx.render(rsx! { + rsx! { div { class: "{user_theme} {user_font}", PageBase { Title { title: "A Letter to the Void".to_string(), is_html: false, user_prefs: user_prefs.clone() } @@ -97,27 +139,32 @@ pub mod void_app { Footer { theme: user_prefs.clone().get_theme(), font: user_prefs.get_font() } } } - }) + } } - pub fn PoemPage(cx: Scope) -> Element { - let poem_database = &cx.props.poem_database; - let user_prefs = cx.props.user_prefs.clone(); - let (user_theme, user_font) = user_prefs.get_pref_classes(ThemedComponent::Page); + pub fn PoemPage(props: VoidProps) -> Element { + #[cfg(target_family = "wasm")] + let poem_database = POEM_DATABASE + .get() + .expect("Poem database is not initialized") + .clone(); #[cfg(any(target_family = "unix", target_family = "windows"))] - let slug = &cx - .props + let poem_database = props.poem_database.clone(); + let user_prefs = 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 = props .slug .as_ref() - .expect("A slug was given in the pops.") + .expect("A slug was given in the props.") .clone(); - #[cfg(target_family = "wasm")] - let slug = String::from( - dioxus_router::use_route(cx) - .segment("slug") - .expect("No slug specified."), - ); - cx.render(rsx!{ + // #[cfg(target_family = "wasm")] + // let slug = String::from( + // use_route() + // .segment("slug") + // .expect("No slug specified."), + // ); + rsx! { div { class: "{user_theme} {user_font}", PageBase { BackToHomePage { theme: user_prefs.clone().get_theme(), font: user_prefs.clone().get_font() } @@ -133,15 +180,15 @@ pub mod void_app { Footer { theme: user_prefs.clone().get_theme(), font: user_prefs.get_font() } } } - }) + } } - pub fn SettingsPage(cx: Scope) -> Element { - let user_prefs = cx.props.clone(); + pub fn SettingsPage(props: UserPrefs) -> Element { + let user_prefs = props.clone(); let (user_theme, user_font) = user_prefs.get_pref_classes(ThemedComponent::Page); // Get rid of this and create a general card component with children. let (user_theme_card, user_font_card) = user_prefs.get_pref_classes(ThemedComponent::Card); - cx.render(rsx! { + rsx! { div { class: "{user_theme} {user_font}", PageBase { Title { title: "Settings".to_string(), is_html: false, user_prefs: user_prefs.clone() } @@ -162,14 +209,14 @@ pub mod void_app { "Font" } ButtonGroup { - NavigationButton { title: "Nerd Font".to_string(), slug: "/settings/?font=nerd".to_string(), user_prefs: user_prefs.clone() override_font: "font-nerd".to_string() } - NavigationButton { title: "Open Dyslexic".to_string(), slug: "/settings/?font=open".to_string(), user_prefs: user_prefs.clone() override_font: "font-open".to_string() } + NavigationButton { title: "Nerd Font".to_string(), slug: "/settings/?font=nerd".to_string(), user_prefs: user_prefs.clone(), override_font: "font-nerd".to_string() } + NavigationButton { title: "Open Dyslexic".to_string(), slug: "/settings/?font=open".to_string(), user_prefs: user_prefs.clone(), override_font: "font-open".to_string() } } } } BackToHomePage { theme: user_prefs.clone().get_theme(), font: user_prefs.get_font() } } } - }) + } } } diff --git a/void-fe/src/main.rs b/void-fe/src/main.rs index 67e5c0e..a45aefc 100644 --- a/void-fe/src/main.rs +++ b/void-fe/src/main.rs @@ -18,5 +18,5 @@ fn main() { wasm_logger::init(wasm_logger::Config::default()); console_error_panic_hook::set_once(); - dioxus_web::launch(void_app::DioxusApp); + dioxus::prelude::launch(void_app::DioxusApp); } diff --git a/void-fe/src/utils/helpers.rs b/void-fe/src/utils/helpers.rs index f852084..b8d096b 100644 --- a/void-fe/src/utils/helpers.rs +++ b/void-fe/src/utils/helpers.rs @@ -23,6 +23,14 @@ 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) { + use dioxus::dioxus_core::Component; + use markdown::CompileOptions; + let markdown_options = &mut Options::gfm(); + markdown_options.compile = CompileOptions { + allow_dangerous_html: true, + ..CompileOptions::default() + }; + for p in Poems::iter() { let filename = p.to_string(); let poem_content = Poems::get(&filename).expect("Found poem {filename:?}"); @@ -32,7 +40,7 @@ impl PoemDatabase { let poem_title = poem_to_str.next().expect("No title specified."); let poem_content = poem_to_str.into_iter().collect::>().join("\n"); let poem_title_to_html_string = - markdown::to_html_with_options(poem_title, &Options::gfm()).unwrap(); + markdown::to_html_with_options(poem_title, markdown_options).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("_"); @@ -41,7 +49,7 @@ impl PoemDatabase { self.poem_list .push((creation_date.to_string(), slug.to_string())); let poem_struct = PoemStruct { - title: poem_title_to_html_string.to_string(), + title: poem_title_to_html_string, content: poem_content_to_html_string, creation_date: creation_date.to_string(), }; diff --git a/void-fe/src/utils/prop_structs.rs b/void-fe/src/utils/prop_structs.rs index 9a11566..18beefe 100644 --- a/void-fe/src/utils/prop_structs.rs +++ b/void-fe/src/utils/prop_structs.rs @@ -1,27 +1,28 @@ use std::collections::HashMap; -use crate::void_app::{Element, Props}; +// use crate::void_app::{Element, Props}; use super::user_prefs::UserPrefs; +use dioxus::prelude::*; -#[derive(PartialEq, Props)] +#[derive(PartialEq, Props, Clone)] pub struct PoemRequest { pub slug: String, pub user_prefs: UserPrefs, } -#[derive(PartialEq, Props)] +#[derive(PartialEq, Props, Clone)] pub struct TitleProps { pub title: String, pub is_html: bool, pub user_prefs: UserPrefs, } -#[derive(PartialEq, Props)] +#[derive(PartialEq, Props, Clone)] pub struct ContentProps { pub content: String, pub user_prefs: UserPrefs, } -#[derive(PartialEq, Props)] +#[derive(PartialEq, Props, Clone)] pub struct ButtonProps { pub title: String, pub slug: String, @@ -29,14 +30,14 @@ pub struct ButtonProps { pub override_font: Option, } -#[derive(PartialEq, Props)] +#[derive(Default, PartialEq, Props, Clone)] pub struct VoidProps { pub slug: Option, pub poem_database: PoemDatabase, pub user_prefs: UserPrefs, } -#[derive(PartialEq, Props, Clone, Debug)] +#[derive(Default, PartialEq, Props, Clone, Debug)] pub struct PoemDatabase { pub poem_list: Vec<(String, String)>, pub poem_hashmap: HashMap, @@ -50,17 +51,17 @@ pub struct PoemStruct { } // These next three should all just be one prop. -#[derive(Props)] -pub struct PoemChildren<'a> { - pub children: Element<'a>, +#[derive(PartialEq, Props, Clone)] +pub struct PoemChildren { + pub children: Element, } -#[derive(Props)] -pub struct PageChildren<'a> { - pub children: Element<'a>, +#[derive(PartialEq, Props, Clone)] +pub struct PageChildren { + pub children: Element, } -#[derive(Props)] -pub struct ContentChildren<'a> { - pub children: Element<'a>, +#[derive(PartialEq, Props, Clone)] +pub struct ContentChildren { + pub children: Element, } diff --git a/void-fe/src/utils/user_prefs.rs b/void-fe/src/utils/user_prefs.rs index c7730a0..843d58c 100644 --- a/void-fe/src/utils/user_prefs.rs +++ b/void-fe/src/utils/user_prefs.rs @@ -1,20 +1,22 @@ use dioxus::prelude::*; -#[derive(PartialEq, Props, Clone)] +#[derive(Default, PartialEq, Props, Clone)] pub struct UserPrefs { theme: ThemePref, font: FontPref, } -#[derive(PartialEq, Clone)] +#[derive(Default, PartialEq, Clone)] pub enum ThemePref { Light, Dark, + #[default] Auto, } -#[derive(PartialEq, Clone)] +#[derive(Default, PartialEq, Clone)] pub enum FontPref { + #[default] NerdFont, OpenDyslexic, } @@ -41,9 +43,9 @@ impl UserPrefs { // class: "dark:text-alice-werefox-grey-light dark:hover:text-alice-werefox-blue-light dark:hover:ring-alice-werefox-blue" // class: "text-alice-werefox-grey-light hover:text-alice-werefox-blue-light hover:ring-alice-werefox-blue" - const PAGE_CLASSES: &str = "bg-alice-werefox-grey-light dark:bg-alice-werefox-grey"; - const CARD_CLASSES: &str = "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"; - const BUTTON_CLASSES: &str = "bg-alice-werefox-grey-lightest ring-alice-werefox-red-dark text-alice-werefox-grey-dark hover:text-alice-werefox-blue-dark hover:ring-alice-werefox-blue dark:bg-alice-werefox-grey-dark dark:ring-alice-werefox-red dark:text-alice-werefox-grey-light dark:hover:text-alice-werefox-blue-light dark:hover:ring-alice-werefox-blue"; + const PAGE_CLASSES: &'static str = "bg-alice-werefox-grey-light dark:bg-alice-werefox-grey"; + const CARD_CLASSES: &'static str = "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"; + const BUTTON_CLASSES: &'static str = "bg-alice-werefox-grey-lightest ring-alice-werefox-red-dark text-alice-werefox-grey-dark hover:text-alice-werefox-blue-dark hover:ring-alice-werefox-blue dark:bg-alice-werefox-grey-dark dark:ring-alice-werefox-red dark:text-alice-werefox-grey-light dark:hover:text-alice-werefox-blue-light dark:hover:ring-alice-werefox-blue"; pub fn new(theme: ThemePref, font: FontPref) -> UserPrefs { UserPrefs { theme, font }