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 Browser() -> impl IntoView { let websocket = expect_context::(); let connected = move || websocket.ready_state.get() == ConnectionReadyState::Open; let game_update_context = expect_context::>>(); let card_packs = expect_context::>(); let (active_games, set_active_games) = create_signal::>(vec![]); let new_game_name_ref = create_node_ref::(); let (selected_packs, set_selected_packs) = create_signal::>(BTreeSet::new()); // create_effect(move |_| { // logging::log!("{:#?}", selected_packs().iter().collect::>()); // }); // Game stuff let new_game = move |_| { if let Some(input) = new_game_name_ref.get() { if input.value() != String::from("") { (websocket.send)( &to_string(&NewGameRequest { name: input.value(), packs: selected_packs() .into_iter() .map(|n| n.clone()) // hax .collect::>(), }) .unwrap(), ); input.set_value(""); } } }; create_effect(move |_| { game_update_context.with(move |games| { if let Some(games) = games { set_active_games(games.games.clone()); } }) }); // Clear games list on disconnect create_effect(move |_| { if !connected() { set_active_games(vec![]); } }); let (show_packs, set_show_packs) = create_signal(false); let show_packs_button = move |_| set_show_packs(!show_packs()); view! {

Game Browser

    {move || active_games().into_iter().map(|n| view! {
  • {n}
  • }).collect_view()}

Create Game

Packs

finish this

Official

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

Unofficial

{move || { card_packs() .unofficial_meta .into_iter() .map(|n| { view! {
} }) .collect_view() }}
} }