summaryrefslogtreecommitdiff
path: root/webapp/src/components
diff options
context:
space:
mode:
authorKjetil Orbekk <kj@orbekk.com>2022-11-24 20:38:30 -0500
committerKjetil Orbekk <kj@orbekk.com>2022-11-24 20:38:30 -0500
commitddeace030e909ed8e22747f74d6c2e2018440911 (patch)
treee761b37c19ea036fc180416380c94d4537d4472d /webapp/src/components
parent05a657661fe08ebc364d005b008a3408c5a0d15f (diff)
Serve webapp from localhost; fix an issue when not logged in
Diffstat (limited to 'webapp/src/components')
-rw-r--r--webapp/src/components/app_context_provider.rs9
1 files changed, 6 insertions, 3 deletions
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<UserInfo, anyhow::Error> {
+async fn initialize_user_info() -> Result<Option<UserInfo>, 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<Option<UserInfo>> = use_state(|| None);
let error: UseStateHandle<Option<ErrorInfoProperties>> = 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! {
<p>{ "Loading app..." }</p>
};