use crate::components::{Hand, BiddingTable, BiddingBox}; use crate::use_app_context; use crate::utils::ok_json; use anyhow::Context; use gloo_net::http::Request; use log::info; use protocol::bridge_engine::GameStatePlayerView; use yew::prelude::*; #[function_component(OnlineTable)] pub fn online_table(props: &OnlineTableProps) -> Html { let ctx = use_app_context(); let table_state: UseStateHandle> = use_state(|| None); { // TODO update this from server state let table_state = table_state.clone(); let props = props.clone(); let ctx = ctx.clone(); use_effect_with_deps( move |_| { ctx.spawn_async(async move { let response = Request::get(&format!("/api/table/{}", props.table.id)) .send() .await .context("fetching table data")?; let table = ok_json(response).await?; table_state.set(Some(table)); Ok(()) }); || () }, (), ); } let leave_table = { let ctx = ctx.clone(); Callback::from(move |_| { ctx.leave_table(); }) }; html! { <>

{ format!("This is table {}", props.table.id) }

if let Some(table_state) = &*table_state { } } } #[derive(PartialEq, Properties, Clone)] pub struct OnlineTableProps { pub table: protocol::Table, } #[function_component(Table)] pub fn table(props: &TableProps) -> Html { let on_card_clicked = { Callback::from(move |card| { info!("Card clicked: {}", card); }) }; let on_bid = { Callback::from(move |bid| { info!("Bid clicked: {:?}", bid); }) }; let center = match &props.table { GameStatePlayerView::Bidding { bidding, .. } => html! { <> }, GameStatePlayerView::PassedOut { .. } => todo!(), GameStatePlayerView::Lead { .. } => todo!(), GameStatePlayerView::Play { .. } => todo!(), }; html! { <>
{ center }

{ "Table view" }

{ format!("{:#?}", props.table) }
} } #[derive(PartialEq, Properties, Clone)] pub struct TableProps { pub table: GameStatePlayerView, }