diff --git a/client/src/components/browser.rs b/client/src/components/browser.rs index a20fc9a..cec1d5a 100644 --- a/client/src/components/browser.rs +++ b/client/src/components/browser.rs @@ -1,31 +1,46 @@ use crate::components::websocket::WebSocketContext; use leptos::*; use leptos_use::core::ConnectionReadyState; -use lib::models::GamesUpdate; +use lib::models::*; +use serde_json::to_string; #[component] pub fn Browser() -> impl IntoView { let websocket = expect_context::(); - let game_update_context = expect_context::>>(); + let connected = move || websocket.ready_state.get() == ConnectionReadyState::Open; + let game_update_context = expect_context::>>(); let (active_games, set_active_games) = create_signal::>(vec![]); + let fake_new_game_request = NewGameRequest { + name: String::from("Ligma"), + host: Player { + name: String::from("Adam"), + role: PlayerRole::Host, + white: vec![], + black: vec![], + }, + packs: vec![0], + }; + + // Game stuff + let new_game_test = move |_| { + (websocket.send)(&to_string(&fake_new_game_request).unwrap()); + }; + create_effect(move |_| { game_update_context.with(move |games| { if let Some(games) = games { set_active_games(games.games.clone()); - logging::log!("{:#?}",active_games()); } }) }); // Clear games list on disconnect create_effect(move |_| { - websocket.ready_state.with(move |status| { - if *status == ConnectionReadyState::Closed { - set_active_games(vec![]); - } - }) + if !connected() { + set_active_games(vec![]); + } }); view! { @@ -34,6 +49,9 @@ pub fn Browser() -> impl IntoView {

Game Browser

{move || active_games().into_iter().map(|n| view! {
  • {n}
  • }).collect_view()} + } } diff --git a/client/src/components/debug.rs b/client/src/components/debug.rs index 8590772..9fb072f 100644 --- a/client/src/components/debug.rs +++ b/client/src/components/debug.rs @@ -2,7 +2,6 @@ use crate::components::websocket::WebSocketContext; use leptos::*; use leptos_use::core::ConnectionReadyState; use lib::models::*; -use serde_json::to_string; #[component] pub fn Debug() -> impl IntoView { @@ -26,22 +25,6 @@ pub fn Debug() -> impl IntoView { set_active_games(0); }; - let fake_new_game_request = NewGameRequest { - name: String::from("Ligma"), - host: Player { - name: String::from("Adam"), - role: PlayerRole::Host, - white: vec![], - black: vec![], - }, - packs: vec![0], - }; - - // Game stuff - let new_game_test = move |_| { - (websocket.send)(&to_string(&fake_new_game_request).unwrap()); - }; - // Update server info -> move this to a new component create_effect(move |_| { state_summary.with(move |state_summary| { @@ -66,9 +49,6 @@ pub fn Debug() -> impl IntoView { - }