From 4d9b04659bfb3ecb76ec8488382299292e24fde4 Mon Sep 17 00:00:00 2001 From: Adam <24621027+adoyle0@users.noreply.github.com> Date: Tue, 27 Aug 2024 22:44:59 -0400 Subject: [PATCH] aestheticss and stop spamming empty strings on join --- client/src/components/browser.rs | 174 +++----------------------- client/src/components/create_game.rs | 176 +++++++++++++++++++++++++++ client/src/components/debug.rs | 3 +- client/src/components/game.rs | 2 +- client/src/components/mod.rs | 1 + client/src/pages/home.rs | 7 +- server/src/message_handler.rs | 2 +- 7 files changed, 201 insertions(+), 164 deletions(-) create mode 100644 client/src/components/create_game.rs diff --git a/client/src/components/browser.rs b/client/src/components/browser.rs index 405ec7e..41f56bb 100644 --- a/client/src/components/browser.rs +++ b/client/src/components/browser.rs @@ -13,19 +13,24 @@ pub fn Browser() -> impl IntoView { let connected = move || websocket.ready_state.get() == ConnectionReadyState::Open; let tx = websocket.clone(); let (websocket_send, set_websocket_send) = create_signal("".to_string()); + create_effect(move |_| { - tx.send(&websocket_send()); + if websocket_send() != "".to_string() { + tx.send(&websocket_send()); + } }); // Browser stuff let game_browser_context = expect_context::>>(); let (join_id, set_join_id) = create_signal("".to_string()); let (delete_id, set_delete_id) = create_signal("".to_string()); + create_effect(move |_| { - set_websocket_send(to_string(&GameJoinRequest { id: join_id() }).unwrap()); + set_websocket_send.set_untracked(to_string(&GameJoinRequest { id: join_id() }).unwrap()); }); + create_effect(move |_| { - set_websocket_send( + set_websocket_send.set_untracked( to_string(&GameDeleteRequest { delete_game_id: delete_id(), }) @@ -33,36 +38,14 @@ pub fn Browser() -> impl IntoView { ); }); - // New game stuff - let card_packs = expect_context::>(); - let new_game_name_ref = create_node_ref::(); - let (show_packs, set_show_packs) = create_signal(false); - let show_packs_button = move |_| set_show_packs(!show_packs()); - let (selected_packs, set_selected_packs) = create_signal::>(BTreeSet::new()); - let new_game = move |_| { - if let Some(input) = new_game_name_ref.get() { - if input.value() == *"" { - logging::log!("New game name is empty!"); - } else if selected_packs().is_empty() { - logging::log!("New game selected packs is empty!"); - } else { - set_websocket_send( - to_string(&NewGameRequest { - name: input.value(), - packs: selected_packs().into_iter().collect::>(), - }) - .unwrap(), - ); - input.set_value(""); - } - } - }; - view! { -
- Disconnected.

}> -

Game Browser

-

"Yes, the delete button works. Please don't abuse it."

+
+

Game Browser

+

"Yes, the delete button works. Please don't abuse it."

+ 0 } + fallback=|| view! { "No games to show right now.. Maybe you should create one!" } + >
@@ -114,133 +97,6 @@ pub fn Browser() -> impl IntoView { />
-
- -
-
-

Create Game

- -

Packs

-
- - - - "click custom at least once for the new game button to work. there are worse problems right now (sorry (kinda))" -
- - -
-

Official

- {move || { - card_packs() - .official_meta - .into_iter() - .map(|n| { - view! { - - - -
- - // hax - {set_selected_packs - .update(|packs| { - packs.insert(n.pack); - })} - } - }) - .collect_view() - }} - -
-
-

Unofficial

- {move || { - card_packs() - .unofficial_meta - .into_iter() - .map(|n| { - view! { - - - -
- - // hax - {set_selected_packs - .update(|packs| { - packs.insert(n.pack); - })} - } - }) - .collect_view() - }} - -
-
-
- - -
-
} diff --git a/client/src/components/create_game.rs b/client/src/components/create_game.rs new file mode 100644 index 0000000..684a172 --- /dev/null +++ b/client/src/components/create_game.rs @@ -0,0 +1,176 @@ +use crate::components::websocket::WebSocketContext; +use leptos::html::Input; +use leptos::*; +use leptos_use::core::ConnectionReadyState; +use lib::*; +use serde_json::to_string; +use std::collections::BTreeSet; + +#[component] +pub fn CreateGame() -> impl IntoView { + // Websocket stuff + let websocket = expect_context::(); + let connected = move || websocket.ready_state.get() == ConnectionReadyState::Open; + let tx = websocket.clone(); + let (websocket_send, set_websocket_send) = create_signal("".to_string()); + create_effect(move |_| { + tx.send(&websocket_send()); + }); + + // New game stuff + let card_packs = expect_context::>(); + let new_game_name_ref = create_node_ref::(); + let (show_packs, set_show_packs) = create_signal(false); + let show_packs_button = move |_| set_show_packs(!show_packs()); + let (selected_packs, set_selected_packs) = create_signal::>(BTreeSet::new()); + let new_game = move |_| { + if let Some(input) = new_game_name_ref.get() { + if input.value() == *"" { + logging::log!("New game name is empty!"); + } else if selected_packs().is_empty() { + logging::log!("New game selected packs is empty!"); + } else { + set_websocket_send( + to_string(&NewGameRequest { + name: input.value(), + packs: selected_packs().into_iter().collect::>(), + }) + .unwrap(), + ); + input.set_value(""); + } + } + }; + + view! { +
+ Disconnected.

}> +
+
+

Create Game

+ +

Packs

+
+ + + + "click custom at least once for the new game button to work. there are worse problems right now (sorry (kinda))" +
+ + +
+

Official

+ {move || { + card_packs() + .official_meta + .into_iter() + .map(|n| { + view! { + + + +
+ + // hax + {set_selected_packs + .update(|packs| { + packs.insert(n.pack); + })} + } + }) + .collect_view() + }} + +
+
+

Unofficial

+ {move || { + card_packs() + .unofficial_meta + .into_iter() + .map(|n| { + view! { + + + +
+ + // hax + {set_selected_packs + .update(|packs| { + packs.insert(n.pack); + })} + } + }) + .collect_view() + }} + +
+
+
+ + +
+
+
+
+ } +} diff --git a/client/src/components/debug.rs b/client/src/components/debug.rs index 568fd36..c370cb8 100644 --- a/client/src/components/debug.rs +++ b/client/src/components/debug.rs @@ -36,8 +36,7 @@ pub fn Debug() -> impl IntoView { }); view! { -
-
+

Debug:

"Connection Status: " {status}

"Users Online: " {online_users}

diff --git a/client/src/components/game.rs b/client/src/components/game.rs index f1a77fa..f4b5910 100644 --- a/client/src/components/game.rs +++ b/client/src/components/game.rs @@ -163,7 +163,7 @@ pub fn Game() -> impl IntoView { }); view! { -
+

Game

impl IntoView {

+ +



- git +
+ git +

diff --git a/server/src/message_handler.rs b/server/src/message_handler.rs index 3959710..aa1bd51 100644 --- a/server/src/message_handler.rs +++ b/server/src/message_handler.rs @@ -95,7 +95,7 @@ impl MessageHandler { .unwrap(); } - _ => tracing::debug!("Unhandled text from {}", addr), + _ => tracing::debug!("Unhandled text from {}\n{:#?}", addr, &text), }, Message::Binary(data) => tracing::debug!("{} sent binary: {:?}", addr, data),