From 4c0109a8c40012f75e3d0d900c0ef41893cfb4bb Mon Sep 17 00:00:00 2001 From: Kjetil Orbekk Date: Mon, 14 Nov 2022 19:49:52 -0500 Subject: Fetch table state from server --- webapp/src/components/app_context_provider.rs | 6 ++++-- webapp/src/components/table.rs | 22 ++++++++++++++++------ 2 files changed, 20 insertions(+), 8 deletions(-) (limited to 'webapp/src/components') diff --git a/webapp/src/components/app_context_provider.rs b/webapp/src/components/app_context_provider.rs index 19e7611..0b490fc 100644 --- a/webapp/src/components/app_context_provider.rs +++ b/webapp/src/components/app_context_provider.rs @@ -1,3 +1,4 @@ +use log::error; use crate::routing::Route; use gloo_net::http::Request; use log::info; @@ -26,13 +27,14 @@ pub struct AppContext { } impl AppContext { - fn spawn_async(&self, f: F) + pub fn spawn_async(&self, f: F) where F: Future> + 'static, { let error = self.state.error.clone(); spawn_local(async move { if let Err(err) = f.await { + error!("Error occurred: {err:?}"); error.set(Some(ErrorInfoProperties { message: format!("Some error occured: {:?}", err), })); @@ -47,7 +49,7 @@ impl AppContext { pub fn error(&self) -> Option<&ErrorInfoProperties> { self.state.error.as_ref() } - + pub fn create_table(&self) { let user = self.state.user.clone(); let history = self.history.clone(); diff --git a/webapp/src/components/table.rs b/webapp/src/components/table.rs index 829441e..b8da804 100644 --- a/webapp/src/components/table.rs +++ b/webapp/src/components/table.rs @@ -1,3 +1,4 @@ +use log::info; use yew::prelude::*; use yew_router::prelude::*; @@ -6,21 +7,30 @@ use crate::use_app_context; #[function_component(Table)] pub fn table(props: &TableProps) -> Html { let ctx = use_app_context(); - let history = use_history().unwrap(); + + let table_state: UseStateHandle> = use_state(|| None); + { + 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 leave_table = { let ctx = ctx.clone(); Callback::from(move |_| { - ctx.leave_table(); - }) + ctx.leave_table(); + }) }; html! { <>

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

- + } } -- cgit v1.2.3