2021-11-01 16:30:23 +00:00
|
|
|
use std::borrow::Cow;
|
|
|
|
|
2021-11-04 06:41:56 +00:00
|
|
|
use crate::components::auth;
|
2021-11-08 12:29:24 +00:00
|
|
|
use crate::pages::{page_home::PageHome, page_not_found::PageNotFound};
|
2021-11-01 16:30:23 +00:00
|
|
|
use yew::html::IntoPropValue;
|
2021-11-01 13:36:38 +00:00
|
|
|
use yew::prelude::*;
|
2021-11-01 16:30:23 +00:00
|
|
|
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),
|
2021-11-08 12:29:24 +00:00
|
|
|
// #[to = "/ssh"]
|
|
|
|
// Ssh,
|
2021-11-01 16:30:23 +00:00
|
|
|
#[to = "/!"]
|
|
|
|
Home,
|
|
|
|
#[to = ""]
|
|
|
|
NotFound,
|
|
|
|
}
|
|
|
|
|
2021-11-04 06:41:56 +00:00
|
|
|
impl From<AppRoute> for &str {
|
|
|
|
fn from(route: AppRoute) -> Self {
|
|
|
|
match route {
|
2021-11-08 12:29:24 +00:00
|
|
|
// AppRoute::Ssh => "/ssh",
|
2021-11-04 06:41:56 +00:00
|
|
|
_ => "/",
|
2021-11-01 16:30:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl IntoPropValue<Option<Cow<'_, str>>> for AppRoute {
|
|
|
|
fn into_prop_value(self: AppRoute) -> Option<Cow<'static, str>> {
|
|
|
|
Some(Cow::Borrowed(self.into()))
|
|
|
|
}
|
|
|
|
}
|
2021-11-01 13:36:38 +00:00
|
|
|
|
2021-11-04 06:41:56 +00:00
|
|
|
pub struct App {
|
|
|
|
authdone: bool,
|
|
|
|
link: ComponentLink<Self>,
|
|
|
|
}
|
2021-11-01 13:36:38 +00:00
|
|
|
|
2021-11-04 06:41:56 +00:00
|
|
|
pub enum AppMsg {
|
|
|
|
AuthDone,
|
|
|
|
}
|
2021-11-01 13:36:38 +00:00
|
|
|
|
|
|
|
impl Component for App {
|
2021-11-04 06:41:56 +00:00
|
|
|
type Message = AppMsg;
|
2021-11-01 13:36:38 +00:00
|
|
|
type Properties = ();
|
|
|
|
|
2021-11-04 06:41:56 +00:00
|
|
|
fn create(_: Self::Properties, link: ComponentLink<Self>) -> Self {
|
|
|
|
Self {
|
|
|
|
authdone: false,
|
|
|
|
link,
|
|
|
|
}
|
2021-11-01 13:36:38 +00:00
|
|
|
}
|
|
|
|
|
2021-11-04 06:41:56 +00:00
|
|
|
fn update(&mut self, msg: Self::Message) -> ShouldRender {
|
|
|
|
match msg {
|
|
|
|
AppMsg::AuthDone => self.authdone = true,
|
|
|
|
}
|
2021-11-01 13:36:38 +00:00
|
|
|
true
|
|
|
|
}
|
|
|
|
|
|
|
|
fn change(&mut self, _: Self::Properties) -> ShouldRender {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
|
2021-11-04 06:41:56 +00:00
|
|
|
fn view(&self) -> Html {
|
2021-11-01 13:36:38 +00:00
|
|
|
html! {
|
2021-11-01 16:30:23 +00:00
|
|
|
<>
|
2021-11-04 06:41:56 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
if self.authdone {
|
|
|
|
html! {
|
|
|
|
<>
|
|
|
|
{self.view_nav()}
|
|
|
|
|
|
|
|
<main class="content">
|
|
|
|
<Router<AppRoute>
|
|
|
|
render = Router::render(Self::switch)
|
|
|
|
redirect=Router::redirect(|route: Route| {
|
|
|
|
ConsoleService::log(&format!("{:?}", route));
|
|
|
|
AppRoute::NotFound
|
|
|
|
})
|
|
|
|
/>
|
|
|
|
</main>
|
|
|
|
</>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
let onauthdone = &self.link.callback(|_| AppMsg::AuthDone);
|
|
|
|
html!{
|
|
|
|
<auth::AuthComponents onauthdone=onauthdone/>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-11-01 16:30:23 +00:00
|
|
|
<footer class="footer">
|
2021-11-03 16:03:35 +00:00
|
|
|
{ "Powered by " }
|
|
|
|
<a href="https://yew.rs">{ "Yew" }</a>
|
2021-11-01 16:30:23 +00:00
|
|
|
</footer>
|
|
|
|
</>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl App {
|
|
|
|
fn view_nav(&self) -> Html {
|
|
|
|
html! {
|
|
|
|
<nav class="navbar" role="navigation" aria-label="main navigation">
|
|
|
|
<div class=classes!("navbar-menu")>
|
|
|
|
<RouterAnchor<AppRoute> classes="navbar-item" route=AppRoute::Home>
|
|
|
|
{ "Home" }
|
|
|
|
</RouterAnchor<AppRoute>>
|
2021-11-08 12:29:24 +00:00
|
|
|
// <RouterAnchor<AppRoute> classes="navbar-item" route=AppRoute::Ssh>
|
|
|
|
// { "Ssh" }
|
|
|
|
// </RouterAnchor<AppRoute>>
|
2021-11-01 16:30:23 +00:00
|
|
|
</div>
|
|
|
|
</nav>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn switch(switch: AppRoute) -> Html {
|
|
|
|
ConsoleService::log(&format!("{:?}", switch));
|
|
|
|
match switch {
|
|
|
|
// Route::Ssh(ip) => {
|
|
|
|
// html! { <Ssh /> }
|
|
|
|
// }
|
2021-11-08 12:29:24 +00:00
|
|
|
// AppRoute::Ssh => {
|
|
|
|
// html! {<PageSsh />}
|
|
|
|
// }
|
2021-11-01 16:30:23 +00:00
|
|
|
AppRoute::Home => {
|
|
|
|
html! {<PageHome />}
|
|
|
|
}
|
|
|
|
AppRoute::NotFound => {
|
|
|
|
html! { <PageNotFound /> }
|
|
|
|
}
|
2021-11-01 13:36:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|