use std::borrow::Cow; use crate::components::auth; use crate::pages::{page_home::PageHome, page_not_found::PageNotFound}; use yew::html::IntoPropValue; use yew::prelude::*; use yew::services::ConsoleService; use yew::Component; use yew_router::prelude::*; use yew_router::{router::Router, Switch}; #[derive(Switch, Clone, Debug)] enum AppRoute { // #[at("/ssh/:id")] // Ssh(i32), // #[to = "/ssh"] // Ssh, #[to = "/!"] Home, #[to = ""] NotFound, } impl From for &str { fn from(route: AppRoute) -> Self { match route { // AppRoute::Ssh => "/ssh", _ => "/", } } } impl IntoPropValue>> for AppRoute { fn into_prop_value(self: AppRoute) -> Option> { Some(Cow::Borrowed(self.into())) } } pub struct App { authdone: bool, link: ComponentLink, } pub enum AppMsg { AuthDone, } impl Component for App { type Message = AppMsg; type Properties = (); fn create(_: Self::Properties, link: ComponentLink) -> Self { Self { authdone: false, link, } } fn update(&mut self, msg: Self::Message) -> ShouldRender { match msg { AppMsg::AuthDone => self.authdone = true, } true } fn change(&mut self, _: Self::Properties) -> ShouldRender { false } fn view(&self) -> Html { html! { <> { if self.authdone { html! { <> {self.view_nav()}
render = Router::render(Self::switch) redirect=Router::redirect(|route: Route| { ConsoleService::log(&format!("{:?}", route)); AppRoute::NotFound }) />
} } else { let onauthdone = &self.link.callback(|_| AppMsg::AuthDone); html!{ } } } } } } impl App { fn view_nav(&self) -> Html { html! { } } fn switch(switch: AppRoute) -> Html { ConsoleService::log(&format!("{:?}", switch)); match switch { // Route::Ssh(ip) => { // html! { } // } // AppRoute::Ssh => { // html! {} // } AppRoute::Home => { html! {} } AppRoute::NotFound => { html! { } } } } }