Compare commits
2 commits
a6681f31a0
...
bbc48a6619
Author | SHA1 | Date | |
---|---|---|---|
|
bbc48a6619 | ||
|
dd36a5f455 |
3 changed files with 30 additions and 32 deletions
8
Cargo.lock
generated
8
Cargo.lock
generated
|
@ -226,9 +226,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
|
|||
|
||||
[[package]]
|
||||
name = "bytes"
|
||||
version = "1.7.0"
|
||||
version = "1.7.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fca2be1d5c43812bae364ee3f30b3afcb7877cf59f4aeb94c66f313a41d2fac9"
|
||||
checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50"
|
||||
|
||||
[[package]]
|
||||
name = "camino"
|
||||
|
@ -1675,9 +1675,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.121"
|
||||
version = "1.0.122"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4ab380d7d9f22ef3f21ad3e6c1ebe8e4fc7a2000ccba2e4d71fc96f15b2cb609"
|
||||
checksum = "784b6203951c57ff748476b126ccb5e8e2959a5c19e5c617ab1956be3dbc68da"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"memchr",
|
||||
|
|
|
@ -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::<WebSocketContext>();
|
||||
let game_update_context = expect_context::<ReadSignal<Option<GamesUpdate>>>();
|
||||
let connected = move || websocket.ready_state.get() == ConnectionReadyState::Open;
|
||||
|
||||
let game_update_context = expect_context::<ReadSignal<Option<GamesUpdate>>>();
|
||||
let (active_games, set_active_games) = create_signal::<Vec<String>>(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 {
|
||||
if !connected() {
|
||||
set_active_games(vec![]);
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
view! {
|
||||
|
@ -34,6 +49,9 @@ pub fn Browser() -> impl IntoView {
|
|||
<h2 class="text-2xl">Game Browser</h2>
|
||||
{move || active_games().into_iter().map(|n| view! { <li>{n}</li> }).collect_view()}
|
||||
</ul>
|
||||
<button on:click=new_game_test disabled=move || !connected()>
|
||||
"Test New Game"
|
||||
</button>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
|||
<button on:click=close_connection disabled=move || !connected()>
|
||||
"Disconnect"
|
||||
</button>
|
||||
<button on:click=new_game_test disabled=move || !connected()>
|
||||
"Test New Game"
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue