diff --git a/app/src/components/app.rs b/app/src/components/app.rs index c947345..222397f 100644 --- a/app/src/components/app.rs +++ b/app/src/components/app.rs @@ -92,10 +92,8 @@ impl Component for App { redirect_to: Self::get_redirect_route(ctx), password_reset_enabled: None, }; - let link = ctx.link().clone(); - wasm_bindgen_futures::spawn_local(async move { - let result = HostService::probe_password_reset().await; - link.send_message(Msg::PasswordResetProbeFinished(result)); + ctx.link().send_future(async move { + Msg::PasswordResetProbeFinished(HostService::probe_password_reset().await) }); app.apply_initial_redirections(ctx); app @@ -157,47 +155,41 @@ impl Component for App { } impl App { + // Get the page to land on after logging in, defaulting to the index. fn get_redirect_route(ctx: &Context) -> Option { - let history = ctx.link().history().unwrap(); - let route = history.location().route::(); - route.and_then(|route| match route { - AppRoute::Index - | AppRoute::Login - | AppRoute::StartResetPassword - | AppRoute::FinishResetPassword { token: _ } => None, - _ => Some(route), + let route = ctx.link().history().unwrap().location().route::(); + route.filter(|route| { + !matches!( + route, + AppRoute::Index + | AppRoute::Login + | AppRoute::StartResetPassword + | AppRoute::FinishResetPassword { token: _ } + ) }) } fn apply_initial_redirections(&self, ctx: &Context) { let history = ctx.link().history().unwrap(); let route = history.location().route::(); - let redirection = if let Some(route) = route { - if matches!( - route, - AppRoute::StartResetPassword | AppRoute::FinishResetPassword { token: _ } - ) && self.password_reset_enabled == Some(false) - { - Some(AppRoute::Login) - } else { - match &self.user_info { - None => Some(AppRoute::Login), - Some((user_name, is_admin)) => match &self.redirect_to { - Some(url) => Some(url.clone()), - None => { - if *is_admin { - Some(AppRoute::ListUsers) - } else { - Some(AppRoute::UserDetails { - user_id: user_name.clone(), - }) - } - } - }, + let redirection = match (route, &self.user_info, &self.redirect_to) { + ( + Some(AppRoute::StartResetPassword | AppRoute::FinishResetPassword { token: _ }), + _, + _, + ) if self.password_reset_enabled == Some(false) => Some(AppRoute::Login), + (None, _, _) | (_, None, _) => Some(AppRoute::Login), + // User is logged in, a URL was given, don't redirect. + (_, Some(_), Some(_)) => None, + (_, Some((user_name, is_admin)), None) => { + if *is_admin { + Some(AppRoute::ListUsers) + } else { + Some(AppRoute::UserDetails { + user_id: user_name.clone(), + }) } } - } else { - Some(AppRoute::Login) }; if let Some(redirect_to) = redirection { history.push(redirect_to); @@ -340,6 +332,7 @@ impl App { } } else { html!{} } } + { self.view_user_menu(ctx) } // TODO migrate chagnes from above @@ -347,6 +340,52 @@ impl App { } } + fn view_user_menu(&self, ctx: &Context) -> Html { + if let Some((user_id, _)) = &self.user_info { + let link = ctx.link(); + html! { + + } + } else { + html! {} + } + } + fn view_footer(&self) -> Html { html! {