diff options
author | Kjetil Orbekk <kj@orbekk.com> | 2022-11-16 09:10:41 -0500 |
---|---|---|
committer | Kjetil Orbekk <kj@orbekk.com> | 2022-11-16 09:10:41 -0500 |
commit | 8fbf71b667d8b02777361adb7189939bd2d6fd02 (patch) | |
tree | fcadeede5218622d84aac467f1a692f4b106c3fd /webapp/src/components | |
parent | b114fe7940e77090861ac9ba60f4d0b8caec8978 (diff) |
Generate and display table in the webapp
Diffstat (limited to 'webapp/src/components')
-rw-r--r-- | webapp/src/components/table.rs | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/webapp/src/components/table.rs b/webapp/src/components/table.rs index bccbfe4..3561131 100644 --- a/webapp/src/components/table.rs +++ b/webapp/src/components/table.rs @@ -1,3 +1,4 @@ +use gloo_net::http::Request; use log::info; use yew::prelude::*; @@ -7,15 +8,26 @@ use crate::use_app_context; pub fn table(props: &TableProps) -> Html { let ctx = use_app_context(); - // let table_state: UseStateHandle<Option<protocol::TableView>> = use_state(|| None); + let table_state: UseStateHandle<Option<String>> = use_state(|| None); { // TODO update this from server state - // let table_state = table_state.clone(); - let ctx = ctx.clone(); - ctx.spawn_async(async move { - info!("Getting table state"); - Err(anyhow::anyhow!("Not implemented yet")) - }); + 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?; + let table: protocol::bridge_engine::GameState = response.json().await?; + table_state.set(Some(format!("{:#?}", table))); + Ok(()) + }); + || () + }, + (), + ); } let leave_table = { @@ -31,6 +43,7 @@ pub fn table(props: &TableProps) -> Html { <button onclick={leave_table}> { "Leave table" } </button> + <pre>{ table_state.as_ref().map_or("".to_string(), |t| format!("{}", t)) }</pre> </> } } |