From db180a66ed8c2062d39604f8ede74def6112df71 Mon Sep 17 00:00:00 2001 From: Adam <24621027+adoyle0@users.noreply.github.com> Date: Sun, 25 Aug 2024 15:57:41 -0400 Subject: [PATCH] separate submit/judge --- client/src/components/game.rs | 58 +++++++++++++++++------------------ lib/src/lib.rs | 2 +- 2 files changed, 29 insertions(+), 31 deletions(-) diff --git a/client/src/components/game.rs b/client/src/components/game.rs index 924dee8..3342b16 100644 --- a/client/src/components/game.rs +++ b/client/src/components/game.rs @@ -9,6 +9,11 @@ use std::collections::HashMap; #[component] pub fn Game() -> impl IntoView { let websocket = expect_context::(); + let tx = websocket.clone(); + let (websocket_send, set_websocket_send) = create_signal("".to_string()); + create_effect(move |_| { + tx.send(&websocket_send()); + }); let connected = move || websocket.ready_state.get() == ConnectionReadyState::Open; let game_meta = expect_context::>>(); let judge_round = expect_context::>>(); @@ -61,9 +66,6 @@ pub fn Game() -> impl IntoView { set_card_clicked.update(|list| { list.clear(); }); - set_selected_cards_ordered.update(|list| { - list.clear(); - }); // Load hand if let Some(judge) = judge_round { @@ -148,33 +150,24 @@ pub fn Game() -> impl IntoView { } }); - let submit_cards = move |_| { - let tx = websocket.clone(); - judge_round.with(move |judge| { - let mut _message: Option = None; - - if judge.is_some() { - _message = Some( - to_string(&JudgeDecisionRequest { - game_id: game_id(), - winning_cards: selected_cards_ordered(), - }) - .unwrap(), - ); - } else { - _message = Some( - to_string(&PlayerMoveRequest { - game_id: game_id(), - card_ids: selected_cards_ordered(), - }) - .unwrap(), - ); - } - - if let Some(msg) = _message { - tx.send(&msg); - } + let submit_move = move |_| { + let msg = to_string(&PlayerMoveRequest { + game_id: game_id(), + card_ids: selected_cards_ordered(), }) + .unwrap(); + + set_websocket_send(msg); + }; + + let submit_judge = move |_| { + let msg = to_string(&JudgeDecisionRequest { + game_id: game_id(), + winning_cards: selected_cards_ordered(), + }) + .unwrap(); + + set_websocket_send(msg); }; view! { @@ -232,10 +225,15 @@ pub fn Game() -> impl IntoView { />
-
+
+ +
// Player cards
diff --git a/lib/src/lib.rs b/lib/src/lib.rs index 3ac5474..918ebdf 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -8,7 +8,7 @@ pub struct JudgeDecisionRequest { } /// Judge round -#[derive(Debug, Serialize, Deserialize)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub struct JudgeRound { pub cards_to_judge: Vec>, }