summaryrefslogtreecommitdiff
path: root/webapp/src/components
diff options
context:
space:
mode:
authorKjetil Orbekk <kj@orbekk.com>2022-09-10 14:49:38 -0400
committerKjetil Orbekk <kj@orbekk.com>2022-09-10 14:49:38 -0400
commit55a24a3b7d1b3fcc07f0bb8e53b00abf23e651b3 (patch)
treee85911ccc1eca8c820d7b4f40c9e3b36aa121034 /webapp/src/components
parent5ad23c12d718e5b4b6f9076ef2d29de5addd40fc (diff)
Add nav bar with context
Diffstat (limited to 'webapp/src/components')
-rw-r--r--webapp/src/components/bidding.rs4
-rw-r--r--webapp/src/components/game.rs28
-rw-r--r--webapp/src/components/show_bid.rs18
3 files changed, 44 insertions, 6 deletions
diff --git a/webapp/src/components/bidding.rs b/webapp/src/components/bidding.rs
index 26a4426..d142dec 100644
--- a/webapp/src/components/bidding.rs
+++ b/webapp/src/components/bidding.rs
@@ -46,13 +46,13 @@ pub fn bidding(props: &BiddingProperties) -> Html {
html! {
<>
- <p>{ "Bidding table" }</p>
- <BiddingTable bidding={ (*bidding).clone() } />
<p>{ "Bidding box" }</p>
<BiddingBox
current_bid={ bidding.highest_bid().clone() }
{ on_bid }
/>
+ <p>{ "Bidding table" }</p>
+ <BiddingTable bidding={ (*bidding).clone() } />
</>
}
}
diff --git a/webapp/src/components/game.rs b/webapp/src/components/game.rs
index 33fb5b7..0f25fc3 100644
--- a/webapp/src/components/game.rs
+++ b/webapp/src/components/game.rs
@@ -1,11 +1,17 @@
use crate::bridge_engine::{self, Contract, Player};
use crate::card;
use crate::card::Suit;
-use crate::components::{Bidding, Hand, HandProps};
+use crate::components::{Bidding, Hand, HandProps, ShowBid};
use yew::prelude::*;
pub const SUIT_DISPLAY_ORDER: [Suit; 4] = [Suit::Diamond, Suit::Club, Suit::Heart, Suit::Spade];
+#[derive(Debug)]
+enum Phase {
+ Bidding,
+ Cardplay,
+}
+
#[function_component(Game)]
pub fn game() -> Html {
let mut rng = rand::thread_rng();
@@ -25,12 +31,19 @@ pub fn game() -> Html {
Callback::from(move |c| contract.set(Some(c)))
};
+ let phase = if contract.is_none() {
+ Phase::Bidding
+ } else {
+ Phase::Cardplay
+ };
+
let shuffle = {
let north = north.clone();
let west = west.clone();
let south = south.clone();
let east = east.clone();
let dealer = dealer.clone();
+ let contract = contract.clone();
Callback::from(move |_| {
let mut rng = rand::thread_rng();
@@ -42,19 +55,26 @@ pub fn game() -> Html {
east.set(deal.east.into_iter().collect());
dealer.set(dealer.next());
+ contract.set(None);
})
};
html! {
<>
+ <div class="nav">
+ if let Some((contract, bidding)) = &*contract {
+ <ShowBid contract={contract.clone()} bidding={bidding.clone()}/>
+ }
+ <p>{ format!("Phase: {:?}", phase) }</p>
+ <button onclick={shuffle}>{ "Shuffle" }</button>
+ </div>
<div class="center">
<p>{ format!("Dealer: {:?}", *dealer) }</p>
- if let Some((contract, bidding)) = &*contract {
- { format!("Got contract {:?}. Bidding was {:?}", contract, bidding) }
+ if let Some(_) = &*contract {
+ { "Let's play" }
} else {
<Bidding {on_contract} dealer={ *dealer } />
}
- <button onclick={shuffle}>{ "Shuffle" }</button>
</div>
<div class="hand west">
<Hand ..(*west).clone() />
diff --git a/webapp/src/components/show_bid.rs b/webapp/src/components/show_bid.rs
new file mode 100644
index 0000000..b0c917e
--- /dev/null
+++ b/webapp/src/components/show_bid.rs
@@ -0,0 +1,18 @@
+use crate::bridge_engine::{Bid, Bidding, Contract};
+use crate::components::bid_css_class;
+use yew::prelude::*;
+
+#[derive(PartialEq, Properties, Clone)]
+pub struct ShowBidProps {
+ pub contract: Contract,
+ pub bidding: Bidding,
+}
+
+#[function_component(ShowBid)]
+pub fn show_bid(props: &ShowBidProps) -> Html {
+html! {
+ <>
+ <p>{ format!("{}", props.contract) }</p>
+ </>
+}
+}