use crate::components::websocket::WebSocketContext; use leptos::html::Input; use leptos::*; use leptos_use::core::ConnectionReadyState; use lib::models::*; use serde_json::to_string; #[component] pub fn Browser() -> impl IntoView { let websocket = 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 new_game_input_ref = create_node_ref::(); // Game stuff let new_game = move |_| { (websocket.send)( &to_string(&NewGameRequest { name: new_game_input_ref.get().unwrap().value(), }) .unwrap(), ); new_game_input_ref.get().unwrap().set_value(""); }; create_effect(move |_| { game_update_context.with(move |games| { if let Some(games) = games { set_active_games(games.games.clone()); } }) }); // Clear games list on disconnect create_effect(move |_| { if !connected() { set_active_games(vec![]); } }); view! {

    Game Browser

    {move || active_games().into_iter().map(|n| view! {
  • {n}
  • }).collect_view()}
} }