From ddeace030e909ed8e22747f74d6c2e2018440911 Mon Sep 17 00:00:00 2001 From: Kjetil Orbekk Date: Thu, 24 Nov 2022 20:38:30 -0500 Subject: Serve webapp from localhost; fix an issue when not logged in --- webapp/Trunk.toml | 4 ++-- webapp/src/components/app_context_provider.rs | 9 ++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/webapp/Trunk.toml b/webapp/Trunk.toml index 8c891da..e053ef1 100644 --- a/webapp/Trunk.toml +++ b/webapp/Trunk.toml @@ -4,8 +4,8 @@ dist = "dist" [serve] address = "::" -port = 11120 +port = 8080 watch = ["src"] [[proxy]] -backend = "http://localhost:11121/api/" \ No newline at end of file +backend = "http://localhost:8081/api/" \ No newline at end of file diff --git a/webapp/src/components/app_context_provider.rs b/webapp/src/components/app_context_provider.rs index bba7e33..4c9e18f 100644 --- a/webapp/src/components/app_context_provider.rs +++ b/webapp/src/components/app_context_provider.rs @@ -93,7 +93,7 @@ pub struct Props { pub children: Children, } -async fn initialize_user_info() -> Result { +async fn initialize_user_info() -> Result, anyhow::Error> { let response = Request::get("/api/user/info").send().await?; if response.status() == 401 { web_sys::window() @@ -115,17 +115,20 @@ pub fn use_app_context() -> AppContext { #[function_component(AppContextProvider)] pub fn app_context_provider(props: &Props) -> Html { + let initialized = use_state(|| false); let user: UseStateHandle> = use_state(|| None); let error: UseStateHandle> = use_state(|| None); { + let initialized = initialized.clone(); let user = user.clone(); let error = error.clone(); use_effect_with_deps( move |_| { spawn_local(async move { + initialized.set(true); match initialize_user_info().await { - Ok(user_info) => user.set(Some(user_info)), + Ok(user_info) => user.set(user_info), Err(e) => error.set(Some(ErrorInfoProperties { message: format!("Could not contact server: {:?}", e), })), @@ -137,7 +140,7 @@ pub fn app_context_provider(props: &Props) -> Html { ); } - if user.is_none() && error.is_none() { + if !*initialized { return html! {

{ "Loading app..." }

}; -- cgit v1.2.3