diff --git a/Cargo.lock b/Cargo.lock index 2452f9c..d2407cc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -599,6 +599,7 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a8d5564e570a38b43d78bdc063374a0c3098c4f0d64005b12f9bbe87e869b6d7" dependencies = [ + "futures-channel", "gloo-events", "js-sys", "wasm-bindgen", @@ -672,6 +673,8 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "98c4a8d6391675c6b2ee1a6c8d06e8e2d03605c44cec1270675985a4c2a5500b" dependencies = [ + "futures-channel", + "futures-core", "js-sys", "wasm-bindgen", ] @@ -1286,6 +1289,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "route-recognizer" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afab94fb28594581f62d981211a9a4d53cc8130bbcbbb89a0440d9b8e81a7746" + [[package]] name = "rustc-demangle" version = "0.1.21" @@ -2268,6 +2277,35 @@ dependencies = [ "syn", ] +[[package]] +name = "yew-router" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "426ee0486d2572a6c5e39fbdbc48b58d59bb555f3326f54631025266cf04146e" +dependencies = [ + "gloo", + "js-sys", + "route-recognizer", + "serde", + "serde_urlencoded", + "tracing", + "wasm-bindgen", + "web-sys", + "yew", + "yew-router-macro", +] + +[[package]] +name = "yew-router-macro" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89b249cdb39e0cddaf0644dedc781854524374664793479fdc01e6a65d6e6ae3" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "yewprint" version = "0.4.0" @@ -2299,6 +2337,7 @@ dependencies = [ "web-sys", "wee_alloc", "yew", + "yew-router", "yewprint", ] diff --git a/Cargo.toml b/Cargo.toml index e2c7807..0fe2016 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,6 +28,7 @@ js-sys = "0.3" wee_alloc = { version = "0.4.5", optional = false } yew = { version = "0.20.0", features = ["csr"] } +yew-router = { version = "0.17.0" } yewprint = "0.4.0" gloo = "0.8.0" gloo-events = "0.1" diff --git a/src/app.rs b/src/app.rs index 665970d..85abee9 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1,6 +1,10 @@ use yew::prelude::*; +use yew_router::prelude::Navigator; +use yew_router::prelude::use_navigator; use yewprint::Icon; use crate::page::Page; +use crate::page::PageRouter; +use crate::page::Pages; use crate::theme::ThemeContext; use crate::theme::ThemeMsg; use crate::theme::ThemeProvider; @@ -11,15 +15,20 @@ use crate::component::actionbar::{Actionbar, ActionbarOption}; pub fn AppRoot() -> Html { html! { - + + + } } #[function_component] fn ThemedApp() -> Html { + let navigator = use_navigator().unwrap(); + // Helper function for generating tabs - fn page_option(current: &Page, page: Page, state: UseStateHandle) -> ActionbarOption { + fn page_option(current: &Page, page: Page, navigator: Navigator, state: UseStateHandle) -> ActionbarOption { + let is_current = *current == page; ActionbarOption::new( page.name(), match page { @@ -28,8 +37,11 @@ fn ThemedApp() -> Html { Page::Socials => Icon::SocialMedia, Page::Contact => Icon::Envelope, }, - Callback::from(move |_| state.set(page)), - *current == page + Callback::from(move |_| { + navigator.push(&page); + state.set(page); + }), + is_current ) } @@ -41,10 +53,10 @@ fn ThemedApp() -> Html { <> {vec![ - page_option(¤t_page, Page::Home, page_state.clone()), - page_option(¤t_page, Page::Projects, page_state.clone()), - page_option(¤t_page, Page::Socials, page_state.clone()), - page_option(¤t_page, Page::Contact, page_state), + page_option(¤t_page, Page::Home, navigator.clone(), page_state.clone()), + page_option(¤t_page, Page::Projects, navigator.clone(), page_state.clone()), + page_option(¤t_page, Page::Socials, navigator.clone(), page_state.clone()), + page_option(¤t_page, Page::Contact, navigator, page_state), ActionbarOption::new_opt( None, Some(Icon::Flash), @@ -56,7 +68,7 @@ fn ThemedApp() -> Html { ]}
- {current_page.content()} +
} diff --git a/src/component/image_viewer.rs b/src/component/image_viewer.rs index 44f5930..9e03384 100644 --- a/src/component/image_viewer.rs +++ b/src/component/image_viewer.rs @@ -1,7 +1,8 @@ use yew::{function_component, Html, html, Callback, Properties, use_state}; -use yewprint::{Overlay, Icon, IconSize}; +use yewprint::{Overlay, Icon, IconSize, Intent}; const CHEVRON_SIZE: f64 = 40.0; +const CHEVRON_TYPE: Intent = Intent::Danger; #[derive(PartialEq)] pub struct ImageDescription { @@ -60,7 +61,7 @@ pub fn ImageViewer(props: &ImageViewerProps) -> Html { Some(html! { Html { Some(html! { Html { + match page { + Page::Home => html!{}, + Page::Contact => html!{}, + Page::Socials => html!{}, + Page::Projects => html!{}, + } +} + +#[derive(Properties, PartialEq)] +pub struct PageRouterProps { + pub children: Children +} + +#[function_component] +pub fn PageRouter(props: &PageRouterProps) -> Html { + html! { + + {props.children.clone()} + + } +} + +#[function_component] +pub fn Pages() -> Html { + html! { + render={switch} /> + } +} + impl Page { pub fn name(&self) -> &'static str{ match self { @@ -22,13 +60,4 @@ impl Page { Page::Contact => "Contact" } } - - pub fn content(&self) -> Html { - match self { - Page::Home => html!{}, - Page::Contact => html!{}, - Page::Socials => html!{}, - Page::Projects => html!{}, - } - } } \ No newline at end of file diff --git a/static/404.html b/static/404.html new file mode 100644 index 0000000..c80fd1b --- /dev/null +++ b/static/404.html @@ -0,0 +1,40 @@ + + + + + Single Page Apps for GitHub Pages + + + + + \ No newline at end of file diff --git a/static/index.html b/static/index.html index 3da18b3..b4eb34f 100644 --- a/static/index.html +++ b/static/index.html @@ -3,6 +3,28 @@ +