diff --git a/src/main.rs b/src/main.rs index 4ac739a..5237874 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,7 +4,7 @@ use std::{borrow::Borrow, future::IntoFuture, io::Read}; use ai::mcts_worker::{mcts_worker, MctsInput}; use futures::executor::LocalPool; use game::{Board, BoardState, Game, GameState, InvalidMoveError, Player, PlayerType, Position}; -use leptos::{component, create_action, create_effect, create_signal, ev::click, logging::log, mount_to_body, update, view, Callback, CollectView, IntoSignal, IntoView, ReadSignal, Signal, SignalGet, SignalGetUntracked, SignalSet, SignalUpdate, SignalWith, SignalWithUntracked}; +use leptos::{component, create_action, create_effect, create_signal, ev::click, logging::log, mount_to_body, update, view, Callback, CollectView, IntoSignal, IntoView, ReadSignal, Show, Signal, SignalGet, SignalGetUntracked, SignalSet, SignalUpdate, SignalWith, SignalWithUntracked}; use rand::{distributions::Alphanumeric, Rng}; use wasm_peers::{one_to_one::NetworkManager, ConnectionType, SessionId}; use web_sys::console; @@ -76,6 +76,7 @@ const STUN_SERVER_URL: &str = "stun:stun.relay.metered.ca:80"; #[component] fn OnlineGame(host: bool) -> impl IntoView { if host { + let (connected, set_connected) = create_signal(false); let (game, set_game) = create_signal(Game::new(Player::X, PlayerType::Local, PlayerType::Online)); let session_code: String = rand::thread_rng().sample_iter(&Alphanumeric).take(8).map(char::from).collect(); let opponent_url = { @@ -102,7 +103,7 @@ fn OnlineGame(host: bool) -> impl IntoView { let send_move = move |pos: Position| { server_clone.send_message(serde_json::to_string(&pos).unwrap().as_str()).unwrap() }; - server.start(||{}, server_on_message); + server.start(move ||{create_effect(move |_| set_connected.set(true));}, server_on_message); let game_view = { @@ -142,28 +143,29 @@ fn OnlineGame(host: bool) -> impl IntoView { out }; view! { -