clear game state on disconnect
This commit is contained in:
parent
69bc1714f4
commit
77ac313070
1 changed files with 19 additions and 0 deletions
|
@ -1,6 +1,7 @@
|
||||||
use crate::components::cards::*;
|
use crate::components::cards::*;
|
||||||
use crate::components::websocket::WebSocketContext;
|
use crate::components::websocket::WebSocketContext;
|
||||||
use leptos::*;
|
use leptos::*;
|
||||||
|
use leptos_use::core::ConnectionReadyState;
|
||||||
use lib::*;
|
use lib::*;
|
||||||
use serde_json::to_string;
|
use serde_json::to_string;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
@ -8,6 +9,7 @@ use std::collections::HashMap;
|
||||||
#[component]
|
#[component]
|
||||||
pub fn Game() -> impl IntoView {
|
pub fn Game() -> impl IntoView {
|
||||||
let websocket = expect_context::<WebSocketContext>();
|
let websocket = expect_context::<WebSocketContext>();
|
||||||
|
let connected = move || websocket.ready_state.get() == ConnectionReadyState::Open;
|
||||||
let game_meta = expect_context::<ReadSignal<Option<GameStateMeta>>>();
|
let game_meta = expect_context::<ReadSignal<Option<GameStateMeta>>>();
|
||||||
let judge_round = expect_context::<ReadSignal<Option<JudgeRound>>>();
|
let judge_round = expect_context::<ReadSignal<Option<JudgeRound>>>();
|
||||||
|
|
||||||
|
@ -24,6 +26,23 @@ pub fn Game() -> impl IntoView {
|
||||||
let (card_clicked, set_card_clicked) = create_signal::<String>(String::new());
|
let (card_clicked, set_card_clicked) = create_signal::<String>(String::new());
|
||||||
provide_context::<WriteSignal<String>>(set_card_clicked);
|
provide_context::<WriteSignal<String>>(set_card_clicked);
|
||||||
|
|
||||||
|
// Clear everything on disconnect
|
||||||
|
create_effect(move |_| {
|
||||||
|
if !connected() {
|
||||||
|
set_game_id("".to_string());
|
||||||
|
set_game_name("".to_string());
|
||||||
|
set_game_host("".to_string());
|
||||||
|
set_game_players(vec![]);
|
||||||
|
set_game_czar("".to_string());
|
||||||
|
set_game_black(("".to_string(), 0u8));
|
||||||
|
set_selected_cards_ordered(vec![]);
|
||||||
|
set_player_hand(vec![]);
|
||||||
|
set_player_white.update(|hand| {
|
||||||
|
hand.clear();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Handle incoming judge message
|
// Handle incoming judge message
|
||||||
create_effect(move |_| {
|
create_effect(move |_| {
|
||||||
judge_round.with(move |judge_round| {
|
judge_round.with(move |judge_round| {
|
||||||
|
|
Loading…
Add table
Reference in a new issue