use gloo_net::http::Request; use log::info; use protocol::bridge_engine::GameStatePlayerView; use yew::prelude::*; use crate::use_app_context; use crate::components::Hand; #[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?; // info!("Got response: {:#?}", response.body()); let table = response.json().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); }) }; html! { <>

{ "Table view" }

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