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/main.rs | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) (limited to 'webapp/src/main.rs') diff --git a/webapp/src/main.rs b/webapp/src/main.rs index 577b720..35e69fd 100644 --- a/webapp/src/main.rs +++ b/webapp/src/main.rs @@ -11,7 +11,7 @@ use components::{AppContext, AppContextProvider, ErrorInfo, Game, Table}; use gloo_net::http::Request; extern crate wee_alloc; pub mod routing; -use crate::{routing::Route, components::use_app_context}; +use crate::{components::use_app_context, routing::Route}; use uuid::Uuid; // Use `wee_alloc` as the global allocator. @@ -41,8 +41,6 @@ pub fn app() -> Html { fn home() -> Html { let ctx = use_app_context(); - info!("User: {:#?}", ctx.user()); - let user = match &ctx.user() { Some(userinfo) => html! {

{ format!("Logged in as {}", userinfo.username) }

@@ -56,28 +54,35 @@ fn home() -> Html { } let create_table = { - let ctx = ctx.clone(); - Callback::from(move |_| { - ctx.create_table(); - }) + let ctx = ctx.clone(); + Callback::from(move |_| { + ctx.create_table(); + }) }; + info!("home(): Error is {:?}", ctx.error()); + html! { - <> - if let Some(error) = &ctx.error() { - - } - + } +} + +#[function_component(Header)] +fn header() -> Html { + let ctx = use_app_context(); + html! { + if let Some(error) = &ctx.error() { + + } } } fn switch(routes: &Route) -> Html { - match routes { + let main = match routes { Route::Home => html! { }, Route::Playground => html! {
@@ -85,6 +90,13 @@ fn switch(routes: &Route) -> Html { Route::Table { id } => html! { }, + }; + + html! { + <> +
+ { main } + } } -- cgit v1.2.3