fix mismatches
This commit is contained in:
parent
791651a9da
commit
e30de2ac9e
3 changed files with 38 additions and 21 deletions
|
@ -10,6 +10,7 @@ pub fn JudgingView() -> impl IntoView {
|
||||||
let websocket = expect_context::<WebSocketContext>();
|
let websocket = expect_context::<WebSocketContext>();
|
||||||
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>>>();
|
||||||
|
let set_judge_round = expect_context::<WriteSignal<Option<JudgeRound>>>();
|
||||||
|
|
||||||
// Signals
|
// Signals
|
||||||
let (selected_cards, set_selected_cards) = create_signal::<Vec<WhiteCardMeta>>(vec![]);
|
let (selected_cards, set_selected_cards) = create_signal::<Vec<WhiteCardMeta>>(vec![]);
|
||||||
|
@ -78,6 +79,8 @@ pub fn JudgingView() -> impl IntoView {
|
||||||
set_selected_cards.update(|list| {
|
set_selected_cards.update(|list| {
|
||||||
list.clear();
|
list.clear();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
set_judge_round(None);
|
||||||
};
|
};
|
||||||
|
|
||||||
view! {
|
view! {
|
||||||
|
|
|
@ -13,7 +13,9 @@ pub fn PlayingView() -> impl IntoView {
|
||||||
|
|
||||||
// Signals
|
// Signals
|
||||||
let (selected_cards, set_selected_cards) = create_signal::<Vec<WhiteCardMeta>>(vec![]);
|
let (selected_cards, set_selected_cards) = create_signal::<Vec<WhiteCardMeta>>(vec![]);
|
||||||
|
let (submitted_cards, set_submitted_cards) = create_signal::<Vec<WhiteCardMeta>>(vec![]);
|
||||||
let (card_clicked, set_card_clicked) = create_signal::<String>(String::new());
|
let (card_clicked, set_card_clicked) = create_signal::<String>(String::new());
|
||||||
|
let (submitted, set_submitted) = create_signal(false);
|
||||||
let (player_hand, set_player_hand) =
|
let (player_hand, set_player_hand) =
|
||||||
create_signal::<HashMap<String, WhiteCardMeta>>(HashMap::new());
|
create_signal::<HashMap<String, WhiteCardMeta>>(HashMap::new());
|
||||||
|
|
||||||
|
@ -34,33 +36,38 @@ pub fn PlayingView() -> impl IntoView {
|
||||||
set_selected_cards.update(|list| {
|
set_selected_cards.update(|list| {
|
||||||
list.clear();
|
list.clear();
|
||||||
});
|
});
|
||||||
|
set_submitted_cards.update(|list| {
|
||||||
|
list.clear();
|
||||||
|
});
|
||||||
|
set_submitted(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Card selection //
|
// Card selection
|
||||||
// Toggle selected status of cards
|
// Toggle selected status of cards
|
||||||
create_effect(move |_| {
|
create_effect(move |_| {
|
||||||
if card_clicked() != "".to_string() {
|
if card_clicked() != "".to_string()
|
||||||
if !selected_cards.get_untracked().contains(
|
&& submitted_cards().len() < game_meta().unwrap().black.1.into()
|
||||||
player_hand
|
{
|
||||||
|
if let Some(clicked_card) = player_hand
|
||||||
.get_untracked()
|
.get_untracked()
|
||||||
.get(&card_clicked.get_untracked())
|
.get(&card_clicked.get_untracked())
|
||||||
.unwrap(),
|
|
||||||
) {
|
|
||||||
set_selected_cards
|
|
||||||
.update(|cards| cards.push(player_hand().get(&card_clicked()).unwrap().clone()))
|
|
||||||
} else if selected_cards
|
|
||||||
.get_untracked()
|
|
||||||
.contains(player_hand.get_untracked().get(&card_clicked()).unwrap())
|
|
||||||
{
|
{
|
||||||
set_selected_cards.update(|cards| {
|
if !selected_cards.get_untracked().contains(clicked_card) {
|
||||||
cards.remove(
|
set_selected_cards.update(|cards| cards.push(clicked_card.to_owned()))
|
||||||
cards
|
} else if selected_cards.get_untracked().contains(clicked_card)
|
||||||
.iter()
|
&& !submitted_cards.get_untracked().contains(clicked_card)
|
||||||
.position(|card| card == player_hand().get(&card_clicked()).unwrap())
|
{
|
||||||
.unwrap(),
|
logging::log!(
|
||||||
|
"{:#?}\n{:#?}\n{:#?}",
|
||||||
|
clicked_card,
|
||||||
|
selected_cards(),
|
||||||
|
submitted_cards()
|
||||||
);
|
);
|
||||||
|
set_selected_cards.update(|cards| {
|
||||||
|
cards.remove(cards.iter().position(|card| card == clicked_card).unwrap());
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// Clear the signal otherwise it selects the last selected card again
|
// Clear the signal otherwise it selects the last selected card again
|
||||||
set_card_clicked.update_untracked(|value| value.clear());
|
set_card_clicked.update_untracked(|value| value.clear());
|
||||||
}
|
}
|
||||||
|
@ -77,10 +84,15 @@ pub fn PlayingView() -> impl IntoView {
|
||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
set_submitted_cards.update_untracked(|cards| {
|
||||||
|
cards.extend(selected_cards.get_untracked());
|
||||||
|
});
|
||||||
|
|
||||||
websocket.send(&msg);
|
websocket.send(&msg);
|
||||||
set_selected_cards.update(|list| {
|
set_selected_cards.update_untracked(|list| {
|
||||||
list.clear();
|
list.clear();
|
||||||
});
|
});
|
||||||
|
set_submitted(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
view! {
|
view! {
|
||||||
|
@ -111,12 +123,13 @@ pub fn PlayingView() -> impl IntoView {
|
||||||
key=move |card| card.uuid.clone()
|
key=move |card| card.uuid.clone()
|
||||||
children=move |card| {
|
children=move |card| {
|
||||||
view! {
|
view! {
|
||||||
// Hide cards from hand view when they exist as selected
|
// Hide cards from hand view when they exist as selected or submitted
|
||||||
<Show when={
|
<Show when={
|
||||||
let id = card.uuid.clone();
|
let id = card.uuid.clone();
|
||||||
move || {
|
move || {
|
||||||
if let Some(card) = player_hand().get(&id) {
|
if let Some(card) = player_hand().get(&id) {
|
||||||
!selected_cards().contains(card)
|
!selected_cards().contains(card)
|
||||||
|
&& !submitted_cards().contains(card)
|
||||||
} else {
|
} else {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,6 +95,7 @@ pub fn Websocket() -> impl IntoView {
|
||||||
provide_context::<ReadSignal<Option<UserUpdate>>>(user_update);
|
provide_context::<ReadSignal<Option<UserUpdate>>>(user_update);
|
||||||
provide_context::<ReadSignal<Option<ChatUpdate>>>(chat_update);
|
provide_context::<ReadSignal<Option<ChatUpdate>>>(chat_update);
|
||||||
provide_context::<ReadSignal<Option<JudgeRound>>>(judge_round);
|
provide_context::<ReadSignal<Option<JudgeRound>>>(judge_round);
|
||||||
|
provide_context::<WriteSignal<Option<JudgeRound>>>(set_judge_round);
|
||||||
provide_context::<ReadSignal<Option<ChatMessage>>>(chat_message);
|
provide_context::<ReadSignal<Option<ChatMessage>>>(chat_message);
|
||||||
provide_context::<ReadSignal<Vec<GameBrowserMeta>>>(active_games);
|
provide_context::<ReadSignal<Vec<GameBrowserMeta>>>(active_games);
|
||||||
provide_context::<ReadSignal<Option<GameStateMeta>>>(current_game);
|
provide_context::<ReadSignal<Option<GameStateMeta>>>(current_game);
|
||||||
|
|
Loading…
Add table
Reference in a new issue