diff --git a/client/src/components/debug.rs b/client/src/components/debug.rs index 1cdd364..7a841db 100644 --- a/client/src/components/debug.rs +++ b/client/src/components/debug.rs @@ -7,11 +7,12 @@ use thaw::*; #[component] pub fn Debug() -> impl IntoView { let websocket = expect_context::(); - let state_summary = expect_context::>>(); + let server_online_users = expect_context::>>(); + let server_active_games = expect_context::>>(); // Signals - let (online_users, set_online_users) = signal(0); - let (active_games, set_active_games) = signal(0); + let user_count = RwSignal::new(0); + let game_count = RwSignal::new(0); // Websocket stuff let status = move || websocket.ready_state.get().to_string(); @@ -27,17 +28,24 @@ pub fn Debug() -> impl IntoView { let close_connection = move |_| { (websocket.close)(); - set_online_users(0); - set_active_games(0); + user_count.set(0); + game_count.set(0); }; - // Update server info -> move this to a new component + // Update data on incoming updates Effect::new(move |_| { - state_summary.with(move |state_summary| { - if let Some(state_summary) = state_summary { - set_online_users(state_summary.online_users); - set_active_games(state_summary.active_games); - } + server_online_users.with(move |server_online_users| { + if let Some(online_users) = server_online_users { + user_count.set(online_users.online_users); + }; + }) + }); + + Effect::new(move |_| { + server_active_games.with(move |server_active_games| { + if let Some(active_games) = server_active_games { + game_count.set(active_games.active_games); + }; }) }); @@ -45,8 +53,8 @@ pub fn Debug() -> impl IntoView {

Debug:

"Connection Status: " {status}

-

"Users Online: " {online_users}

-

"Active Games: " {active_games}

+

"Users Online: " {user_count}

+

"Active Games: " {game_count}