create_game bandaid

This commit is contained in:
Adam 2024-08-27 23:51:51 -04:00
parent 3b19854898
commit 103a92b486

View file

@ -10,20 +10,38 @@ use std::collections::BTreeSet;
pub fn CreateGame() -> impl IntoView {
// Websocket stuff
let websocket = expect_context::<WebSocketContext>();
let connected = move || websocket.ready_state.get() == ConnectionReadyState::Open;
let tx = websocket.clone();
let (websocket_send, set_websocket_send) = create_signal("".to_string());
let connected = move || websocket.ready_state.get() == ConnectionReadyState::Open;
let tx = websocket.clone();
create_effect(move |_| {
tx.send(&websocket_send());
if websocket_send() != "".to_string() {
tx.send(&websocket_send());
}
});
// New game stuff
let card_packs = expect_context::<ReadSignal<CardPacksMeta>>();
let new_game_name_ref = create_node_ref::<Input>();
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<u8>>(BTreeSet::new());
let new_game = move |_| {
create_effect(move |_| {
set_selected_packs
.update(|set| set.extend(card_packs().official_meta.iter().map(|pack| pack.pack)));
});
create_effect(move |_| {
set_selected_packs
.update(|set| set.extend(card_packs().unofficial_meta.iter().map(|pack| pack.pack)));
});
let new_game_name_ref = create_node_ref::<Input>();
let toggle_show_packs = move |_| set_show_packs(!show_packs());
let request_new_game = move |_| {
if let Some(input) = new_game_name_ref.get() {
if input.value() == *"" {
logging::log!("New game name is empty!");
@ -46,7 +64,7 @@ pub fn CreateGame() -> impl IntoView {
<div class="my-2">
<Show when=move || connected() fallback=|| view! { <p>Disconnected.</p> }>
<div class="flex">
<form onsubmit="return false" on:submit=new_game>
<form onsubmit="return false" on:submit=request_new_game>
<h2 class="text-2xl">Create Game</h2>
<input
class="w-80 h-11 font-mono rounded-sm bg-neutral-900 text-neutral-200"
@ -56,18 +74,18 @@ pub fn CreateGame() -> impl IntoView {
/>
<h2 class="text-2xl">Packs</h2>
<div class="p-2">
<button type="button" class="bg-neutral-600">
<input type="checkbox" id="all" checked />
<label for="all">All</label>
// <button type="button" class="bg-neutral-600">
// <input type="checkbox" id="official" checked />
// <label for="official">Official</label>
// </button>
// <button type="button" class="bg-neutral-600">
// <input type="checkbox" id="unofficial" checked />
// <label for="unofficial">Unofficial</label>
// </button>
<p>"All 205 card packs are enabled by default"</p>
<button type="button" class="bg-neutral-600" on:click=toggle_show_packs>
<label>Customize</label>
</button>
<button type="button" class="bg-neutral-600">
<input type="checkbox" id="official" />
<label for="official">Official</label>
</button>
<button type="button" class="bg-neutral-600" on:click=show_packs_button>
<label>Custom</label>
</button>
"click custom at least once for the new game button to work. there are worse problems right now (sorry (kinda))"
</div>
<Show when=move || show_packs()>
<span class="flex">