Compare commits
No commits in common. "bbc48a6619f3436d125b19eee5c8169244c2fd13" and "a6681f31a07e1cb280de1d606f5656f1de3c2081" have entirely different histories.
bbc48a6619
...
a6681f31a0
3 changed files with 32 additions and 30 deletions
8
Cargo.lock
generated
8
Cargo.lock
generated
|
@ -226,9 +226,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bytes"
|
name = "bytes"
|
||||||
version = "1.7.1"
|
version = "1.7.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50"
|
checksum = "fca2be1d5c43812bae364ee3f30b3afcb7877cf59f4aeb94c66f313a41d2fac9"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "camino"
|
name = "camino"
|
||||||
|
@ -1675,9 +1675,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_json"
|
name = "serde_json"
|
||||||
version = "1.0.122"
|
version = "1.0.121"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "784b6203951c57ff748476b126ccb5e8e2959a5c19e5c617ab1956be3dbc68da"
|
checksum = "4ab380d7d9f22ef3f21ad3e6c1ebe8e4fc7a2000ccba2e4d71fc96f15b2cb609"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"itoa",
|
"itoa",
|
||||||
"memchr",
|
"memchr",
|
||||||
|
|
|
@ -1,46 +1,31 @@
|
||||||
use crate::components::websocket::WebSocketContext;
|
use crate::components::websocket::WebSocketContext;
|
||||||
use leptos::*;
|
use leptos::*;
|
||||||
use leptos_use::core::ConnectionReadyState;
|
use leptos_use::core::ConnectionReadyState;
|
||||||
use lib::models::*;
|
use lib::models::GamesUpdate;
|
||||||
use serde_json::to_string;
|
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
pub fn Browser() -> impl IntoView {
|
pub fn Browser() -> impl IntoView {
|
||||||
let websocket = expect_context::<WebSocketContext>();
|
let websocket = expect_context::<WebSocketContext>();
|
||||||
let connected = move || websocket.ready_state.get() == ConnectionReadyState::Open;
|
|
||||||
|
|
||||||
let game_update_context = expect_context::<ReadSignal<Option<GamesUpdate>>>();
|
let game_update_context = expect_context::<ReadSignal<Option<GamesUpdate>>>();
|
||||||
|
|
||||||
let (active_games, set_active_games) = create_signal::<Vec<String>>(vec![]);
|
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 |_| {
|
create_effect(move |_| {
|
||||||
game_update_context.with(move |games| {
|
game_update_context.with(move |games| {
|
||||||
if let Some(games) = games {
|
if let Some(games) = games {
|
||||||
set_active_games(games.games.clone());
|
set_active_games(games.games.clone());
|
||||||
|
logging::log!("{:#?}",active_games());
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
// Clear games list on disconnect
|
// Clear games list on disconnect
|
||||||
create_effect(move |_| {
|
create_effect(move |_| {
|
||||||
if !connected() {
|
websocket.ready_state.with(move |status| {
|
||||||
set_active_games(vec![]);
|
if *status == ConnectionReadyState::Closed {
|
||||||
}
|
set_active_games(vec![]);
|
||||||
|
}
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
view! {
|
view! {
|
||||||
|
@ -49,9 +34,6 @@ pub fn Browser() -> impl IntoView {
|
||||||
<h2 class="text-2xl">Game Browser</h2>
|
<h2 class="text-2xl">Game Browser</h2>
|
||||||
{move || active_games().into_iter().map(|n| view! { <li>{n}</li> }).collect_view()}
|
{move || active_games().into_iter().map(|n| view! { <li>{n}</li> }).collect_view()}
|
||||||
</ul>
|
</ul>
|
||||||
<button on:click=new_game_test disabled=move || !connected()>
|
|
||||||
"Test New Game"
|
|
||||||
</button>
|
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ use crate::components::websocket::WebSocketContext;
|
||||||
use leptos::*;
|
use leptos::*;
|
||||||
use leptos_use::core::ConnectionReadyState;
|
use leptos_use::core::ConnectionReadyState;
|
||||||
use lib::models::*;
|
use lib::models::*;
|
||||||
|
use serde_json::to_string;
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
pub fn Debug() -> impl IntoView {
|
pub fn Debug() -> impl IntoView {
|
||||||
|
@ -25,6 +26,22 @@ pub fn Debug() -> impl IntoView {
|
||||||
set_active_games(0);
|
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
|
// Update server info -> move this to a new component
|
||||||
create_effect(move |_| {
|
create_effect(move |_| {
|
||||||
state_summary.with(move |state_summary| {
|
state_summary.with(move |state_summary| {
|
||||||
|
@ -49,6 +66,9 @@ pub fn Debug() -> impl IntoView {
|
||||||
<button on:click=close_connection disabled=move || !connected()>
|
<button on:click=close_connection disabled=move || !connected()>
|
||||||
"Disconnect"
|
"Disconnect"
|
||||||
</button>
|
</button>
|
||||||
|
<button on:click=new_game_test disabled=move || !connected()>
|
||||||
|
"Test New Game"
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue