use crate::components::websocket::WebSocketContext; use leptos::prelude::*; use leptos_use::core::ConnectionReadyState; use lib::*; use serde_json::to_string; use thaw::*; pub mod create_game; #[component] pub fn Browser() -> impl IntoView { // Websocket stuff let websocket = expect_context::(); let connected = move || websocket.ready_state.get() == ConnectionReadyState::Open; let tx = websocket.clone(); let (websocket_send, set_websocket_send) = signal("".to_string()); Effect::new(move |_| { if websocket_send() != "".to_string() { tx.send(&websocket_send()); } }); // Browser stuff let game_browser_context = expect_context::>>(); let join_id = RwSignal::new("".to_string()); let delete_id = RwSignal::new("".to_string()); let nav_context = expect_context::>(); Effect::new(move |_| { if join_id() != "" { set_websocket_send(to_string(&GameJoinRequest { id: join_id() }).unwrap()); nav_context.set("game".to_string()); join_id.set("".to_string()); } }); Effect::new(move |_| { if delete_id() != "" { set_websocket_send( to_string(&GameDeleteRequest { delete_game_id: delete_id(), }) .unwrap(), ); delete_id.set("".to_string()); } }); let show_create_game = RwSignal::new(false); provide_context(show_create_game); view! {
"Disconnected."

}> 0 } fallback=|| { view! {

"No games to show right now.. Maybe you should create one!"

} } >

Name

Host

Players

Card Packs

// This rebuilds the entire browser each time it runs but using won't update the children if the id doesn't change {move || { game_browser_context() .iter() .cloned() .map(|game| { view! {

{game.name}

{game.host} {game.players} {game.packs.len()}
} }) .collect_view() }}
} }