From 94cf11e1c2e2e567a0760b45ec52cb9a15a024d3 Mon Sep 17 00:00:00 2001 From: xeovalyte Date: Tue, 9 Apr 2024 15:23:29 +0200 Subject: [PATCH] Added frontend status of websocket connectoin --- application/src/components/header.rs | 4 +++- application/src/pages/add_time.rs | 1 - application/src/util/websocket/client.rs | 2 ++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/application/src/components/header.rs b/application/src/components/header.rs index e8291e1..41bbe7e 100644 --- a/application/src/components/header.rs +++ b/application/src/components/header.rs @@ -1,15 +1,17 @@ use leptos::*; use leptos_router::*; +use leptos_use::core::ConnectionReadyState; /// Renders the home page of your application. #[component] pub fn Header() -> impl IntoView { + let ready_state = use_context::>(); // Creates a reactive value to update the button view! {
"WRB Timings" -
Connection: ???
+
"Connection: " { move || format!("{}", ready_state.unwrap().get()) }
} diff --git a/application/src/pages/add_time.rs b/application/src/pages/add_time.rs index 03433ea..acbb404 100644 --- a/application/src/pages/add_time.rs +++ b/application/src/pages/add_time.rs @@ -1,6 +1,5 @@ use crate::util::surrealdb::schemas; use leptos::{ev::keydown, *}; -use leptos_router::{ActionForm, FromFormData}; use leptos_use::*; use strsim::normalized_damerau_levenshtein; use web_sys::ScrollIntoViewOptions; diff --git a/application/src/util/websocket/client.rs b/application/src/util/websocket/client.rs index b27544e..7b0bb28 100644 --- a/application/src/util/websocket/client.rs +++ b/application/src/util/websocket/client.rs @@ -11,6 +11,8 @@ pub fn init_websocket() { .. } = use_websocket("ws://localhost:3000/ws"); + provide_context(ready_state); + create_effect(move |prev_value| { let msg = message.get();